我遇到了一些 MIPS 代码的问题,其中数组的前 2 个元素被覆盖。我接受来自用户的 4 个不同的输入,每个输入一个字节,然后将它们存储在大小为 4 的“.space”中。当我全部打印它们时,前 2 个元素是空白的。我认为这与回车有关,但我不完全确定。这是我正在使用的:
.data
msg: .asciiz "Enter the band colors\n"
band12: .asciiz "Value bands (first 2 band colors)\n"
bandM: .asciiz "Multiplier band\n"
bandT: .asciiz "Tolerance band\n"
buffer: .byte '0'
userInput: .space 4
normalized: .word 0
tolerance: .ascii ""
.text
main: li $v0, 4
la $a0, msg
syscall
la $a0, band12
syscall
la $t0, userInput #store the input array in a register
li $v0, 8 #read the first input into buffer
la $a0, buffer
la $a1, 8
syscall
#store the input into the first element of the input array
lb $t1, buffer
sb $t1, ($t0)
#read the second input into buffer
la $a0, buffer
la $a1, 8
syscall
lb $t2, buffer #store the input into the second element of the input array
sb $t2, 1($t0)
#3rd band message
li $v0, 4
la $a0, bandM
syscall
#read in 3rd band
li $v0, 8
la $a0, buffer
la $a1, 8
syscall
#move to 3rd array index
lb $t3, buffer
sb $t3, 2($t0)
#last prompt
li $v0, 4
la $a0, bandT
syscall
#read tolerance band
li $v0, 8
la $a0, buffer
la $a1, 8
syscall
#move to 4th array index
lb $t4, buffer
sb $t4, 3($t0)
li $v0, 11
lb $a0, ($t0)
syscall
lb $a0, 1($t0)
syscall
lb $a0, 2($t0)
syscall
lb $a0, 3($t0)
syscall
jr $ra
li $v0, 10
syscall
这是 QtSpim 的输出。