Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Write a program that counts the number of bit at 1 in the binary representation of a variable of type byte
- DIM EQU 8
- .MODEL small
- .STACK
- .DATA
- var DB 1
- .CODE
- .STARTUP
- MOV AL,var
- MOV CX,DIM
- XOR BX,BX
- ciclo: DEC CX
- SHR AL,1 ;Coincides to the division by 2
- JC sum
- ciclo1:
- CMP AL,0
- JNZ ciclo
- JZ ex ;So when I finish to cycle, It doesn't pass through sum cycle
- sum: INC BX
- JMP ciclo1
- ex:
- .exit
- END
- ;My strategy was: I divide my number
- ;always by 2, and whenever that I have remainder, that is
- ;when the Carry Flag is up to 1, go in sum cycle
- ;and increases BX that acts as a counter, then return
- ;at ciclo the value 1 (it is optional) so
- ;I regain the code where I was remained
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement