user3276213
user3276213

Reputation: 1

writing MIPS CODES using qtspim

I want to print type 123 in console of Qtspim. and then print out "the answer = 123".

Why my mips code does not work??

# messages.asm 
 .data 
str: .asciiz "the answer = " 
 .text 


main: 

li $v0,5
syscall

li $v0, 4 # system call code for print_string 
la $a0, str # address of string to print
syscall # print the string 


li $v0, 1 # system call code for print_int 
syscall

li $v0, 10 # system call code for exit
 syscall # terminate program

Upvotes: 0

Views: 696

Answers (2)

Akber Rizvi
Akber Rizvi

Reputation: 1

li $t0,123
li $v0, 1 # system call code for print_int 
move $a0,$t0
syscall

just make the following changes in the code and it will print "the answer = 123". The problem arises because your a0 is still assigned to string but you need to assign it to the value of t0. move $a0,$t0 will move the value of t0 to a0 and your code will work

Upvotes: 0

Michael
Michael

Reputation: 58497

System call 1 (print_integer) expects the value to print in register $a0. In your program, $a0 will not contain 123 when you perform the print_integer syscall, because you've set $a0 to the address of str.

Upvotes: 1

Related Questions