INTRODUCTION:
In the domain of low-level programming and system
architecture, the Assembly Language Program (ALP)
serves as a vital tool for interacting directly with
hardware components. Assembly language is known for
its close proximity to machine code, offering precise
control over processor operations. One of the
foundational tasks in any computing system is performing
arithmetic operations like addition and subtraction.
This practical focuses on the 8086 microprocessor, which
is one of the most widely studied processors in
microprocessor programming courses. It involves writing
an assembly language program to add and subtract two
numbers. These operations, though simple in high-level
languages, require a deeper understanding of registers,
data movement, and the execution flow in assembly.
Through this exercise, students not only grasp the syntax
and structure of ALP but also learn how arithmetic logic is
handled at the hardware level. The program also
demonstrates how to load values into registers, perform
operations using ADD and SUB instructions, and store
results in memory. Such foundational knowledge is
essential for anyone aiming to work with embedded
systems, firmware, or system-level software.
ADDITION:
Assembly Language is a low-level programming language that's
closely related to machine code. It's specific to each processor
architecture (like x86, ARM, etc.). Performing addition in assembly
involves working directly with registers and memory, using
instructions like ADD and ADC (Add with Carry).
[Link] two 8 bit nos
[Link] two 16 bit nos
ALGORITHM:
1. Start the program.
2. Initialize the data segment.
3. Load the first 8-bit number into register AL.
4. Add the second 8-bit number to AL using the ADD
instruction.
5. Store the result in a memory location.
6. Terminate the program.
PROGRAM:
Addition of two 8 bit numbers:
.MODEL SMALL
.DATA
NUM1 DB 25H ; First 8-bit number (37 in decimal)
NUM2 DB 15H ; Second 8-bit number (21 in
decimal)
RESULT DB ? ; To store result
.CODE
START:
MOV AX, @DATA ; Initialize DS
MOV DS, AX
MOV AL, NUM1 ; Load NUM1 into AL
ADD AL, NUM2 ; Add NUM2 to AL
MOV RESULT, AL ; Store result in RESULT
ENDS
END
Program Output (in memory):
Given:
NUM1 = 25H (37 decimal)
NUM2 = 15H (21 decimal)
Result:
RESULT = 3AH (58 decimal)
This output is stored in memory location RESULT.
Addition of two 16 bit no’s:
Algorithm:
1. Start the program.
2. Initialize the data segment.
3. Load the first 16-bit number into register pair
AX.
4. Load the second 16-bit number into register
pair BX.
5. Add the contents of BX to AX using the ADD
instruction.
6. Store the result in a memory location.
7. Terminate the program.
PROGRAM:
.MODEL SMALL
.DATA NUM1 DW 1234H ; First 16-bit number
NUM2 DW 0A56H ; Second 16-bit number
RESULT DW ? ; To store result
.CODE
START:
MOV AX, @DATA ; Initialize data segment
MOV DS, AX
MOV AX, NUM1 ; Load first number into AX
ADD AX, NUM2 ; Add second number to AX
MOV RESULT, AX ; Store result
ENDS
END
Program Output (in memory):
Given:
NUM1 = 1234H (4660 decimal)
NUM2 = 0A56H (2646 decimal)
Result:
RESULT = 1C8AH (7306 decimal)
SUBSTRACTION:
Just like addition, subtraction is one of the most fundamental
arithmetic operations in Assembly Language. It allows a
programmer to compute differences between values stored in
registers or memory locations. Subtraction is essential in tasks
like calculating offsets, implementing loops, adjusting counters,
and performing mathematical operations.
Assembly provides specific instructions to perform subtraction,
the most common being SUB and SBB (Subtract with Borrow).
1. Substraction two 8 bit no’s
2. Substraction two 16 bit no’s
Substraction two 8 bit no’s
Algorithm:
1. Start the program.
2. Initialize the data segment.
3. Load the first 8-bit number into AL.
4. Subtract the second 8-bit number using SUB
instruction.
5. Store the result in a memory location.
6. Terminate the program.
PROGRAM:
.MODEL SMALL
.DATA NUM1 DB 45H ; First number (69)
NUM2 DB 25H ; Second number (37)
RESULT DB ? ; To store result
.CODE START:
MOV AX, @DATA
MOV DS, AX
MOV AL, NUM1 ; Load first number
SUB AL, NUM2 ; Subtract second number
MOV RESULT, AL ; Store result
ENDS
END
OUTPUT
NUM1 = 45H (69)
NUM2 = 25H (37)
RESULT = 20H (32)
Substraction two 16 bit no’s
Algorithm:
[Link] the program.
[Link] data segment.
[Link] first 16-bit number into AX.
[Link] second 16-bit number into BX.
[Link] BX from AX using SUB.
[Link] result in memory.
[Link] the program.
PROGRAM:
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW 4567H ; First number (17767)
NUM2 DW 1234H ; Second number (4660)
RESULT DW ? ; To store result
.CODE
START:
MOV AX, @DATA
MOV DS, AX
MOV AX, NUM1 ; Load first 16-bit number
SUB AX, NUM2 ; Subtract second 16-bit number
MOV RESULT, AX ; Store result
ENDS
END
Output:
NUM1 = 4567H (17767)
NUM2 = 1234H (4660)
RESULT = 3333H (13107)
Conclusion:
In this project, we successfully implemented
basic arithmetic operations—addition and
subtraction—on 8-bit and 16-bit numbers
using Assembly Language Programming
(ALP) for the 8086 microprocessor. The
exercises demonstrated how to initialize the
data segment, load data into registers,
perform operations using ADD and SUB
instructions, and store the results in
memory.
Through this practical, we gained hands-on
experience in low-level programming and
learned how arithmetic operations are
executed at the hardware level. It enhanced
our understanding of data movement,
register usage, and instruction flow in
assembly language. This foundational
knowledge is essential for further studies in
embedded systems, firmware development,
and system-level programming.
References:
1. “Microprocessor Architecture,
Programming and Applications with the
8085” by Ramesh S. Gaonkar – for
understanding microprocessor
fundamentals and instruction sets.
2. Intel 8086 Microprocessor Datasheet –
for opcode details, register structure, and
hardware specifications.
3. Lab Manuals and Lecture Notes –
provided by [Your Institute/Instructor
Name] for practical guidance and
algorithm design
4. Online Resources:
[Link]/
assembly_programming
[Link]/microprocessor-
tutorials
[Link] – for sample
codes and concepts related to 8086 ALP.