MPL EXP3
MPL EXP3
3
ALP to add 4-digit BCD numbers
Date of Performance: 30/01/2025
Date of Submission: 13/02/2025
Aim:
Write ALP to add 4 digit BCD numbers. Operands and data should be in the data
segment.
Objective:
To emphasize instruction set and logic to build assembly language programs on BCD
arithmetic operations.
Theory:
DAA instruction is used to make sure that the result of adding two packed BCD numbers is
adjusted to be a valid BCD number. It operates only on AL register. If number in the lower
nibble of AL register after addition is greater than 9 or if the auxiliary carry flag is set then
add 6. If the higher nibble of AH is greater than 9 or if the carry flag is set, then add 60H.
Algorithm:
Load the lower part of the 16-bit BCD numbers in different locations.
Make the lower part of register 00 and add the carry. This is done to obtain the carry.
Display all the numbers with highest part as carry, middle part as addition of the higher BCD
.model small
.data
a dw 3456H
b dw 4567H
c dw ?
car db ?
.code
mov ax,@data
mov ds,ax
mov ax,a
mov bx,b
add al,bl
daa
mov cl,al
mov al,ah
adc al,bh
daa
mov ch,al
mov c,cx
mov al,00H
adc al,al
mov car,al
mov ah,4CH
int 21H
end
Before:
After:
This Assembly Language Program (ALP) successfully adds two 4-digit BCD numbers,
demonstrating the importance of the DAA (Decimal Adjust after Addition) instruction in BCD
arithmetic. By carefully handling lower and upper nibbles separately, the program ensures
valid BCD results. The algorithm effectively manages carries and adjustments using DAA,
ensuring accuracy in computations. This implementation highlights key assembly
instructions and logical operations essential for BCD-based calculations. Understanding such
operations is crucial for low-level programming, where precision in number representation
matters. The program also reinforces concepts like carry handling, flag manipulation, and
structured arithmetic operations in assembly language.
Questions:
1. What is a BCD (Binary-Coded Decimal) number, and how does it differ from a binary
number?
Ans: A BCD (Binary-Coded Decimal) represents each decimal digit (0-9) using 4 bits, ensuring
decimal alignment. In contrast, a binary number represents values in base-2 without
separation. BCD simplifies decimal calculations but is less space-efficient than binary, as it
wastes combinations (A-F in hexadecimal).
2. Explain the significance of the DAA (Decimal Adjust after Addition) instruction in
Ans: The DAA (Decimal Adjust after Addition) instruction ensures valid BCD results after an
addition operation. It adjusts the AL register by adding 6 if a nibble exceeds 9 or an
auxiliary/carry flag is set, preventing invalid BCD representations, thus maintaining accurate
decimal calculations in assembly programming.
Ans: Without adjustment, results may contain invalid BCD digits (A-F), leading to incorrect
outputs. Adjusting ensures proper decimal representation and prevents computational
errors, particularly in financial and embedded systems requiring precise decimal arithmetic.
DAA corrects such inconsistencies, ensuring accurate addition of BCD numbers.
4. What precautions must be taken while adding multi-digit BCD numbers to ensure the
4. Correct digit placement to maintain alignment, ensuring the result remains a valid
BCD number.