使用qtspim编写MIPS代码

使用qtspim编写MIPS代码,mips,qtspim,Mips,Qtspim,我想在Qtspim的控制台中打印123型。 然后打印出“答案=123” 为什么我的mips代码不起作用 # 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

我想在Qtspim的控制台中打印123型。 然后打印出“答案=123”

为什么我的mips代码不起作用

# 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
系统调用1(
print\u integer
)要求在寄存器
$a0
中打印值。在您的程序中,当您执行
print_integer
系统调用时,
$a0
将不包含123,因为您已将
$a0
设置为
str
的地址

li $t0,123
li $v0, 1 # system call code for print_int 
move $a0,$t0
syscall
只需在代码中进行以下更改,它将打印“答案=123”。 出现问题的原因是a0仍然被分配给字符串,但需要将其分配给t0的值。
move$a0,$t0将t0的值移动到a0,代码将工作

在打印字符串时,将
$a0的值临时放置在另一个寄存器中,然后恢复。当你在汇编程序中编程时,你必须始终记住所有寄存器在代码中的每个位置都用于什么。我可以用a1替换它吗?la$a1,以后怎么恢复??