Как правильно получить и вывести имя и полученный ИМТ с именем в MIPS? - PullRequest
0 голосов
/ 09 октября 2018

Это код C ++, и я должен использовать его в качестве псевдокода для моего кода MIPS

Это мой код MIPS.Всякий раз, когда я запускаю его и ставлю имя, я могу ввести только одну букву, после чего она автоматически переходит к следующей подсказке.Он также не выводит имя и результирующий ИМТ, например, как это должно быть.

.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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...