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

MPL EXP2

The document outlines an experiment to write assembly language programs for performing basic arithmetic operations (addition, subtraction, multiplication, and division) on two 16-bit numbers. It includes the aim, objectives, theoretical background, algorithms, and example code for each operation, as well as a conclusion emphasizing the importance of using specific instructions for efficient arithmetic calculations. Additionally, it provides questions and answers related to the necessity of initializing the data segment and the differences between 16-bit and 8-bit operations.

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)
5 views

MPL EXP2

The document outlines an experiment to write assembly language programs for performing basic arithmetic operations (addition, subtraction, multiplication, and division) on two 16-bit numbers. It includes the aim, objectives, theoretical background, algorithms, and example code for each operation, as well as a conclusion emphasizing the importance of using specific instructions for efficient arithmetic calculations. Additionally, it provides questions and answers related to the necessity of initializing the data segment and the differences between 16-bit and 8-bit operations.

Uploaded by

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

Experiment No.

2
ALP to add, subtracts, multiply and divides two 16-bit numbers
Date of Performance: 16/01/2025
Date of Submission: 30/01/2025

CSL404: Microprocessor Lab


Experiment No. -2

Aim:

Write ALP to add, subtracts, multiply and divides two 16-bit numbers. Operands and data
should be in the data segment.

Objective:

To emphasize on instruction set and logic to build assembly language programs on basic 16-
bit arithmetic operations.

Theory:

Consider that a word of data is present in the AX register and second word of data is
present in the BX register. We have to add the byte in AX with the byte in BX. Using add
instruction add the contents of two registers. Result will be stored in the AX register.
Consider that a word of data is present in the AX register and second word of data is
present in the BX register. We have to subtract the word in BX from the word in AX. Using sub
instruction subtract the contents of two registers. Result will be stored in the AX register.
Consider that a word of data is present in the AX register and second word of data is
present in the BX register. We have to multiply the byte in AX with the byte in BX. Using mul
instruction, multiply the contents of two registers. Result is stored in the DX-AX register. The
MSB stored in DX and LSB in AX.
Consider that a word of data is present in the AX register and second word of data is
present in the BX register. We have to divide the word in DX-AX with the word in BX. Using
div instruction divide the contents of two registers. Result will be stored in the DX-AX register.
AX contains the quotient and DX contains the remainder.

Algorithm:

1. Initialize the data segment


2. Get the first number in AX register.
3. Get the second number in BX register.
4. Add/Subtract two numbers. Result in AX.
5. Multiply/Divide two numbers. Result in DX-AX.
6. Stop

CSL404: Microprocessor Lab


Addition Program:

assume cs:code, ds:data


data segment
a dw 0104h
b dw 0204h
c dw ?
data ends

code segment
start:
mov ax, data
mov ds, ax
mov ax, a
mov bx, b
add ax,bx
mov c,ax
int 03
code ends
end start

CSL404: Microprocessor Lab


Output:

Before:

After:

CSL404: Microprocessor Lab


Subtraction Program:

assume cs:code, ds:data


data segment
a dw 0404h
b dw 0304h
c dw ?
data ends

code segment
start:
mov ax, data
mov ds, ax
mov ax, a
mov bx, b
sub ax, bx
mov c, ax
int 03
code ends
end start

CSL404: Microprocessor Lab


Output:

Before:

After:

CSL404: Microprocessor Lab


Multiplication Program:

assume cs:code, ds:data


data segment
a dw 0102h
b dw 0001h
c dd ?
data ends

code segment
start:
mov ax, data
mov ds, ax
mov ax, a
mov bx, b
mul bx
mov word ptr c, ax
int 03
code ends
end start

CSL404: Microprocessor Lab


Output:

Before:

After:

CSL404: Microprocessor Lab


Division Program:

assume cs:code, ds:data


data segment
a dw 1001h
b dw 0100h
c dw ?
data ends

code segment
start:
mov ax, data
mov ds, ax
mov ax, a
mov bx, b
div bx
mov c, dx
int 03
code ends
end start

CSL404: Microprocessor Lab


Output:

Before:

After:

CSL404: Microprocessor Lab


Conclusion:

The experiment effectively demonstrated basic 16-bit arithmetic operations using assembly
language. By utilizing registers such as AX and BX, we performed addition, subtraction,
multiplication, and division on two 16-bit numbers stored in the data segment. The ADD and
SUB instructions provided direct operations on the registers, while MUL and DIV facilitated
multiplication and division with results stored across the DX-AX register pair, ensuring
correct handling of larger results. This experiment emphasized the importance of using
specific instructions for different operations, enabling efficient arithmetic calculations and
data manipulation in assembly programming for 16-bit data.

Questions:

1. Why is it necessary to initialize the data segment before performing operations in an


assembly language program?
Ans: It ensures correct access to operands and data in memory, as the program operates in a
segmented memory model.

2. How does performing arithmetic operations on 16-bit numbers differ from operations on
8-bit numbers in assembly language?
Ans: 16-bit operations involve larger registers (AX, BX, DX) and may use DX:AX pairs for
multiplication and division to handle overflow.

3. Describe the purpose of using registers like AX, DX, and BX while working with 16-bit
numbers in assembly language.
Ans: AX: Primary accumulator for arithmetic operations. DX: Extended register for high-order
bits during multiplication/division.

4. Explain how the result of a 16-bit multiplication is stored in the DX:AX pair. Why is this
necessary?
Ans: Clear DX before performing division to avoid overflow errors. Ensure the divisor is non-
zero to prevent exceptions.

CSL404: Microprocessor Lab

You might also like