【问题标题】:Simple Addition in MIPSMIPS 中的简单加法
【发布时间】:2013-02-13 16:04:59
【问题描述】:

我目前正在上 MIPS 汇编课程,我们使用的书已绝版,因此我依靠互联网寻求帮助,以便我能理解。这个程序接受三个整数。其中两个是 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 --

有什么想法吗?

【问题讨论】:

    标签: assembly mips


    【解决方案1】:

    您必须在移动之前进行系统调用:

    li $v0,5
    syscall
    move $s2, $v0
    

    【讨论】:

    • 耶!有效!非常感谢。我已经修改了我的其余代码并且它有效。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    相关资源
    最近更新 更多