8086 Programming
8086 Programming
8086 Programming
8086 Programming
By:
Mitul Patel
8086 Programming
• Assembly language programming for the 8086 microprocessor
involves writing low-level instructions that directly interact with
the hardware.
• The 8086 microprocessor has a 16-bit architecture, and its
assembly language uses mnemonics to represent the low-level
instructions.
Basic Structure of an 8086 Assembly Program
• A typical assembly program consists of several sections, which
include:
• Data segment: Defines variables and constants.
• Code segment: Contains the actual code (instructions).
• Stack segment: Used for subroutine calls and local storage.
Program Skeleton
Basic Program
Structure
Registers in 8086
• 8086 has several registers, grouped as:
• General Purpose Registers:
• AX, BX, CX, DX – Can be used for arithmetic, data movement, etc.
• They can be split into two 8-bit registers (AH/AL, BH/BL, CH/CL, DH/DL).
• Segment Registers:
• CS (Code Segment),
• DS (Data Segment),
• SS (Stack Segment),
• ES (Extra Segment) – These hold the segment addresses for different
memory areas.
Registers in 8086
• Pointer and Index Registers:
• SP (Stack Pointer),
• BP (Base Pointer),
• SI (Source Index),
• DI (Destination Index) – Used for addressing and manipulating data in
memory.
• Flag Register:
• Holds the current state of the processor (carry, zero, overflow, etc.).
Basic Instructions:
• Some common instructions include:
1. Data Transfer Instructions:
• MOV – Move data between registers or memory.
• PUSH / POP – Push and pop data to/from the stack.
2. Arithmetic Instructions:
• ADD, SUB, MUL, DIV – Perform addition, subtraction,
multiplication, and division.
• INC, DEC – Increment and decrement a value.
Basic Instructions:
3. Logical Instructions:
• AND, OR, XOR, NOT – Logical operations on bits.
• SHL, SHR – Shift bits left or right.
4. Control Transfer Instructions:
• JMP – Unconditional jump to a specified label.
• JE, JNE, JG, JL – Conditional jumps based on flags (e.g., if equal,
not equal, greater than, less than).
5. Interrupt Instructions:
• INT – Generate an interrupt (e.g., INT 21h for DOS system
calls).
Assembler Directives
end label end of program, label is entry point
proc far|near begin a procedure; far, near keywords
specify if procedure in different code segment (far), or same code
segment (near)
endp end of procedure
page set a page format for the listing file
title title of the listing file
.code mark start of code segment
.data mark start of data segment
.stack set size of stack segment
Assembler Directives
db define byte
dw define word (2 bytes)
dd define double word (4 bytes)
dq define quadword (8 bytes)
dt define tenbytes
equ equate, assign numeric expression to a name
Examples
db 100 dup (?) define 100 bytes, with no initial values for bytes
db “Hello” define 5 bytes, ASCII equivalent of “Hello”.
maxint equ 32767
count equ 10 * 20 ; calculate a value (200)
Example: Addition
of
Two Numbers
Common Interrupts:
• INT 21h: This DOS interrupt is used for various I/O operations
such as printing strings or reading input from the keyboard.
• AH = 09h: Display a string (terminated by $).
• AH = 01h: Read a single character from keyboard input.
Looping and Conditional Statements:
• To implement loops and conditional branches in 8086 assembly,
you can use conditional jump instructions like JE, JNE, and loops
using LOOP.
Subroutines (Procedures):
• 8086 assembly programs can have subroutines (or procedures).
Use CALL to invoke a subroutine and RET to return from it.
8086 Instruction Set Summary(Data Transfer)
8086 Instruction Set
Summary(Arithmetic/Logical)
8086 Instruction Set
Summary(Arithmetic/Logical)
8086 Instruction Set
Summary(Control/Branch)
8086 Instruction Set
Summary(Control/Branch)
How to run 8086 program?
Option 1: Use TASM/MASM Simulator
Step 1: Writing the Program in any text editor(notepad, sublime text). Save the
file with the extension .asm.
Step 2: Assembling the Program
TASM myfile.asm/MASM myfile.asm
Step 3: Linking the Object File
TLINK myfile.obj/LINK myfile.obj
Step 4: Running the Program
Option 1: Using DOSBox (Emulator)
Option 2: Using EMU8086 (8086 Emulator)
Option 3: Using Real DOS Environment (if available)
8086 Program to Multiply Two 16-bit Numbers
8086 program to perform conversion from BCD to Binary
8086 Assembly Program to Count Positive and Negative
Numbers from array
8086 Program to Multiply Two 8-Bit Hexadecimal
Numbers Using Successive Addition
8086 Program to Multiply Two 8-Bit Hexadecimal
Numbers Using Add and Shift Method
8086 program to find cube of a number
8086 program to find a factorial of a number
using recursive method
8086 program to check given string is palindrome or not
8086 assembly program
that sorts a given set of
16-bit unsigned integers
into ascending order
using the Bubble Sort
algorithm