Created
February 11, 2016 19:33
-
-
Save tremblerz/84c392e793f1e49ccc5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# count significant bits in bit battern | |
.text | |
.globl main | |
lui $8, 0x0029 #register 8 contains bit battern to check for sigbits | |
ori $8, $8, 0x8D7D | |
addiu $10, $0, 32 #exit upper loop counter value | |
ori $5, $0, 0 | |
lui $5, 0x8000 #register 5 contains our bit battern to check for | |
loop: | |
and $4, $8, $5 #if left bit is 1 exit | |
beq $4, $5, exit | |
sll $8, $8, 1 #shift left | |
beq $1, $10, exit #if counter is 32 exit | |
sll $0, $0, 0 | |
j loop | |
addiu $1, $1, 1 #increment counter in branch delay slot | |
exit: | |
sub $1, $10, $1 #replace the count register with the answer | |
done: | |
j done | |
sll $0, $0, 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment