user2864709
user2864709

Reputation: 5

MIPS: Printing string with no pseduo instructions

Below I have

.globl main
.data
prompt:
        .asciiz  "Hello world!"
.text
main:
    addi $v0, $v0, 4
    lui $a0, 0x1000
    syscall
rtn:
    jr $ra

Now, I'm not sure why the string is not printing, it runs without syntax errors. Also, I am not permitted to use any pseudo-instructions, so that is why I am doing this the slightly longer way. That is where the error is coming in, I do not know where the prompt string is being stored? Any help is appreciated!

Thanks!

Upvotes: 0

Views: 1980

Answers (2)

Michael
Michael

Reputation: 58467

In SPIM, the .data section starts at address 0x10010000 by default. So to print the Hello World string without using pseudo-instructions you could use this:

.globl main
.data
prompt:
    .asciiz  "Hello world!"
.text
main:
    addi $v0, $zero, 4
    lui $a0, 0x1001       # $a0 = 0x10010000
    syscall
rtn:
    jr $ra

Upvotes: 1

Jester
Jester

Reputation: 58762

Note that if the address is 0x1000, that means the upper 16 bits are all zero, and the bottom 16 bits are 0x1000. You are loading the upper 16 bits. So instead of lui $a0, 0x1000 try addiu $a0, $0, 0x1000

However, your assembler's symbol manipulation expressions shouldn't count as pseudo-instructions, so something like this GAS code (or the equivalent in your assembler) should also be allowed:

lui $a0, %hi(prompt)
ori $a0, $a0, %lo(prompt)

Upvotes: 1

Related Questions