Reputation: 1387
Lets say that you type a name first and a surname last and you want the program to print the surname first and then the name.
f.e.
Gabe
Newell
Newell
Gabe
Ι tried to make just that:
.data
first: .word
second: .word
.text
.globl main
main:
li $v0, 8
la $a0, first
la $a1, 20
syscall
move $s1, $a0
la $a0, second
la $a1, 20
syscall
li $v0, 4
la $a0, second
syscall
move $a0, $s1
la $a0, 0($s1)
syscall
li $v0, 10
syscall
but at the output it gives me: newell newell
So, what it the problem here?
Upvotes: 1
Views: 463
Reputation: 49803
You didn't set aside enough space for the names; .word
only sets aside enough for an integer (2 or 4 bytes, probably the latter).
Use .space
instead.
Then, to print the first name, you need to load the address of first
into $a0
before making the syscall
; $s1
does not have the value you think it does.
Upvotes: 1