MPL EXP2
MPL EXP2
2
ALP to add, subtracts, multiply and divides two 16-bit numbers
Date of Performance: 16/01/2025
Date of Submission: 30/01/2025
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:
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
Before:
After:
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
Before:
After:
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
Before:
After:
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
Before:
After:
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:
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.