8086 Assembly Program to Convert Binary Number into BCD Format

DATA SEGMENT
NO1 DB "1001000000110110"
D1 DW 4 DUP (?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, NO1
LEA DI, D1
MOV CX, 04H
TOP:
MOV BX, 00H
MOV AX, [SI]
ROR AX, 1
JNC P2
ADD BX, 08H
P2:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P3
ADD BX, 04H
P3:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P4
ADD BX, 02H
P4:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P5
ADD BX, 01H
P5:
MOV [DI], BX
INC DI
INC SI
DEC CX
JNZ TOP
INT 3
CODE ENDS
END START

Output

C:\TASM>MASM binbcd.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [binbcd.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:
50324 + 450332 Bytes symbol space free
0 Warning Errors
0 Severe Errors
C:\TASM>LINK BINBCD.OBJ
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
Run File [BINBCD.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment
C:\TASM>DEBUG BINBCD.EXE
-G
AX=0498 BX=0006 CX=0000 DX=0000 SP=0000 BP=0000 SI=0010 DI=0014
DS=0B97 ES=0B87 SS=0B97 CS=0B99 IP=0041 NV UP EI PL ZR NA PE NC
0B99:0041 CC INT 3
-D 0B97:0000
0B97:0000 31 30 30 31 30 30 30 30-30 30 31 31 30 31 31 30 1001000000110110
0B97:0010 09 00 03 06 00 00 00 00-00 00 00 00 00 00 00 00 ................
0B97:0020 B8 97 0B 8E D8 8D 36 00-00 8D 3E 10 00 B9 04 00 ......6...>.....
0B97:0030 BB 00 00 8B 04 D1 C8 73-03 83 C3 08 46 8B 04 D1 .......s....F...
0B97:0040 C8 73 03 83 C3 04 46 8B-04 D1 C8 73 03 83 C3 02 .s....F....s....
0B97:0050 46 8B 04 D1 C8 73 03 83-C3 01 89 1D 47 46 49 75 F....s......GFIu
0B97:0060 CF CC 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.*[email protected].
-Q

Leave a Reply

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