0

I'm new to MIPS. I want to ask how can I take 2 numbers from user and then display those numbers. I know how to do this this for 1 number.

.data
     promt: .asciiz "Enter one number: "
     message: .asciiz "\nNumber1 is: "

.text
 #Promt the user to enter number 1.
 li $v0, 4
 la $a0, promt
 syscall 

 #Get the user's age
 li $v0, 5
 syscall

 #Store the result in $t0
 move $t0, $v0

 #Display
 li $v0, 4
 la $a0, message
 syscall

 #Print or show the number
 li $v0, 1
 move $a0, $t0
 syscall 
Ravindra S
  • 6,302
  • 12
  • 70
  • 108

1 Answers1

0

Just simply add a main and a return address to take more inputs from the user and print more numbers. In case you only need to print two numbers make another message2: .asciiz for the second number and call it as you did with the first number, check my code example.

.data
 promt: .asciiz "Enter one number: "
 message: .asciiz "\nNumber1 is: "

.text

 main:
        #Promt the user to enter number 1.
        li $v0, 4
        la $a0, promt
        syscall 

        #Get the user's age
        li $v0, 5
        syscall

        #Store the result in $t0
        move $t0, $v0

        #Display
        li $v0, 4
        la $a0, message
        syscall

        #Print or show the number
        li $v0, 1
        move $a0, $t0
        syscall

        j main
        nop

Check also my example code here is the code, This print the larger of two numbers.

 .text


 .data
 message: .asciiz " Enter a number\n"
 message2: .asciiz "Enter another number\n"
 main:
.text
la        $a0, message
li        $v0, 4
syscall


li        $v0, 5
syscall

move     $t0,$v0

la       $a0, message2
li       $v0,4
syscall

li       $v0, 5
syscall

move     $t1,$v0


bgt      $t0,$t1, bigger
move     $t2,$t1
b        endif
bigger:
move     $t2,$t0
endif:  
move     $a0,$t2
li $v0, 1
syscall

li       $v0,10
syscall