8086 Assembly Program to Count Number of 0’s and 1’s from a Number

DATA SEGMENT
NO DW 5648H
Z DW ?
O DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AX, NO
MOV BX, 00H
MOV CX, 10H
MOV DX, 00H

UP:
ROL AX,1
JC ONE
INC BX
JMP NXT

ONE:
INC DX

NXT:
DEC CX
JNZ UP

MOV Z, BX
MOV O, DX

INT 3
CODE ENDS
END START

Output

 C:\TASM>masm czo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.

Object filename [czo.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:

  50422 + 450234 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors

C:\TASM>link czo.obj

Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.

Run File [CZO.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment

C:\TASM>debug CZO.EXE
-g

AX=5648  BX=000A  CX=0000  DX=0006  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B97  ES=0B87  SS=0B97  CS=0B98  IP=0025   NV UP EI PL ZR NA PE NC
0B98:0025 CC            INT     3
-d 0b97:0000
0B97:0000  48 56 0A 00 06 00 00 00-00 00 00 00 00 00 00 00   HV..............
0B97:0010  B8 97 0B 8E D8 A1 00 00-BB 00 00 B9 10 00 BA 00   ................
0B97:0020  00 D1 C0 72 04 43 EB 02-90 42 49 75 F4 89 1E 02   ...r.C...BIu....
0B97:0030  00 89 16 04 00 CC E8 77-63 83 C4 06 FF 36 24 21   .......wc....6$!
0B97:0040  B8 0A 00 50 E8 47 5E 83-C4 04 5E 8B E5 5D C3 90   ...P.G^...^..]..
0B97:0050  55 8B EC 81 EC 84 00 C4-5E 04 26 80 7F 0A 00 74   U.......^.&....t
0B97:0060  3E 8B 46 08 8B 56 0A 89-46 FC 89 56 FE C4 5E FC   >.F..V..F..V..^.
0B97:0070  26 8A 47 0C 2A E4 40 50-8B C3 05 0C 00 52 50 E8   &.G.*.@P.....RP.
-q

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.