I have just spent most of today (sunday) working on my assembly programming assignment..its finished by the way.....lol, I just have to write another version of the code that runs faster. It was just a matrix multiplication code in C that we had to rewrite in MIPS 64 Assembly. The hardest part for me was knowing how to calculate the index in a 2-d array in assembly. I finally figured it out, so check this out:
consider a simple 2-d array a[i][j]. To get the element at this location, we simply use the formula:
(i * max_index_of_i +j)<<3.
We need to shift by 3, because in assembly, we are just stepping through an array, and each element occupies 8 bits.
So this principle is shown in MIPS64 assembly code to reference p[i][k] in a 3x3 array.
daddi $t7, $r0, 3 ; $t7=3
dmul $t6, $t0, $t7 ; $t6=i*3
dadd $t6 , $t6, $t2 ; i*3 +k
dsll $t4, $t6, 3 ; $t4=(i*3+k)<<3 multiply by 3
daddi $t8, $r0, p ; get base address of p
dadd $t8, $t8,$t4 ; $t8 has the address of p[i][k]
lw $t9, 0($t8) ; $t9 has the value of p[i][k]
Now I am getting back to debugging. See you later!
Subscribe to:
Post Comments (Atom)
1 comment:
This one wey you sabi technology, come help my computer now...
Post a Comment