Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ code as pseudocode. The variable bmi can be single or double precision Write

ID: 3836882 • Letter: C

Question

C++ code as pseudocode. The variable bmi can be single or double precision Write a MIPS program that calculates bmi. Use the following #include kiostream> 2 finclude using namespace std 5 int main() int height 0, weight 0; double bmi: string name; 10 Prompt user for their data 11 cout "What is your name? 12 cin name 13 14 15 cout Please enter your height in inches 16 cin height. cout Now enter your weight in pounds round to a whole number) 18 cin weight; 19 Calculate the bmi 20 weight 703 21 22 height height bmi static cast

Explanation / Answer

.data

npr:.asciiz "What is your name?"

wpr:.asciiz "Now enter your weight in pounds(round to a

whole number): "

hpr : .asciiz "Please enter your height in inches: "

bpr : .asciiz " Calculated BMI: "

name: .space 20
weight: .word

height: .word

bmi: .float

bmivals:.float 18.5, 25, 30

bmipr: .asciiz " This is considered "

bmiprs: .asciiz "underweight. ", "normal weight. ", "overweight.

", "obese. "

.text

main:

li $v0 33

li $a0 52

li $a1 20

li $a2 22

li $a3 127

syscall

# Prompt name

la $a0 npr

li $v0 4

syscall

#Load input into name

li $v0 8

la $a0 name

syscall

# Remove newline from input

li $t0 -1

index: addi $t0 $t0 1

lb $t1 name($t0)

bne $t1 0xA index

sb $zero name($t0)

# Prompt weight

la $a0 wpr

li $v0 4

syscall

# Load input into saved register $s0

li $v0 5

syscall

move $s0 $v0

# Prompt height

la $a0 hpr

li $v0 4

syscall

# Load input into saved register $s1

li $v0 5

syscall

move $s1 $v0

# Calculations

mul $s0 $s0 703

mul $s1 $s1 $s1

mtc1 $s0 $f20

cvt.s.w $f20 $f20

mtc1 $s1 $f21

cvt.s.w $f21 $f21

div.s $f12 $f20 $f21

# Output BMI

la $a0 name

li $v0 4

syscall

la $a0 bpr

syscall

li $v0 2

syscall

# Determine weight class

li $t0 -4

la $t1 bmivals

status: addi $t0 $t0 4

add $t2 $t1 $t0

l.s $f22 ($t2)

c.le.s $f12 $f22

bc1f status

# Output judgement

li $v0 4

la $a0 bmipr

syscall

# v0 is unchanged, so it is left.

# t0 is set to the word index

# The string array has 15 characters, and a null char. This

makes the offset for each index 16.

# The offset calculated in the status loop is multiplied by four

to compute the string offset.

la $t1 bmiprs

sll $t0 $t0 2

add $t2 $t1 $t0

la $a0 ($t2)

syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote