In: Computer Science
Computer Architecture:
Write a MIPS program to compute f = g - (f + 5)
Assume registers $to, $s1 hold values for g and f
respectively.
The program should display the following prompts and read value
entered by the user “Enter a value for f:"
“Enter a value for g:"
The program the prints: "Answer for f = g - (f + 5):"
The program should repeat the above steps 3 times for each input
pair, f and g
Make certain that your assembly code is properly organized (indented, commented, contains your name at the top of the code). Comment any assumptions at the top and include results showing the working code via screen prints
Dear Student,
I hope the following code fits in your needs.
# Space left to add name of the student
.data
msg1: .asciiz "Enter a value for f: "
msg2: .asciiz "\nEnter a value for g: "
result: .asciiz "\nAnswer for f = g - (f + 5): "
.text
li $t2,5
li $t3, 0
li $t4, 3
Loop:
beq $t3, $t4, Exit
# Taking input from user for f
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall
# moving the value of $v0 to $s1
move $s1,$v0
# Taking input from user for g
li $v0,4
la $a0,msg2
syscall
li $v0,5
syscall
# moving the value of $v0 to $t0
move $t0,$v0
# calculating the value of the given formula
Add $t1,$s1,$t2
sub $s1,$t0,$t1
li $v0,4
la $a0,result
syscall
li $v0,1
move $a0,$s1
syscall
j Loop #jumps back to the top of loop
Exit: # ends the program
li $v0,10
syscall
Note: The out snapshot is to be taken by the student after adding their name.
Thank you, please upvote if you liked it!