检查如果数字大于或小于则使用 slt 并使用 mars 进行分支

checking If a number is greater then or Less then using slt and branching using mars

所以这就是我到目前为止所拥有的,我不确定从这里到哪里去分支或只是打印出答案。我试图打印出消息但无济于事。有没有办法同时使用 slt 和分支?

.data
    message1: .asciiz "The number is less than. :"
    message2: .asciiz "/nThe number is greater than. :"

.text
    main:
    addi $t0, $zero, 20
    addi $t1, $zero, 5

slt $s0, $t0, $t1
beq $s0, $zero, printmessage1

sge $s0, $t0, $t1
beq $s0, $zero, printmessage2 


li $v0, 10
syscall

printmessage1:
li $v0 4        #print out message1
la $a0 message1
syscall

printmessage2:
li $v0 4        #print out message1
la $a0 message2
syscall

slt $t1,$t2,$t3 Set less than : If $t2 is less than $t3, then set $t1 to 1 else set $t1 to 0.

一种更简单且减少指令使用的解决方案是 使用 bltbgt

bgt $t1,$t2,label Branch if Greater Than : Branch to statement at label if $t1 is greater than $t2

blt $t1,$t2,label Branch if Less : Branch to statement at label if $t1 is less than $t2

    .data
    message1: .asciiz "The number is less than. :"
    message2: .asciiz "/nThe number is greater than. :"

    .text
    main:
    addi $t0, $zero, 20
    addi $t1, $zero, 5

    blt $t0, $t1,printmessage1
    b printmessage2


    li $v0, 10
    syscall

    printmessage1:
    li $v0 4        #print out message1
    la $a0 message1
    syscall

    printmessage2:
    li $v0 4        #print out message1
    la $a0 message2
    syscall