You are tasked to provide a final line of output to the display which provides a
ID: 3558596 • Letter: Y
Question
You are tasked to provide a final line of output to the display which provides a declarative statement of which value is greater. More formally, write MIPS assembly code that will execute in MARS to display exactly one of the following statements: "The first number is greater than the second number." which shall be displayed if and only if the value of the first number entered by the user is greater than the value of the second number entered. "The second number is greater than the first number." which shall be displayed if and only if the value of the second number entered by the user is greater than the value of the first number entered. "The two values entered are equal." which shall be displayed if and only if the value of the second number entered by the user is equal to the value of the first number entered.Explanation / Answer
.data
str1: .asciiz "Enter first integer "
str2: .asciiz "Enter Second integer "
str3: .asciiz "The first number is greater than the second number."
str4: .asciiz "The second number is greater than the first number."
str5: .asciiz "The two values entered are equal."
.text
li $v0,4 #command to print string
la $a0,str1 #string to be printed
syscall #print str1
li $v0,5 #command to read integer
syscall #read int
# $v0 contains integer read
move $a1,$v0 #store first integer in $a1
li $v0,4 #command to print string
la $a0,str1 #string to be printed
syscall #print str2
li $v0,5 #command to read integer
syscall #read int
beq $a1,$v0,printequal
bgt $a0,$v0,printgreater
#if not grater or equal it should be lesser
li $v0,4 #command to print string
la $a0,str4 #string to be printed
syscall #print str2
end : b end #infinite loop at the end of program
printequal:
li $v0,4 #command to print string
la $a0,str5 #string to be printed
syscall #print str2
b end
printgreater:
li $v0,4 #command to print string
la $a0,str3 #string to be printed
syscall #print str2
b end
Please let me know if you need more help..:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.