If greater than or equal in MIPS

后端 未结 1 914
孤街浪徒
孤街浪徒 2021-01-15 17:15

Prompt for and input two integers “a” and “b” using syscalls

Display one of the following statements depending on if a>b, or a=b or a

  • You entered a grea

相关标签:
1条回答
  • 2021-01-15 17:39

    Why do you read the numbers into $t1 and $t2 then compare $s1 and $s0? Where is it confusing?

    Simply use slt and beq/bne, that'll cover all comparison cases you need.

    Suppose a is in $s0, b is in $s1

    • a < b:

      slt $t0, $s0, $s1
      bne $t0, $zero, a_lt_b # $t0 == 1 != 0 if a < b
      
    • a = b:

      beq $s0, $s1, a_eq_b   # nothing more to explain
      
    • a > b:

      slt $t0, $s1, $s0
      bne $t0, $zero, b_lt_a # $t0 == 1 != 0 if b < a
      
    • a >= b:

      slt $t0, $s0, $s1
      beq $t0, $zero, a_ge_b # $t0 == 0 if a >= b or !(a < b)
      
    • a <= b:

      slt $t0, $s1, $s0
      beq $t0, $zero, b_ge_a # $t0 == 0 if b >= a or !(b < a)
      
    0 讨论(0)
提交回复
热议问题