簡體   English   中英

MIPS組裝指針數組

[英]MIPS Assembly Array of Pointers

我正在嘗試創建與名稱列表相對應的指針數組,以及另一個跟蹤這些名稱已顯示多少次的並行數組。 我不是在尋找顯示它們的方法,我只是想知道如何加載指針數組,然后加載另一個以全0開頭的int數組。 我在以null結尾的字符串列表中定義名稱,然后為數組留出一些內存,但是我不確定如何將名稱的那些地址放入該數組中。 這是我所擁有的:

.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:

正如@Jester所建議的那樣,您可以使用標簽來獲取匯編程序以計算每個名稱的地址,並使用此標簽來定義數組中的內容。

另一種可能性是為每個名稱留出相同數量的空間,以便可以計算每個名稱的位置。 可以使用.ascii來完成,在字符串中指定空終止符,然后在其后添加足夠的字符,以使其填滿所需的長度。 這會占用更多空間,但無需使用指向每個單獨名稱的指針數組。

如果必須生成一個指向名稱的指針數組,並且不能使用標簽,則必須循環遍歷Listofnames的字符,並且每次找到空字符(指示名稱的結尾)時, next位置以姓氏開頭(除非它包含# ,在這種情況下您要完成)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM