Wednesday, October 30, 2013

To count number of zeros and ones

;To count number of zeros and ones
.8086
.model small
.data
num db 05h ;Storing 05h number as our original number
.code
start:
mov ax,@data
mov ds,ax
mov dx,0000h
mov cx,0000h
mov bx,08h ;Storing 08 in bx as a counter
mov al,num
BACK: ROR Al,1 ;Rotate al by 1
JNC TG ;Jump if no carry
INC dx ;Increment counter dx
TG: INC cx
DEC bx
JNZ BACK
mov ax,4c00h
INT 21H
END start

;Output
;Num:05H
;cx:06h
;dx:02h

No comments:

Post a Comment