Question

I have a MIPS program in which I need to get the state of individual bits in a word stored in the memory at a certain address. How can that be achived?

To clerify - I have a word in memory and its adressed is stored in the register $t0 and the word is stored at register $s0for example. How can I traverse thru each one of its bits and get its state?

It looks something like that by now:

.data
num: .WORD 481516
.text
la $t0, num
lw $s0, 0($t0)

(I need to eventually find out how many bits in the word are 1s and how many are 0s).

Was it helpful?

Solution

Consider the following pseudo-code:

count = 0
while ($s0 > 0) {
    count += $s0 & 1
    $s0 = $s0 >> 1
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top