✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
Microprocessor 8086
Powered by Ur Engineering Friend
Welcome to a world of learning and growth!
Ur Engineering Friend is your trusted companion on your academic
journey. We provide high-quality notes, assignments, question banks,
and engaging guest lectures to help you excel in your studies. Let's learn,
grow, and succeed together!
"Discipline is choosing between what you want now and what you want
most"
Unit 2 -: Art of Assembly
Language Programming
✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
Youtube Channel -: Ur Engineering Friend
Syllabus Topic -:
1. Basics of Machine level, Assembly level & High-level
2. Steps involved in programming
3. Algorithms & Flowcharts
4. Text editor, Assembler, Linker & Debugger
5. Basic debug commands
6. Assembler directives
Why These Notes?
Most books on Assembly Language Programming jump straight into syntax, instructions,
and programming techniques without providing a solid foundation. They assume that
students already understand the underlying concepts, such as:
What exactly is an assembly language?
How does it differ from high-level programming languages?
Why do we even need assembly language when we have C, Python, and Java?
How do microprocessors execute instructions at a low level?
Without answering these fundamental questions, learning assembly language becomes
confusing and overwhelming. Many students struggle not because Assembly Language is
inherently difficult, but because they lack the necessary background knowledge.
How This Guide is Different
In these notes, we will first build a strong foundation by covering:
✅ How computers understand instructions (Machine Code vs. Assembly Language)
✅ The role of microprocessors in executing programs
Youtube Channel -: Ur Engineering Friend
✅ Basic concepts like registers, memory addressing, and instruction sets
✅ How high-level code gets translated into low-level assembly instructions
Only after understanding these core concepts will we move into Assembly Language
Programming. This structured approach ensures that you learn Assembly logically, step
by step, rather than memorizing syntax without truly understanding how it works.
Understanding the Basics Before Assembly Programming
Computers do not understand human languages; they only process binary code (0s and
1s). Every program, whether written in C, Python, or Java, ultimately gets converted into
machine code before execution.
However, writing direct machine code is highly impractical because:
It consists of long sequences of binary numbers (e.g., 10110000 01100001).
It is difficult to read, write, and debug.
To bridge this gap, Assembly Language was created. It is a low-level programming
language that uses mnemonics (short human-readable commands) instead of raw
binary, making it easier to write machine-level instructions.
Example: Instead of writing 10110000 01100001 (binary), we write MOV AL,
61H (assembly).
The Assembler converts this human-readable assembly code into machine code.
Youtube Channel -: Ur Engineering Friend
Key Takeaway: Assembly language is a readable form of machine code that allows
direct communication with the CPU.
A microprocessor is the brain of a computer. It executes all the instructions in a program,
including mathematical operations, data movement, and logic control.
Microprocessors work in three main steps, known as the Fetch-Decode-Execute Cycle:
1. Fetch – The processor retrieves an instruction from memory.
2. Decode – The instruction is decoded to understand what action to perform.
3. Execute – The processor performs the operation (e.g., addition, data transfer).
Every instruction in assembly language is directly mapped to a microprocessor operation.
By learning assembly, you gain a deep understanding of how a microprocessor processes
and manipulates data internally.
Key Takeaway: Assembly programming allows us to directly control how the
microprocessor executes instructions.
Before programming in assembly, it's essential to understand three key components of the
microprocessor:
Registers
Small storage units inside the CPU used to hold temporary data.
Different types include General Purpose Registers (AX, BX, CX, DX) and
Special Registers (IP, SP, BP, etc.).
Youtube Channel -: Ur Engineering Friend
Example: MOV AX, 5 stores the value 5 in register AX.
Memory Addressing
The CPU interacts with RAM (Random Access Memory) to store and retrieve
data.
Every memory location has a unique address.
Assembly uses different addressing modes (Immediate, Direct, Indirect, Indexed)
to access memory efficiently.
Instruction Set
A collection of predefined operations that the CPU can perform.
Example Instructions:
o MOV → Transfer data
o ADD → Perform addition
o JMP → Jump to another instruction
Key Takeaway: Registers, memory addressing, and instruction sets are fundamental to
writing effective assembly programs.
When we write programs in high-level languages (like C or Python), they go through
multiple stages before execution:
1. Compilation – Converts high-level code into assembly code.
2. Assembly – Translates assembly code into machine code (binary).
3. Execution – The microprocessor runs the machine code instructions.
Youtube Channel -: Ur Engineering Friend
Machine-Level Language (Binary Code)
The lowest-level language, directly understood by the CPU.
Consists entirely of binary digits (0s and 1s).
Each instruction is represented as a unique sequence of bits.
Example:
A simple instruction in machine code (for an Intel processor) might look like this:
This means "Move the value 61H into register AL" (but written in binary).
Advantages:
✔ Direct execution by the processor (fastest execution).
✔ No need for a compiler or assembler.
Disadvantages:
✘ Extremely difficult to read, write, and debug.
✘ A small mistake can make the entire program fail.
✘ Not portable (specific to each processor architecture).
Youtube Channel -: Ur Engineering Friend
High-Level Language (HLL)
Uses human-friendly syntax (like English-like statements).
Independent of the underlying hardware (portable across different CPUs).
Requires a compiler or interpreter to convert into machine code.
Example (C Language Equivalent):
Much easier to understand than machine or assembly language.
Advantages:
✔ Easy to read, write, and debug.
✔ Portable across different systems.
✔ Reduces programming effort and complexity.
Disadvantages:
✘ Requires a compiler/interpreter.
✘ Slower than assembly/machine code (because of translation overhead).
✘ Less control over hardware compared to assembly.
Assembly-Level Language (Low-Level Language)
Uses mnemonics (human-readable short codes) instead of pure binary.
Still closely tied to the processor’s architecture.
Requires an Assembler to convert assembly code into machine code.
Example:
Equivalent assembly instruction for the previous machine code example:
Youtube Channel -: Ur Engineering Friend
MOV AL, 61H
MOV → Mnemonic for "Move" instruction.
AL → Register where data is stored.
61H → Value being stored.
Advantages:
✔ Easier to write than machine code.
✔ More efficient than high-level languages.
✔ Allows direct hardware control.
Disadvantages:
✘ Still complex and requires knowledge of hardware.
✘ Not portable (specific to CPU architecture).
✘ Needs an assembler to convert code into machine language.
Assembler Instruction Format
An assembly language instruction consists of different fields that specify the operation
to be performed and the operands involved. The general format of an assembly
instruction is:
Youtube Channel -: Ur Engineering Friend
Steps involved in Programming
Writing an assembly language program requires several systematic steps, from writing
the code to executing it on the microprocessor. The key steps are as follows:
Understand the Problem Statement
Clearly define the objective of the program.
Identify input and output requirements.
Determine the logic and algorithm needed to achieve the desired result.
Choose the Appropriate Microprocessor and Assembler
Decide the target processor (e.g., 8086, 8051, ARM, x86).
Select an assembler such as:
o MASM (Microsoft Macro Assembler)
o TASM (Turbo Assembler)
o NASM (Netwide Assembler)
Write the Assembly Language Program (ALP)
Use mnemonics and appropriate syntax.
Include labels, comments, and proper indentation for readability.
Use registers and memory efficiently.
Example ALP:
MOV AX, 2000H ; Load memory address 2000H into AX
Youtube Channel -: Ur Engineering Friend
ADD AX, BX ; Add BX to AX
MOV [3000H], AX; Store result at memory address 3000H
HLT ; Halt the program
Assemble the Program
Use an assembler to convert the assembly code into machine code.
This process generates the following files:
o Source file (.ASM) → The original assembly program.
o Object file (.OBJ) → The intermediate compiled code.
o Executable file (.EXE or .COM) → The final machine-executable file.
Example (Using MASM in DOS)
MASM program.asm ; Assembles the code
LINK program.obj ; Links the object file to create an executable
Load and Execute the Program
Use a simulator or run the program directly on compatible hardware.
If using an emulator (e.g., EMU8086, DOSBox), load the assembled program and
execute it.
Debugging and Testing
Check for syntax errors during the assembly process.
Use debugging tools like TD (Turbo Debugger) or EMU8086 Debugger to step
through instructions.
Correct any logical errors and reassemble the program.
Youtube Channel -: Ur Engineering Friend
An algorithm is a step-by-step procedure or set of instructions designed to solve a
specific problem. It defines a logical sequence of actions to be performed.
Characteristics of an Algorithm
✅ Well-Defined → Every step must be clear and precise.
✅ Finite → It must end after a limited number of steps.
✅ Effective → Each step should be simple and easy to execute.
✅ Input & Output → Takes input and produces a defined output.
✅ Independent → It should be independent of any programming language.
Example Algorithm: Adding Two Numbers
Problem: Write an algorithm to add two numbers.
Step 1: Start
Step 2: Input two numbers (A and B)
Step 3: Add A and B → SUM = A + B
Step 4: Display SUM
Step 5: Stop
Note: This algorithm works for any two numbers, making it generalized and reusable.
Youtube Channel -: Ur Engineering Friend
A flowchart is a graphical representation of an algorithm using symbols. It visually
represents the sequence of steps involved in solving a problem.
Basic Flowchart Symbols
Youtube Channel -: Ur Engineering Friend
Text Editor
A text editor is used to write and modify the assembly language source code. It saves
the program in a text file with the extension .ASM.
Common Text Editors for Assembly Language
Notepad++ – Simple and lightweight.
Visual Studio Code (VS Code) – Advanced features with extensions.
Turbo C Editor – Used in DOS-based environments.
EMU8086 Editor – Built-in editor for 8086 programs.
Example: Writing an Assembly program in Notepad and saving it as program.asm.
Assembler
An assembler translates assembly language code (.ASM) into machine code (binary
or hexadecimal format) that the microprocessor can understand.
Functions of an Assembler
✅ Converts mnemonics into opcode.
✅ Allocates memory addresses for instructions and data.
✅ Checks syntax errors.
✅ Generates an object file (.OBJ).
Common Assemblers
MASM (Microsoft Macro Assembler)
TASM (Turbo Assembler)
Youtube Channel -: Ur Engineering Friend
NASM (Netwide Assembler)
GNU Assembler (GAS)
Example: Assembling a file in MASM
MASM program.asm ; Assembles the code
Linker
A linker combines multiple object files (.OBJ) and creates a final executable file (.EXE
or .COM).
Functions of a Linker
✅ Combines different modules (if multiple .OBJ files exist).
✅ Resolves addresses for function calls.
✅ Links required libraries.
✅ Generates the final executable (.EXE or .COM).
Common Linkers
LINK.EXE (for MASM/TASM)
LD (GNU Linker)
TASM Linker
Example: Linking an object file in MASM
LINK program.obj ; Links the object file and creates an EXE
Debugger
A debugger is used to execute and test the program step-by-step to find and fix errors.
Functions of a Debugger
Youtube Channel -: Ur Engineering Friend
✅ Runs the program line by line (single stepping).
✅ Displays register values and memory contents.
✅ Allows setting breakpoints to pause execution.
✅ Identifies errors (logical, runtime, or syntax).
Common Debuggers
Turbo Debugger (TD)
DEBUG.EXE (for DOS)
EMU8086 Debugger
gdb (GNU Debugger)
Example: Running DEBUG.EXE in DOS
DEBUG program.exe ; Starts the debugger
The DEBUG tool in DOS (DEBUG.EXE) and other debuggers like Turbo Debugger
(TD) or EMU8086 Debugger help in testing and debugging assembly programs.
Debugging allows you to inspect registers, memory, and execute instructions step-by-
step. Below are the commonly used DEBUG commands in assembly language.
Youtube Channel -: Ur Engineering Friend
D (Dump Memory)
Syntax:
D [segment:offset]
Purpose:
Displays the contents of a specific memory location.
Shows data in hexadecimal and ASCII format.
Example:
D 1000:0000 ; Displays memory contents from address 1000:0000
E (Edit Memory Content)
Syntax:
E [segment:offset]
Purpose:
Modifies values stored in memory.
User can enter new values interactively.
Example:
E 1000:0000 ; Edit memory at address 1000:0000
Output:
arduino
Youtube Channel -: Ur Engineering Friend
1000:0000 00. _ (Type new value and press Enter)
R (Display/Modify Registers)
Syntax:
R [register_name]
Purpose:
Displays the values of registers (AX, BX, CX, DX, etc.).
Allows modifying a specific register.
Example:
R AX ; Shows current value of AX
Output:
AX 0000
After pressing Enter, you can modify the register value.
T (Trace Execution Step-by-Step)
Syntax:
Purpose:
Executes one instruction at a time.
Useful for analyzing how registers and memory change step by step.
Youtube Channel -: Ur Engineering Friend
Example:
T ; Executes the next instruction
Each press of T executes the next assembly instruction.
P (Proceed Execution)
Syntax:
Purpose:
Similar to T, but skips over subroutines instead of stepping into them.
Example:
P ; Executes next instruction, skipping subroutine calls
U (Unassemble Machine Code to Assembly)
Syntax:
U [address]
Purpose:
Converts machine code (hexadecimal) into assembly language instructions.
Useful for analyzing executable files (.EXE, .COM).
Example:
U 1000:0000 ; Disassemble memory at 1000:0000
Youtube Channel -: Ur Engineering Friend
Output:
1000:0000 MOV AX, BX1000:0002 ADD AX, 05
G (Go – Run the Program)
Syntax:
G [address]
Purpose:
Runs the program from a specified address.
Stops execution when encountering a breakpoint.
Example:
G 1000:0000 ; Runs the program from address 1000:0000
N (Name a File for Debugging)
Syntax:
N filename
Purpose:
Loads a file into memory for debugging.
Example:
N myprogram.com
Youtube Channel -: Ur Engineering Friend
L (Load a File into Memory)
Syntax:
Purpose:
Loads a program from disk into memory.
Used after N (Name) command.
Example:
L ; Loads myprogram.com into memory
W (Write to File – Save Changes to Disk)
Syntax:
Purpose:
Saves modified memory back to the file.
Example:
W ; Writes changes to myprogram.com
Q (Quit Debugger) ❌
Syntax:
Youtube Channel -: Ur Engineering Friend
Purpose:
Exits the DEBUG program.
Example:
Q ; Exits DEBUG
Assembler directives are special instructions that guide the assembler on how to process
a program. Unlike normal instructions, directives do not generate machine code;
instead, they provide information to the assembler, such as memory allocation, segment
definitions, and control flow.
Youtube Channel -: Ur Engineering Friend
1. Memory Definition Directives
2. Segment Definition Directives
3. Data Allocation Directives
4. Code Control Directives
5. Macro and Procedure Directives
Youtube Channel -: Ur Engineering Friend
Youtube Channel -: Ur Engineering Friend
End of Unit 2
For Assignment , Question Bank and Previously Asked Questions Stay
tuned with our Whatsapp Group and Youtube Channel
Whatsapp group -
https://chat.whatsapp.com/IeJKgWugSBaIkFyouSGsnc
Youtube Channel -
https://www.youtube.com/@UrEngineeringFriend
Excited for Unit 3 Notes ?
---------------------------------------------------------------------------
Youtube Channel -: Ur Engineering Friend