This is my code in MIPS. Please go over and let me know what is wrong with it. T
ID: 3591388 • Letter: T
Question
This is my code in MIPS. Please go over and let me know what is wrong with it. Thank you.
.data
a: .word 703
height: .word 0
weight: .word 0
bmi: .float 0
number1: .float 18.5
number2: .float 25
number3: .float 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, ($t1)
#ask user for weight
li $v0, 4
la $a0, weightInfo
syscall
move $t2, $v0
la $t4, ($t2)
#take user weight
li $v0, 5
syscall
move $t2, $v0
lwc1 $f0, a #f1 = 703
lwc1 $f2, ($t1) #f2 = height
lwc1 $f4, ($t2) #f3 = weight
lwc1 $f12, bmi #f12 = bmi
lwc1 $f14, number1
lwc1 $f16, number2
lwc1 $f18,number3
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, $f2 #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
hm4 comparbiity Mode] Word X Cu Find Write a MIPS program that calculates bmi. Use the following C++ code as pseudocode. The variable bmi can be single or double precision. 1 include include using namespace std: int main) int height 0, weight = 0; double hmi: string name 10 rompt user tor their data 12 13 14 15 1 6 17 19 19 20 21 cout nama: cout "Please enter your height in inches: rin >> height; cout (weight) / height; 24 output the results coutExplanation / Answer
The Coding you have done is missing some statements and instructions to calculate the BMI of a person so i have done proper coding and giving you the perfect code below
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.