简体   繁体   English

MIPS组装指针数组

[英]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. 我不是在寻找显示它们的方法,我只是想知道如何加载指针数组,然后加载另一个以全0开头的int数组。 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. 我在以null结尾的字符串列表中定义名称,然后为数组留出一些内存,但是我不确定如何将名称的那些地址放入该数组中。 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. 正如@Jester所建议的那样,您可以使用标签来获取汇编程序以计算每个名称的地址,并使用此标签来定义数组中的内容。

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. 可以使用.ascii来完成,在字符串中指定空终止符,然后在其后添加足够的字符,以使其填满所需的长度。 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). 如果必须生成一个指向名称的指针数组,并且不能使用标签,则必须循环遍历Listofnames的字符,并且每次找到空字符(指示名称的结尾)时, next位置以姓氏开头(除非它包含# ,在这种情况下您要完成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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