Count number of 1’s in register in Assembly – masm 8086

Count number of 1’s in register in Assembly – masm 8086

org 100h
.stack 100h
.data
counter DB 0
.code
;Initlization of Data Segment
mov ax,@DATA
mov DS,ax
mov bx,0F0Fh
;Count number of 1's in ax register
mov ax,0F0Fh
mov dx,0000h
mov cx,2
L:
mov cx,2
div cx
cmp dx,1
je INC_COUNTER
back:
cmp ax,0
je exit
mov dx,0000h
LOOP L
INC_COUNTER:
inc counter
jmp back
exit:
;to terminate program
mov ah,4ch
int 21h
ret

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s