简体   繁体   中英

MIPS Assembly Array of Pointers

I'm trying to create an array of pointers that correspond to a list of names, and another parallel array that keeps track of how many times those names have been displayed. I'm not looking for the method to display them, I would just like to know how to load the pointer array, and then load another array of ints that will start with all 0's. I define the names in a list of null terminated strings and then set aside some memory for my arrays, but I'm not sure how to put those addresses of the names into that array. Here's what I have:

.data
.space 5000
Listofnames:
.asciiz "   Jones \n"
.asciiz "   Smith \n"
.asciiz "   Johnson \n"
.asciiz "   Davis \n"
.asciiz "   Reid \n"
.asciiz "   Foster \n"
.asciiz "#"             # indicates end of name list, which can grow in size


.space 400
.align 2 # should this be 2? I thought it should be word aligned
pointer_array:

.space 400
.align 2 # should this be 2? I thought it should be word aligned
parallel_array:

As @Jester suggests, you can use labels to get the assembler to compute the address of each name, and use this labels to define what is in the array.

Another possibility would be to set aside the same amount of space for each name, so that the location of each name can be computed. This could be done using .ascii , specifying the null terminator within the string, and then adding enough characters after that so it fills out to the desired length. This takes more space, but avoids the need for an array of pointers to each individual name.

If you must generate an array of pointers to names, and you can't use labels, then you'll have to loop over the characters in Listofnames , and each time you find a null character (indicating the end of a name), the next location starts the next name (unless it contains a # , in which case you are done).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM