如果在MIPS大于或等于 [英] If greater than or equal in MIPS

查看:1485
本文介绍了如果在MIPS大于或等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提示和输入的两个整数的a和b使用系统调用

Prompt for and input two integers "a" and "b" using syscalls

根据显示下列语句之一。如果A> B或A = B或


  • 您输入大于a b

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

    • You entered a greater than b

      您输入了等于b

      您输入的不是一个更低的B

      You entered a less than b

      我一定要得到这样的提示,我那么努力完成它。这是我stucked,我真的AP preciate你的帮助。

      I have to get this prompt and I tried so hard to get it done. This is where I'm stucked, I'd really appreciate your help.

          .data  
      p1: .asciiz "Please enter the first number ? "  
      p2: .asciiz " Please enter the second number? "  
      ans1: .asciiz " \nYou entered a greater than b "  
      ans2: .asciiz " \nYou entered a equal to b "  
      ans3: .asciiz " \nYou entered a less than b "  
      
      
              .text
              .globl main
      
      main:    
          li $v0, 4     #system call code for print_str  
          la $a0, p1  #address of string to print  
          syscall     #print the first prompt  
      
      
          li $v0, 5   #system call code for read_int
          syscall     #read first integer
          move $t1, $v0   #store it till later
      
          li $v0, 4   #system call code for print_str
          la $a0, p2  #address of string to print
          syscall     #prints the second prompt
      
          li $v0, 5   #system call code for read_int
          syscall     #read first integer
          move $t2, $v0   #store it till later
      
          slt $t1,$s1,$s0      # checks if $s0 > $s1
          beq $t1,1,label1 
      

      我真的不知道如何使用分支语句,这真的令人困惑。我想知道如何解决它。

      I really don't know how to use branch statements, and it's really confusing. I would like to know how to fix it.

      推荐答案

      为什么你阅读数字到$ t1和t2的$然后比较$ s1和$ S0?它在哪里混乱?

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

      只需使用SLT和BEQ / BNE,那会掩盖你需要所有的比较情况。

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

      假设一个在$ S0,b为$ S1

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

      a < b:
      slt $t0, $s0, $s1
      bne a_lt_b, $t0, $zero # $t0 == 1 != 0 if a < b
      
      a = b:
      beq a_eq_b, $s0, $s1   # nothing more to explain
      
      a > b:
      slt $t0, $s1, $s0
      bne b_lt_a, $t0, $zero # $t0 == 1 != 0 if b < a
      
      a >= b:
      slt $t0, $s0, $s1
      beq a_ge_b, $t0, $zero # $t0 == 0 if a >= b or !(a < b)
      
      a <= b:
      slt $t0, $s1, $s0
      beq b_ge_a, $t0, $zero # $t0 == 0 if b >= a or !(b < a)
      

      这篇关于如果在MIPS大于或等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆