2013-02-13 143 views
3

我目前正在MIPS彙編類中,我們使用的書已絕版,因此我依靠互聯網尋求幫助,以便我理解。這個程序有三個整數。其中兩個添加/ sub/mult/div,第三個是運營商。這是代碼。MIPS中的簡單加法

.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: " 

我的理解是,BEQ將跳轉到ADD0如果在$ S2的值等於0 ..但它似乎並沒有發生。輸入操作類型後停止輸出。輸出示例:

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 -- 

任何想法?

回答

3

您以前的動做系統調用:

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

耶!有效!非常感謝你。我已經修改了我的其他代碼,它可以工作。非常感謝! – 2013-02-13 16:53:45