0% found this document useful (0 votes)
3 views

MPL EXP3

The document outlines an assembly language program (ALP) designed to add 4-digit BCD numbers, emphasizing the use of the DAA instruction for valid BCD results. It includes an algorithm, program code, and a conclusion highlighting the importance of carry handling and flag manipulation in BCD arithmetic. Additionally, it addresses common questions regarding BCD representation, the significance of DAA, and precautions for accurate multi-digit BCD addition.

Uploaded by

saiesh.232793105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

MPL EXP3

The document outlines an assembly language program (ALP) designed to add 4-digit BCD numbers, emphasizing the use of the DAA instruction for valid BCD results. It includes an algorithm, program code, and a conclusion highlighting the importance of carry handling and flag manipulation in BCD arithmetic. Additionally, it addresses common questions regarding BCD representation, the significance of DAA, and precautions for accurate multi-digit BCD addition.

Uploaded by

saiesh.232793105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No.

3
ALP to add 4-digit BCD numbers
Date of Performance: 30/01/2025
Date of Submission: 13/02/2025

CSL404: Microprocessor Lab


Experiment No. -3

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.

Add each number by adding first its lower part.

Repeat the above step also by adding the carry if any.

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

8-bits and lower part as the lower BCD 8-bits.

CSL404: Microprocessor Lab


Program:

.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

CSL404: Microprocessor Lab


Output:

Before:

After:

CSL404: Microprocessor Lab


Conclusion:

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

handling BCD numbers in assembly language.

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.

CSL404: Microprocessor Lab


3. Why is it necessary to adjust the result after adding BCD numbers? What might

happen if this step is skipped?

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

correctness of the result?

Ans: When adding multi-digit BCD numbers, ensure:

1. DAA adjustment after each 8-bit addition.

2. Carry handling between adjacent digits.

3. Proper initialization of registers to avoid overflow errors.

4. Correct digit placement to maintain alignment, ensuring the result remains a valid
BCD number.

CSL404: Microprocessor Lab

You might also like