Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- cod: .word 0x05 # store input in memory
- .text
- la x10, cod # load address
- lw x2, 0(x10) # load data from address
- li x7, 5 # loop counter
- li x4, 1 # to go through bits one by one
- li x8, 2 # desired result
- li x1, 0 # counts number of high bits
- andi x3, x2, 0xffffffe0 # mask lower 5 bits
- bne x3, x0, notacode # if any other bit is high, return 0
- back:
- and x5, x2, x4 # mask
- beq x5, x0, next # check if high
- addi x1, x1, 1 # increment 1 if high
- next:
- slli x4, x4, 1 # shift mask to next position
- addi x7, x7, -1 # update loop counter
- bne x7, x0, back
- bne x1, x8, notacode # check desired result
- addi x11, x0, 0xff # if satisfied store FF
- store:
- sb x11, 4(x10) # storing happens here
- j exit
- notacode:
- add x11, x0, x0 # else store 0
- beq x0, x0, store
- exit:
- nop # end of program
Add Comment
Please, Sign In to add comment