0
我應該存儲10個記錄的數組,每個記錄有一個名稱(40個字符),年齡和工資。在一個數組中存儲記錄與mips
我已經做了一個循環來存儲用戶輸入和另一個循環打印出來,但我的輸出顯示了不同的東西。我不確定我是否正確存儲記錄?請諮詢。
這是我的輸出。爲了測試我只有3條記錄。
There are 10 records.
first employee
23
20
second employee
34
20
third employee
25
23
third employee
23
20
23
20
23
20
-- program is finished running --
我的代碼是這樣的:
loop:
bgt $t0, $a2, print #counter = size go to print
#store name
li $v0, 40
li $v0, 8
syscall
#reads and store the age
li $v0, 5
syscall
sb $v0, 40($a1)
#reads and stores the salary
li $v0, 5
syscall
sb $v0, 44($a1)
addi $t0, $t0, 1 #up counter
addiu $a1, $a1, 12 #shift to the next value? may be error here
b loop
print:
beqz $t0, end #counter = 0; end
li $v0, 4
la $a1, Records
syscall #print name
li $v0, 1
lb $t1, 40($a1)
move $a0, $t1
syscall #print age
la $a0, newline
li $v0, 4
syscall #newline
li $v0, 1
lb $t1, 44($a1)
move $a0, $t1
syscall #print salary
la $a0, newline
li $v0, 4
syscall
addi $t0, $t0, -1 #decrement
addiu $a1, $a1, 12
b print