0

Could someone help me figure out what's wrong with my code? I am trying to read an integer, store its value and print it to the screen/

.text

main:

li $v0, 5
la $a0, testInteger
syscall

li $v0, 4
la $a0, resultString
syscall

li $v0, 1    
la $a0, testInteger
syscall

.data

testInteger: .word 5
resultString: .ascii "The integer is :"
Michael
  • 57,169
  • 9
  • 80
  • 125

1 Answers1

0

You need to signal that the end of your program has been reached. In SPIM and its offshoots you do this with syscall number 10.

So when you want execution of your program to stop (e.g. after you've printed the integer) you do:

li $v0, 10   # syscall 10 = exit    
syscall

Some other issues in your code:

  1. syscall number 5 returns the read integer in $v0. It does not store it in the memory pointed to by $a0 like your code seems to assume.

  2. syscall number 1 expects the value of the integer to print in $a0. You're putting the address of the integer in $a0 (that's what la does).

Michael
  • 57,169
  • 9
  • 80
  • 125