In: Computer Science
Write a MIPS assembly program that reads 3 add them together and stores the answer in memory.
Given below is code snippet of MIPS assembly program that reads 3 number and add them together and stores answer in memory alongwith screenshot of MARS Simulator which assemble the code.
.data
msg1: .asciiz "Enter First Number: "
msg2: .asciiz "Enter Second Number: "
msg3: .asciiz "Enter Third Number: "
msg4: .asciiz "Sum of Number entered is: "
.text
#Messgae to enter first number
li $v0,4
la $a0,msg1
syscall
#Read input from user
li $v0,5
syscall
#store input taken from user to register
move $t0,$v0
#Message to enter another number
li $v0,4
la $a0,msg2
syscall
#Read input from user
li $v0, 5
syscall
#store input taken into register
move $t1,$v0
#Message to enter another number
li $v0,4
la $a0,msg3
syscall
#Reading Third Number from User
li $v0,5
syscall
#store input in another register
move $t2,$v0
#adding first two number and storing it in register
add $t3,$t1,$t0
#adding third number to stored value and store value in register
add $t4,$t3,$t2
#************Next lines are additional code which will display sum of three number entered by user******
li $v0,4
la $a0,msg4
syscall
li $v0,1
move $a0,$t4
syscall
I tried my best to explain each instruction using comments,In case something is left, please feel free to ask any query related to any instruction.
SCREENSHOT OF RUN I/O