1
votes

I'm a newbie at assembly and I'm having quite some difficulties with it.

I'm using MARS 4.5 and I want to try to write a code which can take an integer from the keyboard and print it right afterwards.

.data  
number: .word 

.text
.globl main 
main: 

li       $v0, 5   
syscall

move     $v0, $a0

li       $v0, 1
la   $a0, ($v0)
syscall


li       $v0, 10       
syscall   

but when I run this, it returns the value 1 no matter what the input is.

The problem seem to be at the "la $a0, ($v0)" command.

I though that if I loaded the address of the $v0 register that holds the input number to the standard register for printing integers, it could work.

How can I solve this?

1
Registers don't have addresses, and the print integer function requires the value not the address anyway. So just delete that line and it should work.Jester
By deleting the load address command, it returns 0Coursal
You also got the move operands reversed.Jester
You are right. Would it be easier if I stored the input number inside the memory?Coursal

1 Answers

0
votes

You're on the right track. As @Jester explained, you need to remove the load address command and correct your move operands.

.data  
number: .word 

.text
.globl main 
main: 

li       $v0, 5     #Read integer to $v0
syscall

move     $a0, $v0   #Move integer to $a0

li       $v0, 1     #Print integer from $a0
syscall

li       $v0, 10    #Exit     
syscall