0

我想在 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
4

2 回答 2

1

系统调用 1( print_integer) 期望值在寄存器中打印$a0。在您的程序中,$a0执行系统调用时不会包含 123 print_integer,因为您已将$a0地址设置为str.

于 2014-03-23T16:17:36.960 回答
0
li $t0,123
li $v0, 1 # system call code for print_int 
move $a0,$t0
syscall

只需在代码中进行以下更改,它将打印“答案 = 123”。出现问题是因为您的 a0 仍分配给字符串,但您需要将其分配给 t0 的值。move $a0,$t0 会将 t0 的值移动到 a0 并且您的代码将起作用

于 2021-03-26T23:05:04.357 回答