1

I'm not sure how to do check a memory address and see if a word exists inside of the array.

If I have the following code, where $t0 contains the base address of the array

.data
array: .space 800 #For 200 integers

la $t0, table
sw $t1, 0($t0) #Add the value at t1 to the table

Now how would I check if the word i added is already in the table?

  • Maintain a count of the elements in the array, then simply loop through all the items and check if you found it. Which part is causing you problems? โ€“ Jester Oct 06 '15 at 00:51
  • Mainly the loop itself, while I think about it I would have to traverse the array itself than if it exists branch out. But how would I traverse the array? โ€“ James Cortez Oct 06 '15 at 01:07
  • Oh wait, I would have to increment the index by 4. I think I understand what to do, I'll go attempt it. โ€“ James Cortez Oct 06 '15 at 01:12

1 Answers1

0

Maybe you could go with some thing like this:

.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:
Thomas Meyer
  • 384
  • 1
  • 11