Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a flowchart for the following MIPS code: # Registers used: # $t 0 for A # $t 1 for B # $t 2 for

Create a flowchart for the following MIPS code:
# Registers used:
# $t0 for A
# $t1 for B
# $t2 for C
# $t3 for D
# $t4-$t9 is used to store results from evaluations
.data
promptA: .asciiz "Enter 4 integers for A, B, C, D respectively:"
resultF_b: .asciiz "f_two:"
resultF_ten: .asciiz "f_ten: "
resultG_b: .asciiz "g_two: "
resultG_ten: .asciiz "g_ten: "
newline: .asciiz "
"
.text
main:
#input promptA
la $a0, promptA
li $v0,4
syscall
#newline
li $v0,4
la $a0, newline
syscall
#read integers from users input
li $v0,5
syscall
move $t0, $v0 #int A->$t0
li $v0,5
syscall
move $t1, $v0 #int B->$t1
li $v0,5
syscall
move $t2, $v0 #int C->$t2
li $v0,5
syscall
move $t3, $v0 #int D->$t3
li $t40
li $t55
loop_5_b:
beqz $t1, exit1 #if B=0, exit loop
add $t4, $t4, $t5
subi $t1, $t1,1 #repeat addition B number of times
j loop_5_b
exit1:
li $t6,0
move $t9, $t3 #copy D's value to $t9
loop_5b_d:
beqz $t9, exit2 #if D=0, exit loop
add $t6, $t6, $t4
subi $t9, $t9,1 #repeat subsequent addition D number of times
j loop_5b_d
exit2:
add $t7, $t6, $t0 #calculate f=(5*B*D+A)
#input resultF_ten
la $a0, resultF_ten
li $v0,4
syscall
move $a0, $t7 #move f result into $a0
li $v0,1 #print F in decimal
syscall
#newline
li $v0,4
la $a0, newline
syscall
#input resultF_b
la $a0, resultF_b
li $v0,4
syscall
move $a0, $t7 #move f result into $a0
li $v0,35 #print F in binary
syscall
#newline
li $v0,4
la $a0, newline
syscall
move $t8, $t3 #copy D's value to $t8
li $t50
loop_D_D:
beqz $t8, exit3 #if D=0, exit loop
add $t5, $t5, $t3
subi $t8, $t8,1 #repeat addition D number of times
j loop_D_D
exit3:
li $t60
loop_C_A:
beqz $t0, exit4 #if A=0, exit loop
add $t6, $t6, $t2
subi $t0, $t0,1 #repeat addition A number of times
j loop_C_A
exit4:
sub $t9, $t5, $t6 #compute g result
#input resultG_ten
la $a0, resultG_ten
li $v0,4
syscall
move $a0, $t9 #move G result into $a0
li $v0,1 #print G in decimal
syscall
#newline
li $v0,4
la $a0, newline
syscall
#input resultG_b
la $a0, resultG_b
li $v0,4
syscall
move $a0, $t9 #move G result into $a0
li $v0,35 #print G in binary
syscall
#newline
li $v0,4
la $a0, newline
syscall
#exit program
li $v0,10
syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions