如何在MIPS中正确获取和输出名称以及带有名称的结果BMI?

时间:2018-10-09 03:31:58

标签: mips

This is the C++ code and I am supposed to use this as a pseudocode for my MIPS code

这是我的MIPS代码。每当我运行它并输入名称时,我只会输入一个字母,然后它会自动转到下一个提示。它也不会像预期的那样输出名称和生成的BMI。

.data
#initializes the height and weight variable
n: .word 703
height: .word 0
weight: .word 0
bmi:    .float 0.0
nameBuffer: .space 20
underweight:    .float 18.5
normalweight:   .float 25.0
overweight: .float 30.0
name:   .asciiz "What is your name? \n"
displayHeight:  .asciiz "\nPlease enter your height in inches: \n"
displayWeight:  .asciiz "Now enter your weight in pounds (round to whole number): \n"
condition1: .asciiz "\nThis is considered underweight.\n"
condition2: .asciiz "\nThis is considered normal weight. \n"
condition3: .asciiz "\nThis is considered overweight. \n"
condition4: .asciiz "\nThis is considered obese. \n"

.text
main:
#prompt name
la  $a0, name
li  $v0, 4
syscall
#get name
li  $v0, 8
la  $a0, nameBuffer
syscall

#prompt height
la  $a0, displayHeight
li  $v0, 4
syscall
#get height
li  $v0, 5
syscall
sw  $v0, height

#prompt weight
la  $a0, displayWeight
li  $v0, 4
syscall
#get weight
li  $v0, 5
syscall
sw  $v0, weight

#Loading
lwc1    $f0, n #n = 703
lwc1    $f1, height 
lwc1    $f3, weight
lwc1    $f13, underweight
lwc1    $f17, normalweight
lwc1    $f20, overweight

#convert integer to double
cvt.s.w $f5, $f0
cvt.s.w $f7, $f1
cvt.s.w $f8, $f3

#calculate bmi
mul.s   $f8, $f5, $f8 #weight*703
mul.s   $f7, $f7, $f7 #height*height=height
div.s   $f12, $f8, $f7 #weight/height=bmi
la  $a0, name
li  $v0, 4
syscall
li  $v0, 2 #display bmi in float
syscall

#if $f12 < $f13, then underweight
c.lt.s  $f12, $f13
#branch if true, then display1
bc1t    display1
#if $f12 < $f17, then normal weight
c.lt.s  $f12, $f17
#branch if true, then display2
bc1t    display2
#if $f12 < $f20, then overweight
c.lt.s  $f12, $f20
#branch if true, then display3
bc1t    display3
li  $v0, 4
la  $a0, condition4
syscall
#else quit
b   quit

display1:
li  $v0, 4
#print conditon1 message
la  $a0, condition1
syscall
b   quit

display2:
li  $v0, 4
#print condition2 message
la  $a0, condition2
syscall
b   quit

display3:
li  $v0, 4
#print condition3 message
la  $a0, condition3
syscall
quit:
#exit
li  $v0, 10
syscall

0 个答案:

没有答案