Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

32-bit BCD Addition

By:
Rishi 4037 Gaurang 4065
Ravish 4076 Shivang 4110
What is BCD ??
BCD or Binary Coded Decimal is a coding scheme used to represent decimal number (0
to 9) in the form of binary digits of a group of 4-bits. Binary coded decimal is the simplest
form to convert decimal numbers into their equivalent binary format. Although, binary
coded decimal or BCD is not the same as the normal binary representation.

As we know, a 4-bit binary number can represent 16 decimal digits, but in binary coded
decimal, BCD codes 1010, 1011, 1100, 1101, 1110, and 1111 equivalent to decimal 10,
11, 12, 13, 14, and 15 are considered illegal combinations.
Decimal digit BCD code Decimal digit BCD code

0 0000 0 0000

1 0001 1 0001

2 0010 2 0010

3 0011 3 0011

4 0100 4 0100

5 0101 5 0101

6 0110 6 0110

7 0111 7 0111

8 1000 8 1000

9 1001 9 1001

10 10 0001 0000

11 11 0001 0001
Eg : 30 + 15

30 0011 0000
+15 + 0001 0101
45 0100 0101

Eg : 19 + 11 0001

19 0001 1001
+ 11 + 0001 0001

30 0011 0000
Code
.MODEL SMALL
.386
.data
num1 DD 0H
num2 DD 0H
num3 DD 0H
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The Resultant sum is :: $"
.code
.startup BREAK1:
MOV num1 , EBX
MOV AH , 09 MOV AH , 09
MOV DX , OFFSET msg MOV DX , OFFSET msg1
INT 21H ; printing INT 21H ; printing
msg msg1
MOV EBX , 0 MOV EBX , 0

GET_NUM_1: GET_NUM_2:
MOV AH , 01 MOV AH , 01
INT 21H ; getting INT 21H ;
digit getting digit
CMP AL , 'A’ CMP AL , 'A’
JGE EXIT JGE EXIT
CMP AL , 13 CMP AL , 13
JZ BREAK1 JZ BREAK2
SUB AL , 30H ; converting ascii to int SUB AL , 30H ; converting ascii to
SHL EBX , 4 int
ADD BL , AL SHL EBX , 4
JMP GET_NUM_1 ADD BL , AL
JMP GET_NUM_2
ADC AL , DH
BREAK2:
DAA
MOV num2, EBX
MOV BH , AL
ADDITION:
MOV word PTR num3+2 , BX
MOV AX , word PTR num1
MOV EBX , num3
MOV DX , word PTR num2
ADD AL , DL
MOV AH , 09
DAA
MOV DX , OFFSET msg2
MOV BL , AL
INT 21H ; printing
MOV AL , AH msg2
ADC AL , DH
DAA JNC A
MOV BH , AL MOV AH , 02H
MOV DL , "1“
MOV word PTR num3,BX INT 21H ; printing
MOV AX , word PTR num1+2 __
MOV DX , word PTR num2+2
ADC AL , DL A:
DAA MOV CX , 8
MOV BL , AL
MOV AL , AH
DISPLAY_NUM:
ROL EBX,4
MOV DL,BL
AND DL,0FH
ADD DL,30H
MOV AH,02
INT 21H
LOOP DISPLAY_NUM

EXIT:
MOV AH,4CH
INT 21H ; exiting to dos

.EXIT
END
Example output

Thank you

You might also like