對於我的任務,我們給出了一個名稱數組和一個代表對應名稱(基本上是字典或地圖)的年齡的整數數組。我們應該從用戶那裏讀取一個字符串,如果這個名字在數組中,那麼我們打印這些人的年齡。繼承人是我到目前爲止有:MIPS:訪問並比較字符串數組中的元素
.data
names: .asciiz "steve","john","chelsea","julia","ryan"
ages: .byte 20,25,22,21,23
out1: .asciiz "Please enter a name:"
out2: .asciiz "Age is: "
notfound: .asciiz "Not found!"
input: .asciiz
.text
li $v0, 4
la $a0, out1
syscall #prompts user for name
li $v0, 8
la $a0, input
li $a1, 20
syscall #Reads a name into address "input"
CheckNames: #needs to compare the input string with each element of "names" array and return 1 if they match
la $t0, (names)
la $t1, (input)
beq $t1, $t0, printAge
printAge:
我意識到,我的CheckNames功能是錯誤的,但我不知道如何通過名稱數組迭代時每名尺寸不同(因爲我不能用一個偏移量以獲得下一個名稱)
查看此答案:http://stackoverflow.com/a/26045398/583570 – markgz 2014-09-26 01:44:05