Fellow SO users
I'm hoping someone could explain the behavior that I am experiencing whilst using SPIM to run my MIPS code. I'm implementing an encryption algorithm and one of the steps is loading the encryption key which is 64 bits wide. For example, if the encryption key is 0x123456789ABCDEF0
, I'm declaring it in the following way;
.data
enc_key_lo: 0x78563412
enc_key_hi: 0xF0DEBC9A
Now, whenever I load enc_key_lo
first, I check to see whether I encounter a 0
so that I can load enc_key_hi
. The following is my code;
.text
la $a1, enc_key_lo
la $a2, enc_key_hi
load_lo:
lbu $s0, 0($a1)
addi $a1, $a1, 1
beq $s0, $zero, load_hi #If 0, then we need to load enc_key_hi
j load_lo
load_hi:
lbu $s1, 0($a2)
addi $s2, $s2, 1
/* DO SOME OPERATIONS ETC ETC */
When I run the code, I observe the register $s0
loads with the following on successive iterations of the load_lo
loop;
12, 34, 56, 78, 9A, BC, DE, F0
I was expecting register $s0
to load with 0 after loading 78
but it keeps loading all the way till F0
. Hence, this defeats the purpose of having the load_hi
segment in the code. I noticed that if I commented out the declaration enc_key_hi
, then $s0
is loaded with 0
after loading with 78
.
Could someone please explain this behavior? Kind regards.