Questions : 1. Explain the procedure for addition of two BCD numbers. 2. Explain the procedure for subtraction of two BCD numbers.
BCD Arithmetic
Lab Experiment 3.4.1 : Add two 2-digit BCD numbers.
Statement :
Add two 2 digit BCD numbers in memory location 2200H and 2201H and store the
result in memory location 2300H.
Sample
problem :
(2200H)
= 39
(2201H)
= 45
Result
= (2300H) = 39 + 45
=
7E + 6 = 84
(lower
nibble is greater than 9 so add 6)
Source
program :
LXI
H, 2200H ; Initialize pointer
MOV
A, M ; Get the first number
INX
H ; Increment the pointer
ADD
M ; Add two numbers
DAA
; Convert HEX to valid BCD
STA
2300H ; Store the result
HLT
; Terminate program executaion
Lab Experiment 3.4.2 : Add two 4-digit
BCD numbers.
Statement :
Add two 4 digit BCD numbers in HL and DE register pairs and store result in
memory locations, 2300H and 2301H. Ignore carry after 16 bit.
Sample
problem :
(HL)
= 3629
(DE)
= 4738
Step
1 :
29
+ 38 = 61 and auxiliary carry flag = 1
add
06
61
+ 06 = 67
Step
2 :
36
+ 47 + 0 (carry of LSB) = 7D
Lower
nibble of addition is greater than 9
so
add 6.
7D
+ 06 = 83
Result
= 8367
Source
program :
MOV
A, L ; Get lower 2 digits of no. 1
ADD
E ; Add two lower digits
DAA
; Adjust result to valid BCD
STA
2300H ; Store partial result
MOV
A, H ; Get most significant 2 digits of no. 2
ADC
D ; Add two most significant
;
digits
DAA
; Adjust result to valid BCD
STA
2301H ; Store partial result
HLT
; Terminate program
;
execution.
Lab Experiment 3.4.3 : Subtraction of
two BCD numbers.
Statement :
Subtract the BCD number stored in E register from the number stored in the D
register.
Source
program :
MVI
A,99H
SUB
E ; Find the 99's complement of subtrahend
INR
A ; Find 100's complement of subtrahend
ADD
D ; Add minuend to 100's complement of subtrahend
DAA
; Adjust for BCD
HLT
; Terminate program execution
Lab Experiment 3.4.4 : Multiply two
2-digit BCD numbers
Statement :
Write an assembly language program to multiply 2 BCD numbers
Source
program :
MVI
C, Multiplier ; Load BCD
multiplier
MVI
B, 00 ; Initialize counter
LXI
H, 0000H ; Result = 0000
MVI
E, multiplicand ; Load multiplicand
MVI
D, 00H ; Extend to 16-bits
BACK
: DAD D ; Result ← Result + Multiplicand
MOV
A, L ; [ Get the lower
ADI,
00H ; byte of the result
DAA ; Adjust it to BCD and
MOV
L, A ; store it]
MOV
A, H ; [ Get the higher
ACI,
00H ; byte of the result
DAA ; Adjust it to BCD and
MOV
H, A ; store it]
MOV
A, B ; [ Increment
ADI
01 H ; counter
DAA ; adjust it to BCD and
MOV
B, A ; store it]
CMP
C ; Compare if count = multiplier
JNZ
BACK ; if not equal repeat
HLT ; Stop
Review Questions
1. Explain the
procedure for addition of two BCD numbers.
2. Explain the procedure for subtraction of two BCD numbers.
Microprocessors and Microcontrollers: Unit II: (b) Looping, Counting, Time Delays & Code Conversion : Tag: : - BCD Arithmetic
Microprocessor and Microcontroller
EE3404 MCU 4th Semester EEE Dept | 2021 Regulation | 4th Semester EEE Dept 2021 Regulation