我目前正在上 MIPS 汇编类(class),我们使用的书已经绝版,所以我依靠互联网寻求帮助,以便我能理解。该程序接受三个整数。其中两个用于 add/sub/mult/div,第三个是运算符。这是代码。
.text
.globl __start
__start:
# Prompt for first int and accept first int
la $a0,firstint
li $v0,4
syscall
li $v0,5
move $s0, $v0
syscall
# Prompt for second int and accept second int
la $a0,firstint
li $v0,4
syscall
li $v0,5
move $s1, $v0
syscall
# Prompt for operation
la $a0,operation
li $v0,4
syscall
li $v0,5
move $s2, $v0
syscall
beq $s2,0,__add0
li $v0,10
syscall
__add0:
la $a0,added
li $v0,4
syscall
add $a0, $s0, $s1
li $a0,1
syscall
.data
firstint: .asciiz "Enter the first integer: "
secondint: .asciiz "Enter the second integer: "
operation: .asciiz "Enter operation (add=0, subtract=1, multiply=2, divide=3): "
added: .asciiz "The added number is: "
我的理解是,如果$s2中的值等于0,beq将跳转到add0..但它似乎没有发生。输入操作类型后输出停止。示例输出:
Enter the first integer: 10
Enter the first integer: 5
Enter operation (add=0, subtract=1, multiply=2, divide=3): 0
-- program is finished running --
有什么想法吗?
最佳答案
您必须在移动之前执行系统调用:
li $v0,5
syscall
move $s2, $v0
关于assembly - MIPS 中的简单加法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14857729/