0

我对这个 MIPS 程序的评论是否准确地解释了每个语句行的作用?

.data
str1: .asciiz "Enter the first integer: "
str2: .asciiz "Enter the second integer: "
str3: .asciiz "The sum is "
newline: .asciiz "\n"

.text       # instructions follow this line 
main:   # indicates start of code (first instruction to execute)

addi $v0, $zero, 4 
  # adds zero and imm value 4 and stores in 32-bit function result registers

la $a0, str1 
  #load system register $a0, with the address of the string to be output
syscall

addi $v0, $zero, 5
   # adds zero and imm value 5 and stores in 32-bit function result registers
syscall
add $s0, $zero, $v0
   #adds 0 and value in $v0 and stores in $s0
addi $v0, $zero, 4
   # adds zero and imm value 4 and stores in 32-bit function result registers
la $a0, str2
   #load system register $a0, with the address of the string to be output
syscall

addi $v0, $zero, 5
   # adds zero and imm value 5 and stores in 32-bit function result registers
syscall 
add $s1, $zero, $v0
   #adds 0 and value in $v0 and stores in $s1
add $s2, $s0, $s1
   # adds value in $s0 and value in $s1 and stores in $s2
addi $v0, $zero, 4
   # adds zero and imm value 4 and stores in 32-bit function result registers
la $a0, str3
   # load system register $a0, with the address of the string to be output
syscall

addi $v0, $zero, 1
   # adds zero and imm value 1 and stores in 32-bit function result registers
add $a0, $zero, $s2
   # adds value in $s2 and 0 and stores in system register $a0
syscall

addi $v0, $zero, 4
   # adds zero and imm value 4 and stores in 32-bit function result registers
la $a0, newline
   # load system register $a0, with the address of the string to be output
syscall

addi $v0, $zero, 10
   # adds zero and imm value 10 and stores in 32-bit function result registers
syscall
jr  $ra  
   # jump to address contained in $ra

系统调用有什么作用,因为我在网上看到了不同的评论?另外,如果我想修改这个程序以打印第一个整数第二个整数的时间量,我该怎么做?例如:1st: 2, 2nd: 5,所以我打印 2 5 次。

4

1 回答 1

1

MIPS 上的一般syscall指令会导致由操作系统处理的异常。操作系统的作用取决于操作系统和使用的特定 ABI。通常,用户在特定寄存器中设置一些参数(由使用中的约定/ABI 确定)并代表用户执行一些“特权”操作。

考虑到您没有提供您的代码应该在其上执行的环境的细节,我无法告诉您使用了哪些特定的参数传递约定以及操作系统(或模拟器)将为您传递的特定参数做什么。

于 2014-03-13T22:48:26.503 回答