Create a MIPS program that fulfills the following specifications: in the .data s
ID: 3743137 • 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 (name them whatever you like)
a variable to hold the user’s name
3 variables for messages:
A prompt for name
A prompt for integers
A 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 in memory
3 times:
prompt user for an integer between 1-100
read and store the integers in a, b, and c
no input checking required
calculate ans1 = a + b + c and store the result
calculate ans2 = c + b - a and store the result
calculate ans3 = (a + 2) + (b - 5) - (c – 1) 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)
Sample Runs: (you should use different test data) Notice that printing the name string causes a newline, but don't worry about it What is your name? Karen Please enter an integer between 1-100: 7 Please enter an integer between 1-100: 17 Please enter an integer between 1-100: 27 Karen your answers are: 51 37 -5 program is finished running What is your name? Karen Please enter an integer between 1-100: 20 Please enter an integer between 1-100: 360 Please enter an integer between 1-100: 40 Karen your answers are: 90 50 8 program is finished runningExplanation / Answer
ANS:-
Given that,
3 variables to hold input values: a, b, c
3 variables to hold output values (name them whatever you like)
a variable to hold the user’s name
3 variables for messages:
A prompt for name
A prompt for integers
program code:-
.data
a: .space 4
b: .space 4
c: .space 4
ansl: .space 4
ans2: .space 4
ans3: .space 4
name: .space 100
promptl: .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, promptl
li $v0, 4
syscall
# read name from user
la $a0, name
li $al, 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
syscall
sw $v0, b
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
sw $v0, c
# calculate answers
#ansl
lw $tO, a
lw $tl, b
add $tO, $tO, 2 # a+2
add $tl, $tl, 5 # b+5
add $tO, $t0, $t1 # (a+2) + (b+5)
sw $t0, ansl
#ans2
lw $tO, a
lw $tl, b
mul $tO, $tO, 5 # 5*a
sub $tO, $tO, $tl # (5*a) - b
add $tO, $t0, 10 # (5*a) - b + 10
sw $tO, ans2
#ans3
lw $tO, a
lw $tl, b
div $tl, $tl, 2 # b/2
add $tO, $tO, $t1 # a + b/2
sw $tO, 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, ansl
li $v0, 1
syscall
9:42 PM
,L I
li $vU, 4
syscall
lw $a0, ansl
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
################ttit##########
# a = 20
# b = 30
# c = 40
# ansl =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