Question & Answer: Using the following data segment, write the code to read the first two words from memory and then write the sum of the numbers to the third word……

Using the following data segment, write the code to read the first two words from memory and then write the sum of the numbers to the third word.

.data
.word 10, 14
.word 0

Expert Answer

 

.data
num1: .word 10               # Assign a variable num1 and holds 10
num2: .word 14               # A variable that holds 14
res: .word 0                     # Variable that holds sum of two words

.text
lw $t0, number1              # load word 10 from RAM to processor register $t0
lw $t1, number2             # load word 14 from RAM to processor register $t1
add $t1, $t1, $t0             # $t1 and $t0 are added and stored to register $t1
la $t2, res                       # Load the address of res variable
sw $t1, 0($t2) # Store the data to the res location.

Still stressed from student homework?
Get quality assistance from academic writers!