For my assignment we are given an array of names and an array of integers which represent the ages of the corresponding names (this is basically a dictionary or a map). We are supposed to read in a string from the user, and if that name is in the array, then we print that persons age. Heres what I have so far:
.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:
I realize that my CheckNames function is wrong, but I don't know how to iterate through the array of names when each name differs in size (since I can't use an offset to get to the next name)