In: Computer Science
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S. The program then prints out the result (i.e. integer S) after printing the string "The sum of X and Y (X + Y) is ".
Then assemble and run the program with MARS to show and capture the input/output.
Instruction:
1. A copy of the final working assembly language source code with comments and documentation. The file should be "text-only" and the extension must be ".s" or ".asm".
2. A screenshot showing keyboard input and displayed output from the console.
Given below is the code and output for the question. Please do rate the answer if it helped. Thank you.
.data
xMsg: .asciiz "Enter the values for X: "
yMsg: .asciiz "Enter the values for Y: "
outMsg: .asciiz "The sum of X and Y (X + Y) is "
X: .word 0
Y: .word 0
S: .word 0
.text
#print string
la $a0, xMsg
li $v0, 4
syscall
#read int and store in X
li $v0, 5
syscall
sw $v0, X
#print string
la $a0, yMsg
li $v0, 4
syscall
#read int and store in Y
li $v0, 5
syscall
sw $v0, Y
#load X into $t0, and Y into $t1, calculate sum
into $t0 and save to S
lw $t0, X
lw $t1, Y
add $t0, $t0, $t1
sw $t0, S
#display the result - msg and then number from S
la $a0, outMsg
li $v0, 4
syscall
#print number from S
lw $a0, S
li $v0, 1
syscall
#exit
li $v0, 10
syscall
output
----
Enter the values for X: 2
Enter the values for Y: 3
The sum of X and Y (X + Y) is 5
-- program is finished running --