0
我不知道如何检查内存地址并查看数组内是否存在单词。检查内存中的值是否已经存在
如果我有下面的代码,其中$ T0包含数组
.data
array: .space 800 #For 200 integers
la $t0, table
sw $t1, 0($t0) #Add the value at t1 to the table
的基地址现在我将如何检查,如果我加入这个词已经在表中?
我不知道如何检查内存地址并查看数组内是否存在单词。检查内存中的值是否已经存在
如果我有下面的代码,其中$ T0包含数组
.data
array: .space 800 #For 200 integers
la $t0, table
sw $t1, 0($t0) #Add the value at t1 to the table
的基地址现在我将如何检查,如果我加入这个词已经在表中?
也许你可以用一些像这样的东西去:
.data
array: .space 800 #200 int á 4 bits
value: .word 0 #value
table: #some crazy value....
.text
.globl Main
MAIN:
li $t0, 0 #Loop-Start_Point
li $t1, 200 #LOOP-Break-Point
la $t2, table #load table
addi $t4, $t2, 0 #store table address
lw $t5, value #load value
li $t6, 4 #load multiplier
LOOP:
mul $t3, $t0, $t6 #calculate offset
addi $t2, $t2, $t3 #add offset
beg $t2, $t5, END #check if value is in table
addi $t0, $t0, 1 #add 1 to loop count
blt $t0, $t1, LOOP #if loop not finish -> LOOP:
STORE:
sw $t5, ($t4) #add value
END:
通过所有的项目维护元素的计数数组中,然后简单地循环和检查,如果你发现了它。哪一部分导致你的问题? – Jester
主要是循环本身,当我想到它时,我将不得不遍历数组本身,如果它存在分支。但是,我将如何遍历数组? –
哦,等等,我不得不将索引增加4。我想我明白要做什么,我会去尝试它。 –