In: Computer Science
Write a MIPS program that executes the statement: s = (a + b) – (c + 101), where a, b, and c are
user provided integer inputs, and s is computed and
printed as an output. Answer the following:
a. Suppose the user enters a = 5, b = 10, and c = -30,
what is the expected value of s?
b. Which instruction in your program computed the
value of s and which register is used?
c. What is the address of this instruction in
memory?
d. Put a breakpoint at this instruction and write the
value of the register used for computing s in
decimal and hexadecimal.
MIPS PROGRAM
.data
askA: .asciiz "Enter value of a: "
askB: .asciiz "Enter value of b: "
askC: .asciiz "Enter value of c: "
msgS: .asciiz "Result s: "
.text
# Prompt user to enter value of a
li $v0, 4
la $a0, askA
syscall
# Get user input
li $v0, 5
syscall
#store the result in t0
move $t0, $v0
# Prompt user to enter value of b
li $v0, 4
la $a0, askB
syscall
# Get user input
li $v0, 5
syscall
#store the result in t1
move $t1, $v0
add $t2, $t0, $t1
# Prompt user to enter value of c
li $v0, 4
la $a0, askC
syscall
# Get user input
li $v0, 5
syscall
#store the result in t0
move $t0, $v0
add $t1,$t0,101
sub $t0,$t2,$t1
li $v0, 4
la $a0, msgS
syscall
#print or show the age
li $v0, 1
move $a0, $t0
syscall
Explanation
$t0 = a
$t1 = b
$2 = $t0 + $t1
$t0 = c
$t1 = $t0 + 101
$t0 = $t2 - $t1
Qa Ans) -56
Qc Ans )
Qb Ans)
sub $t0,$t2,$t1
Qd Ans)
Hexadecimal
Decimal