Create a MIPS program that fulfills the following specifications: in the .data s
ID: 3875216 • Letter: C
Question
Create a MIPS program that fulfills the following specifications: in the .data section: 3 variables to hold input values: a, b, c 3 variables to hold output values a variable to hold the user's name 3 variables for messages: prompt for name prompt for integers message for results (similar to the sample run below) in the .text section write instructions to: prompt the user for their name and save it 3 times: prompt user for an integer between 1-100 read and store the integer calculate ans1 = (a + 2) + (b - 5) and store the result calculate ans2 = 5*a - b + 10 and store the result calculate ans3 = a + b/2 and store the result display the user name and message for results display the 3 results but print a space character in between for readability at the bottom of your program, add comments with test values for a, b, c and the results you expect from the program for ans1, ans2, ans3 (see sample run below)Explanation / Answer
Code:
.data
a: .space 4
b: .space 4
c: .space 4
ans1: .space 4
ans2: .space 4
ans3: .space 4
name: .space 100
prompt1: .asciiz "Enter name of the user: "
prompt2: .asciiz "Enter an integer (1-100): "
prompt3: .asciiz "Result: "
space: .asciiz " "
.globl main
.text
# main loop
main:
# prompt user for name
la $a0, prompt1
li $v0, 4
syscall
# read name from user
la $a0, name
li $a1, 100
li $v0, 8
syscall
# read 3 integers from user
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
sw $v0, a
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
sw $v0, b
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
sw $v0, c
# calculate answers
#ans1
lw $t0, a
lw $t1, b
add $t0, $t0, 2 # a+2
add $t1, $t1, 5 # b+5
add $t0, $t0, $t1 # (a+2) + (b+5)
sw $t0, ans1
#ans2
lw $t0, a
lw $t1, b
mul $t0, $t0, 5 # 5*a
sub $t0, $t0, $t1 # (5*a) - b
add $t0, $t0, 10 # (5*a) - b + 10
sw $t0, ans2
#ans3
lw $t0, a
lw $t1, b
div $t1, $t1, 2 # b/2
add $t0, $t0, $t1 # a + b/2
sw $t0, ans3
#display user name
la $a0, name
li $v0, 4
syscall
#display result message
la $a0, prompt3
li $v0, 4
syscall
la $a0, space
li $v0, 4
syscall
lw $a0, ans1
li $v0, 1
syscall
la $a0, space
li $v0, 4
syscall
lw $a0, ans2
li $v0, 1
syscall
la $a0, space
li $v0, 4
syscall
lw $a0, ans3
li $v0, 1
syscall
la $a0, space
li $v0, 4
syscall
# exit the program
li $v0, 10
syscall
############################
# a = 20
# b = 30
# c = 40
# ans1 = 57
# ans2 = 80
# ans3 = 35
############################
Output:
Enter name of the user: asd
Enter an integer (1-100): 20
Enter an integer (1-100): 30
Enter an integer (1-100): 40
asd
Result: 57 80 35
-- program is finished running --