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

This is my MIPS code. It\'s to calculate bmi score from the user\'s input and th

ID: 3591534 • Letter: T

Question

This is my MIPS code. It's to calculate bmi score from the user's input and then output the result. Please try to run it and tell me what is wrong with it. Thank you.

.data

a: .word 703

#height: .word 0

#weight: .word 0

bmi: .float 0

floats: .float 18.5, 25, 30

name: .asciiz "What is your name? "

inputBuffer: .space 20

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

weightInfo: .asciiz "Please enter your weight in pounds (round to a whole number): "

output1: .asciiz "This is considered underweight. "

output2: .asciiz "This is a normal weight. "

output3: .asciiz "This is considered overweight. "

output4: .asciiz "This is considered obese. "

.text

#lw $t1, height

#lw $t2, weight

#display message to ask for user's name

li $v0, 4

la $a0, name

syscall

#take user name

li $v0, 8

la $a0, inputBuffer

li $a1, 20

syscall

#ask user for height

li $v0, 4

la $a0, heightInfo

syscall

#take user height

li $v0, 5

syscall

move $t1, $v0

la $t3, 0($t1)

  

#ask user for weight

li $v0, 4

la $a0, weightInfo

syscall

#take user weight

li $v0, 5

syscall

move $t2, $v0

la $t4, 0($t2)

lwc1 $f0, a #f0 = 703

lwc1 $f2, 4($t3) #f2 = height

lwc1 $f4, 4($t4) #f3 = weight

lwc1 $f12, bmi #f12 = bmi

la $t0, floats

lwc1 $f14, ($t0)

lwc1 $f16, 4($t0)

lwc1 $f16, 8($t0)

cvt.s.w $f6, $f0

cvt.s.w $f8, $f2

cvt.s.w $f10,$f4

mul.s $f10, $f6, $f10 #weight = weight * 703

div.s $f12, $f10, $f8 #bmi = weight/height

c.lt.s $f12, $f14

bc1t exit1

c.lt.s $f12, $f16

bc1t exit2

c.lt.s $f12, $f18

bc1t exit3

li $v0, 4

la $a0, output4

syscall

#exit

li $v0, 10

syscall

exit1:

li $v0, 4

la $a0, output1

syscall

exit2:

li $v0, 4

la $a0, output2

syscall

exit3:

li $v0, 4

la $a0, output3

syscall

Explanation / Answer

The Answer for your question is given below clearly:

The MIPS code you have provided is missing some steps in calculating the BMI of a person so I have added those missing steps in the code and the total completed code is given below clearly

code:

.data

npr:.asciiz "What is your Name: "

wpr:.asciiz "Please enter your Weight in pounds: "

hpr:.asciiz "Please enter 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

Hope This Helps, if you have any doubts Please comment i will get back to you, thank you and please thumbs up

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