0
37kviews
Write 8086 assembly language program to count number of 0's and 1's in a given 8 bit number.
1 Answer
4
4.3kviews

Program:

Data segment.

NUM DB 564

ZEROS DB ?

ONES DB ?

Data ENDS

CODE SEGMENT

ASSUME CS : CODE, DS : DATA

START :

MOV AX, DATA

MOV . DS, AX ; Initialize Data Segment

MOV AL, NUM ; Get number into Accumulator

MOV BL, 00H ; initially ZERO count = 00H

MOV DL, 004 ; initially ONES count = 00H

MOV CX, 008 H ; initialize bit counter = 08 H

UP : ROL AL, 01H ; Rotate left 'NUM'

JC ONE ; IFCY = 1 go to label ONE

INC BL ; INC O'S Count.

Jmp NXT :

ONE : INC DL ; inc i's count

NXT : LOOP UP ; Dec cx and if cx = 0 go to up.

MOV ZEROS , BL ; ZEROS = no. of 0's 

MOV ONES, DL ; ONES = no. of 1's

INT 03H ; Terminate program by break point.

CODE ENDS interrupt

END.START
Please log in to add an answer.