Moving bits using srlv in Mips

Viewed 13

Currently I have an Array of a length of 8 bytes, assuming all the bits in the Array alternate between 0 and 1 [0, 1, 0, 1] etc, and I load the address of the Array like so:

la $t0, Array
li $t1, 1
srlv $t2, $t0, $t1

Would the array become [1, 0, 1]? I'm supposed to get bits from within a byte in MIPS and this was the method I was going to use, I don't know a better way right now, but any help is appreciated.

1 Answers

Would the array become [1, 0, 1]

No, you're not accessing the array.  The array lives in memory.  To access the array from memory, you would minimally need to use some kind of load instruction.  To modify the array, you will minimally use some kind of store instruction.

You code sample is shifting the address of the array.  The address is a number — which itself it is not the array, but a reference to the array, the memory location of the start of the array in memory.

Related