MIPS字符串第一个字符未显示

时间:2017-03-09 03:50:22

标签: string mips

因此我的MARS MIPS模拟器发生了一个奇怪的问题。

我的字符串取用了用户的名字,似乎正在删除他们名字的第一个字符。我不能为我的生活找出原因。

.data
    height: .asciiz "enter your height"
    weight: .asciiz "enter your weight"
    little: .float 18.5
    medium: .float 25
    large: .float 30
    fpconstant: .float 703
    bmi: .float
    under: .asciiz "This is considered underweight"
    health: .asciiz "This is considered healthy"
    overweight: .asciiz "This is considered overweight"
    obese: .asciiz "This is considered obese."
    name: .asciiz ", here are your BMI results\n"
    prompt: .asciiz "Please enter your name"
    buffer: .space 20

.text

main: li $v0, 4
la $a0, prompt
syscall

li $v0, 8
syscall

la $a0, buffer  # load byte space into address
    li $a1, 20      # allot the byte space for string
   move $t6, $a0   # save string to t6
   syscall

li $v0, 4
la $a0, weight
syscall

li $v0, 6
syscall



movf.s $f1, $f0 #f1 now contains weight, will continue after this correction has been made.
l.s $f2, fpconstant
mul.s $f0, $f1, $f2

movf.s $f1, $f0
movf.s $f12, $f0

li $v0, 4
la $a0, height
syscall

li $v0, 6
syscall


movf.s $f2, $f0 #f2 now contains height, will continue after this correction has been made.
mul.s $f0, $f2, $f2
movf.s $f2, $f0
movf.s $f12, $f0

div.s $f3, $f1, $f2 #f3 is our BMI
movf.s $f12, $f3

la $a0, buffer  # reload byte space to primary address
    move $a0, $t6  # primary address = t6 address (load pointer)
    li $v0, 4       # print string


syscall #Problem


la $a0, name
move $t0, $a0
syscall


li $v0, 2
syscall

l.s $f4, little
c.lt.s $f3,$f4
bc1t underweight  #Branch if specified FP condition flag true (BC1T, not BCLT) : If Coprocessor 1 condition flag specified by immediate is true (one) then branch to statement at label's address       #  Compare less than single precision : If $f0 is less than $f1, set Coprocessor 1 condition flag 0 true else set it false

l.s $f4, medium
c.lt.s $f3,$f4
bc1t mid  

l.s $f4, large
c.lt.s $f3,$f4
bc1t big  

li $v0, 4
la $a0, obese
syscall

li $v0, 10
syscall

underweight: 
li $v0, 4
la $a0, under
syscall

li $v0, 10
syscall

li $v0, 10
syscall

mid: 
li $v0, 4
la $a0, health
syscall

li $v0, 10
syscall

big: 

li $v0, 4
la $a0, overweight
syscall

li $v0, 10
syscall

我为格式错误道歉 - 这是我曾经问过的第一个问题。谢谢!

1 个答案:

答案 0 :(得分:0)

您的实际问题在代码中更进一步(例如,当您第一次使用inputEl.triggerEventHandler('change', { target: { value: '-5'}}); 读取名称时)。 <{1}} syscall 8之后

此外,似乎你对某些la $a0,buffer有点自由。 (例如syscall两个 syscall,但只需要一个)。 我已经注释了你的代码并清理了一些注释,并修复了这个bug。我也重新格式化了它:

underweight: