Skip to content

Instantly share code, notes, and snippets.

@tremblerz
Created February 11, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tremblerz/84c392e793f1e49ccc5f to your computer and use it in GitHub Desktop.
Save tremblerz/84c392e793f1e49ccc5f to your computer and use it in GitHub Desktop.
# 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