You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MIPS 16位ALU PCSpim代码输出位序反转问题求助

问题与代码实现

待解决问题

我正在解决以下问题:
问题

已实现的PCSpim代码

## Two 16 bits value is assigned in data segment 
## Provide Selector value in console window
## Result is displayed
.text
globl main

main:
    la $s1, value   
    lb $t1, 0($s1)
    lb $t2, 2($s1)
    lb $t3, 4($s1)
    xor $t7,$t7,$t7
    

    li $v0, 4
    la $a0, msg1
    syscall 
    
    li $v0, 5   ##selector
    syscall
    add $s3, $v0, $0 ##selector in s3
    
    addi $s4, $0, 0  ##carry in 0 in s4


    addi $t0,$0, 3
    bne $t0, $s0, LabelY
    addi $s4, $0, 1  ##carry in 1 substruction
        
LabelY:
    bgt $t3,15,exit1
    addi $t3,$t3,1

    jal aBitALU

        
    li $v0, 1
    move $a0, $t6
    syscall
    
    
    srl $t1,$t1,1
    srl $t2,$t2,1
    j LabelY

    #li  $v0, 10
    #syscall
    
aBitALU:
    add $s0, $0, $s3
    add $s1, $0, $s4
    andi $t5, $t2, 1
    andi $t4, $t1, 1


    addi $t0,$0, 0
    beq $t0, $s0, Label0

    addi $t0,$0, 1
    beq $t0, $s0, Label1

    addi $t0,$0, 2
    beq $t0, $s0, Label2
    addi $t0,$0, 3
    beq $t0, $s0, Label3
    addi $t0,$0, 4
    beq $t0, $s0, Label4
    addi $t0,$0, 5
    beq $t0, $s0, Label5
    addi $t0,$0, 7
    beq $t0, $s0, Label7
    
    

Label0: 
    or $t6, $t5, $t4   #binary or
    jr $ra

Label1: 
    and $t6, $t5, $t4  #binary and
    jr $ra

Label2: 
                    #binary addition

    or $t4,$t4,$t7  
    xor $a0, $t4, $t5 #sum
    xor $a1, $a0, $s1
    
    and $a0, $a0, $s1

    and $a2, $t4, $t5

    or $a0, $a0, $a2 #cout

    add $t6, $a1, $0
    add $t7, $a0, $0

    jr $ra

Label3: 
                    #binary 2's complement substruction

    nor  $t7, $t5, $t5
    andi $t7, $t7,1

    xor $a0, $t4, $t7 #sum
    xor $a1, $a0, $s1
    
    and $a0, $a0, $s1
    and $a2, $t4, $t7

    or $a0, $a0, $a2 #cout

    add $t6, $a0, $0
    add $t7, $a1, $0

    jr $ra

Label4:
    beq $t3,1,l1
    bne $t3,1,l2
    l1:
    sll $t1,$t1,1
    xor $t6,$t6,$t6
    andi $t6, $t1, 1
    jr $ra
    
    l2:
    xor $t6,$t6,$t6
    andi $t6, $t1, 1
    jr $ra
Label5:
    beq $t3,1,l3
    bne $t3,1,l4
    l3:
    srl $t1,$t1,1
    xor $t6,$t6,$t6
    andi $t6, $t1, 1
    jr $ra
    
    l4:
    xor $t6,$t6,$t6
    andi $t6, $t1, 1
    jr $ra
Label7: 
    slt $t6, $t2, $t1    #if t2 less then t1 then t6=1 otherwise t6=0
    j exit
exit:
    li $v0, 1
    move $a0, $t6
    syscall
exit1:
    li $v0, 4
    la $a0, msg2
    syscall
        
    li $v0, 1
    move $a0, $t6
    syscall
    
    li $v0, 1
    move $a0, $t7
    syscall

.data
value: .half 5, 6, 0
msg1:  .asciiz "Selector Value = "

msg2:  .asciiz "Result = "

运行结果

运行代码后,控制台显示如下:
控制台输出

疑问

选择器值2代表加法运算(5+6=11,二进制应为0000 0000 0000 1101),但当前输出的位序颠倒,最高位(MSB)与最低位(LSB)互换;结果中的“00”分别代表零标志和进位标志,请问该如何修正这个位序问题?


内容的提问来源于stack exchange,提问作者Rocky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 01:25:13