您是否有 Qtspim 应该解释的标头 就像通常的 C 代码具有该功能一样main
?
这是 MIPS 标头。
.globl main # Make main global so you can refer to
# it by name in QtSPIM.
.text # This line tells the computer this is the
# text section of the program
# (No data contained here).
main: # Program actually starts here.
// your code
ori $v0, $0, 10 # Sets $v0 to "10" so when syscall is executed, program will exit.
syscall # Exit.
所以,你的代码应该是:
.globl main # Make main global so you can refer to
# it by name in QtSPIM.
.text # This line tells the computer this is the
# text section of the program
# (No data contained here).
main: # Program actually starts here.
li $s7, 5 #Read a Character AS A INT and store in $s7
#Load values for each:
li $t0, 43 #Addition
li $t1, 45 #Subtraction
li $t2, 42 #Multiplication
li $t3, 47 #Division
#if $s7 is equal to any of these, then jump back to the main loop and wait for a second operand
beq $s7, $t0, loop #ADD
beq $s7, $t1, loop #SUB
beq $s7, $t2, loop #MULTI
beq $s7, $t3, loop #DIV
la $a0, error #Load error message
j ra
ori $v0, $0, 10 # Sets $v0 to "10" so when syscall is executed, program will exit.
syscall # Exit.