MIPS Assembly Language: I need to ask the user to enter in two decimal numbers,
ID: 662956 • Letter: M
Question
MIPS Assembly Language: I need to ask the user to enter in two decimal numbers, read in the integers, and store them into a 32-bit word in a memory location. Then add the numbers and store the sum into a 32-bit word memory location. Then print the sum from the memory location.
I have the code mostly done, but I am having trouble understanding how store the sum. I am also not sure if it is storing the two numbers either. I used 'sw' and .word to the word memory locations. Can someone show me how to write this code? It would be greatly appreciated.
Explanation / Answer
Getting the input of two numbers from the user:
main:
li $v0 5
syscall
move $t0, $v0
li $v0 5
syscall
move $t1, $v0
Input numbers are in t0 and t1 where t1 and t2 are temporary registers.
sw $t0 num1 will store first number to word
sw $t1 num2 will store second number to word
Add the numbers:
add $t2, $t0, $t1 ( The sum of t1 and t0 is in t2)
sw $t3 sum ( This instruction will save the sum of the two numbers in a word)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.