代码之家  ›  专栏  ›  技术社区  ›  team224

如何在不使用循环的情况下确定MIPS中三个整数的最小值

  •  0
  • team224  · 技术社区  · 7 年前

    我能够获得用户输入,如代码所示,但我无法获得最小的数字。 谢谢。。。

    以下是相关说明。

    “编写一个汇编程序,从用户那里读取三个32位有符号整数。确定这三个数字中的最小值并显示结果。不要使用循环。提示用户输入每个整数。”

    .data
    Msg1: .asciiz "Enter the first integer: "
    Msg2: .asciiz "Enter the second integer: "
    Msg3: .asciiz "Enter the third integer: "
    Msg4: .asciiz "the the smallest numberis: "
    
    .text
         # Print the first message
     li $v0, 4
     la $a0, Msg1
     syscall
    
     # Prompt the user to enter the first integer
     li $v0, 5
     syscall
    
     # Store the first integer in $t0
     move $t0, $v0
    
     # Print the second message
     li $v0, 4
     la $a0, Msg2
     syscall
    
     # Prompt the user to enter the second integer
     li $v0, 5
     syscall
    
     # Store the first integer in $t1
     move $t1, $v0
    
     # Print the third message
     li $v0, 4
     la $a0, Msg3
     syscall
    
     # Prompt the user to enter the third interger
     li $v0, 5
     syscall
    
     # Store the first integer in $t0
     move $t2, $v0
    
     # Determine the smallest Number
     slt $s0, $t1, $t0
     beq $s0, $zero, L1
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   team224    7 年前

    .data
    Msg1: .asciiz "Enter the first integer: "
    Msg2: .asciiz "Enter the second integer: "
    Msg3: .asciiz "Enter the third integer: "
    
    .text
         # Print the first message
     li $v0, 4
     la $a0, Msg1
     syscall
    
     # Prompt the user to enter the first integer
     li $v0, 5
     syscall
    
     # Store the first integer in $t0
     move $t0, $v0
    
     # Print the second message
     li $v0, 4
     la $a0, Msg2
     syscall
    
     # Prompt the user to enter the second integer
     li $v0, 5
     syscall
    
     # Store the first integer in $t1
     move $t1, $v0
    
     # Print the third message
     li $v0, 4
     la $a0, Msg3
     syscall
    
     # Prompt the user to enter the third interger
     li $v0, 5
     syscall
    
     # Store the first integer in $t0
     move $t2, $v0
    
     # Determine the smallest Number
     blt $t0, $t1, L0
     blt $t1, $t0, L3
    
    
     li, $v0, 10
     syscall
    
     L0:
       blt $t0, $t2, L2
       blt $t2, $t0, L3
    
     L2:
       li $v0, 1
       move $a0, $t0
       syscall
       li, $v0, 10
       syscall
    
     L3:
       blt $t1, $t2, L4
       blt $t2, $t1, L5
    
     L4:
        li $v0, 1
        move $a0, $t1
        syscall
        li, $v0, 10
        syscall
    
     L5:
        li $v0, 1
        move $a0, $t2
        syscall
        li, $v0, 10
        syscall
    
    
     li, $v0, 10
     syscall