0% found this document useful (0 votes)
7 views41 pages

Course Assembly Language Programming

The document outlines a comprehensive course on Assembly Language Programming at Heritage University, covering various lessons over 60 hours. Key topics include the introduction to assembly language, number and character representations, signed and unsigned numbers, instruction types, data transfer instructions, and debugging techniques. Each lesson includes learning objectives, content summaries, key terms, and exercises for self-assessment.

Uploaded by

paguemic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views41 pages

Course Assembly Language Programming

The document outlines a comprehensive course on Assembly Language Programming at Heritage University, covering various lessons over 60 hours. Key topics include the introduction to assembly language, number and character representations, signed and unsigned numbers, instruction types, data transfer instructions, and debugging techniques. Each lesson includes learning objectives, content summaries, key terms, and exercises for self-assessment.

Uploaded by

paguemic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assembly Language Programming –

Institution: Heritage University​


Level: 2​
Course Duration: 60 hours

Lesson 1: Introduction to Assembly Language +


Instruction Format
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Define assembly language and its role in programming.​

2.​ Understand the difference between high-level, low-level, and machine languages.​

3.​ Identify the basic structure of an assembly instruction.​

Lesson Content

1. Introduction to Assembly Language

●​ Assembly language is a low-level programming language that is closely related


to machine code.​

●​ Each assembly instruction corresponds to a single machine instruction.​

●​ It allows direct control over hardware, making it essential for system programming
and embedded applications.​

2. Comparison of Programming Languages

Language Abstraction Example Notes


Type Level

Machine Low 10110000 Binary instructions executed by


Code 01100001 CPU
Assembly Low MOV AL, 61H Mnemonics make machine code
readable

High-Level High C, Python Easy to write, portable, less


hardware control

3. Instruction Format

●​ Assembly instructions typically have the following components:​

[Label] Mnemonic Operand1, Operand2 ; Comment

●​ Label: Optional, used for jumps and loops​

●​ Mnemonic: Operation code (e.g., MOV, ADD, SUB)​

●​ Operand(s): Registers, memory addresses, or constants​

●​ Comment: Optional explanation​

Example:

START: MOV AX, 5 ; Load 5 into register AX


ADD AX, 2 ; Add 2 to AX

4. Program Structure

●​ Data Segment: Define variables and constants​

●​ Code Segment: Write instructions​

●​ Stack Segment: Manage temporary storage and subroutine calls​

Summary

●​ Assembly language bridges high-level languages and machine code.​

●​ Each instruction has a mnemonic and operands.​

●​ Understanding instruction format is critical for writing assembly programs.​


Key Terms

●​ Assembly Language, Mnemonic, Operand, Label, Data Segment, Code Segment​

Exercises / Self-Assessment

1.​ Explain the difference between machine code and assembly language.​

2.​ Identify the label, mnemonic, and operands in the instruction: LOOP: ADD BX, 10.​

3.​ Write a simple assembly program to move 7 into AX and add 3.​

Lesson 2: Number & Character Representations


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Represent numbers in binary, decimal, octal, and hexadecimal systems.​

2.​ Understand ASCII codes for characters.​

3.​ Convert between different number systems.​

Lesson Content

1. Number Systems

System Bas Symbol Example of 10


e s decimal

Binary 2 0,1 1010

Decimal 10 0–9 10

Octal 8 0–7 12

Hexadecimal 16 0–9, A–F A


2. Conversion Examples

●​ Decimal to Binary: 13 → 1101​

●​ Binary to Decimal: 1011 → 11​

●​ Decimal to Hexadecimal: 255 → FF​

3. Character Representation – ASCII Codes

●​ ASCII (American Standard Code for Information Interchange): 7 or 8-bit code for
characters.​

●​ Examples:​

○​ A → 65 (Decimal) → 41H (Hex)​

○​ a → 97 (Decimal) → 61H (Hex)​

○​ 0 → 48 (Decimal) → 30H (Hex)​

4. Practical Use in Assembly

●​ ASCII codes are used to display characters on screens and manage keyboard input.​

●​ Example in assembly:​

MOV AL, 'A' ; Load ASCII of A into AL


MOV DL, AL
MOV AH, 02H ; DOS function to display character
INT 21H

Summary

●​ Numbers can be represented in multiple bases; conversions are critical in assembly.​

●​ ASCII provides standard codes for characters.​

●​ Understanding representations allows correct data handling in programs.​


Key Terms

●​ Binary, Decimal, Octal, Hexadecimal, ASCII, Character Code​

Exercises / Self-Assessment

1.​ Convert decimal 25 to binary, octal, and hexadecimal.​

2.​ Find ASCII codes for characters 'C', 'z', and '5'.​

3.​ Write assembly code to display the character 'B' using DOS interrupt.​

Lesson 3: Signed & Unsigned Representations, ASCII


Codes
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand signed and unsigned numbers.​

2.​ Represent signed numbers using Two’s complement.​

3.​ Use ASCII codes in practical assembly programs.​

Lesson Content

1. Unsigned Numbers

●​ Can only represent non-negative integers.​

●​ Range for n-bit number: 0 to 2ⁿ – 1​

●​ Example: 8-bit → 0 to 255​

2. Signed Numbers

●​ Can represent positive and negative numbers.​


●​ Two’s complement representation is used in assembly:​

○​ Positive: same as unsigned​

○​ Negative: invert all bits and add 1​

Example: Represent -5 in 8-bit

●​ Step 1: 5 → 00000101​

●​ Step 2: Invert → 11111010​

●​ Step 3: Add 1 → 11111011​

3. Range of 8-bit Signed Numbers

●​ -128 to +127​

4. ASCII Codes Review

●​ Already introduced in Lesson 2​

●​ ASCII codes can be combined with arithmetic to manipulate characters.​

●​ Example: Convert lowercase to uppercase:​

MOV AL, 'a' ; AL = 97


SUB AL, 20H ; AL = 65 ('A')

Summary

●​ Signed numbers allow representation of negative values using Two’s complement.​

●​ Unsigned numbers are always non-negative.​

●​ ASCII codes enable character manipulation in assembly programs.​

Key Terms
●​ Signed Number, Unsigned Number, Two’s Complement, ASCII​

Exercises / Self-Assessment

1.​ Represent -12 in 8-bit Two’s complement.​

2.​ Convert 11010110 (8-bit) to signed decimal.​

3.​ Write assembly code to convert 'd' to 'D' using ASCII arithmetic.​

Lesson 4: Instruction Types + 8086 Register Set


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Identify different types of assembly instructions.​

2.​ Understand the purpose of the 8086 register set.​

3.​ Use registers effectively in assembly programs.​

Lesson Content

1. Types of Assembly Instructions

Instruction Type Description Example

Data Transfer Moves data between MOV AX, BX


registers/memory

Arithmetic Performs arithmetic operations ADD AX, 5

Logical/Boolean Performs bitwise operations AND AL, 0Fh

Control Transfer Jumps, loops, calls JMP START

String Operations Manipulates string data MOVS, CMPS

Input/Output Communicates with hardware IN AL, 60H

Flag Control Sets or clears flags CLC, STC

2. 8086 Register Set

Register Type Names Purpose

General Purpose AX, BX, CX, DX Arithmetic, data, counters

Segment Registers CS, DS, ES, SS Points to code, data, extra, stack segments

Pointer/Index SP, BP, SI, DI Stack pointer, base pointer, source, destination
Registers indexes

Instruction Pointer IP Holds address of next instruction

Flags Register FLAGS Indicates status of arithmetic/logic operations

3. Notes:
●​ AX often used for arithmetic operations.​

●​ BX can serve as a base for memory addressing.​

●​ CX commonly used as loop counter.​

Summary

●​ 8086 has multiple registers for arithmetic, addressing, and control.​

●​ Instruction types define the operation performed on data or control flow.​

Key Terms

●​ Register, Segment Register, Instruction Pointer, Flags, Data Transfer, Arithmetic


Instruction​

Exercises / Self-Assessment

1.​ List three types of assembly instructions with examples.​

2.​ What is the role of the CX register?​

3.​ Identify the purpose of DS and SS registers in 8086.​

Lesson 5: Data Transfer Instructions – MOV, ADD, SUB


+ Data Definition
Learning Objectives:​
By the end of this lesson, students should be able to:
1.​ Use MOV, ADD, and SUB instructions effectively.​

2.​ Define data in memory using assembly directives.​

Lesson Content

1. MOV Instruction

●​ Syntax: MOV destination, source​

●​ Moves data from source to destination.​

●​ Examples:​

MOV AX, 5 ; Load 5 into AX


MOV BX, AX ; Copy AX to BX
MOV AL, 'A' ; Load ASCII of A into AL

2. ADD Instruction

●​ Adds source operand to destination and stores result in destination.​

ADD AX, BX ; AX = AX + BX
ADD AL, 1 ; Increment AL

3. SUB Instruction

●​ Subtracts source operand from destination and stores result in destination.​

SUB AX, 2 ; AX = AX – 2
SUB BL, AL ; BL = BL – AL

4. Data Definition Directives

●​ DB: Define Byte​

●​ DW: Define Word (2 bytes)​


●​ DD: Define Double Word (4 bytes)​

MYBYTE DB 5
MYWORD DW 1234H
MYARRAY DB 'HELLO'

Summary

●​ MOV, ADD, and SUB are basic instructions for data movement and arithmetic.​

●​ Data must be properly defined in memory for assembly programs.​

Key Terms

●​ MOV, ADD, SUB, Data Definition, DB, DW, DD​

Exercises / Self-Assessment

1.​ Write instructions to load 10 into AX and subtract 3.​

2.​ Define a byte variable and a word variable in memory.​

3.​ Copy the value of AX into BX using MOV.​

Lesson 6: Flag Register + Overflow Detection


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand the structure of the FLAGS register.​

2.​ Identify the role of flags in arithmetic and logical operations.​

3.​ Detect and handle overflow conditions.​


Lesson Content

1. FLAGS Register Structure

●​ 16-bit register; important flags include:​

Flag Description

CF – Carry Flag Indicates carry/borrow in arithmetic

PF – Parity Flag 1 if number of 1s is even

AF – Auxiliary Carry Carry from lower nibble (used in BCD)

ZF – Zero Flag 1 if result is zero

SF – Sign Flag 1 if result is negative

OF – Overflow Flag 1 if signed overflow occurs

2. Overflow Detection

●​ Occurs when result exceeds range of destination operand.​

●​ Example: 8-bit signed addition: 127 + 1 → overflow​

MOV AL, 7FH


ADD AL, 1
; OF is set

3. Using Flags in Programs

●​ Conditional jumps depend on flags:​

JC CARRY_LABEL ; Jump if Carry Flag is set


JZ ZERO_LABEL ; Jump if Zero Flag is set
JO OVERFLOW_LABEL ; Jump if Overflow Flag is set

Summary
●​ FLAGS register stores status of arithmetic and logical operations.​

●​ Overflow detection prevents incorrect results in signed arithmetic.​

●​ Understanding flags is essential for conditional operations.​

Key Terms

●​ FLAGS Register, Carry Flag, Zero Flag, Sign Flag, Overflow Flag, Parity Flag​

Exercises / Self-Assessment

1.​ What happens to the Overflow Flag when adding 80 + 60 in 8-bit signed numbers?​

2.​ Write assembly code to check if a result is zero and jump to a label.​

3.​ Explain the role of the Sign Flag in conditional operations.​

Lesson 7: Addressing Modes


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand different addressing modes in assembly.​


2.​ Apply appropriate addressing modes in instructions.​

3.​ Use memory, immediate, and register operands effectively.​

Lesson Content

1. Addressing Modes in Assembly

Addressing Mode Description Example

Immediate Operand is constant value MOV AL, 5

Register Operand is a register MOV AX, BX

Direct Operand is memory address MOV AX, [1000H]

Indirect Operand is pointed by register MOV AX, [BX]

Base + Memory address = base + offset MOV AX, [BX+10H]


Displacement

Indexed Memory address = index register MOV AX, [SI]

Relative Offset relative to instruction pointer JMP LABEL

2. Notes

●​ Immediate mode: Fastest; value embedded in instruction.​

●​ Register mode: No memory access, efficient.​

●​ Direct/Indirect: Used to access data in memory.​

●​ Base+Displacement/Indexed: Allows arrays and structured data access.​

3. Example Program Using Addressing Modes

MOV AX, 1234H ; Immediate


MOV BX, AX ; Register
MOV CX, [2000H] ; Direct memory
MOV DX, [BX] ; Register indirect
MOV SI, 0050H
MOV AX, [SI+10H] ; Indexed with displacement
Summary

●​ Addressing modes define how operands are specified.​

●​ Proper use improves efficiency and flexibility in programs.​

Key Terms

●​ Immediate, Register, Direct, Indirect, Base, Indexed, Relative​

Exercises / Self-Assessment

1.​ Write an instruction to load 0xFF into AX using immediate addressing.​

2.​ Access a memory location at 3000H using direct addressing.​

3.​ Load the value at address [BX+5] into DX.​

Lesson 8: Debugger + Assembler


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand the role of assemblers and linkers.​


2.​ Use a debugger to run and trace assembly programs.​

3.​ Identify syntax and runtime errors.​

Lesson Content

1. Assembler

●​ Converts assembly code (mnemonics) into machine code.​

●​ Generates object files (.OBJ) and executable files (.EXE).​

●​ Examples: MASM, TASM, NASM.​

2. Debugger

●​ Tool to execute instructions step by step.​

●​ Allows monitoring of registers, flags, and memory.​

●​ Common features:​

○​ Breakpoints​

○​ Single-step execution​

○​ Examine memory/registers​

○​ Modify values​

3. Example Debugging Session

MOV AX, 5
ADD AX, 3
INT 3 ; Breakpoint

●​ Run program step by step​

●​ Check AX value after each instruction​

●​ Modify memory/register if needed​


4. Notes

●​ Syntax errors: Invalid mnemonics, operands, or labels​

●​ Runtime errors: Division by zero, overflow, stack errors​

●​ Debugging helps correct logic errors efficiently​

Summary

●​ Assembler converts human-readable code to machine code.​

●​ Debugger allows tracing and fixing program errors.​

●​ Using both is essential for successful assembly programming.​

Key Terms

●​ Assembler, Debugger, Breakpoint, Single-step Execution, Object File​

Exercises / Self-Assessment

1.​ Explain the difference between an assembler and a compiler.​

2.​ Write a simple program and describe how you would debug it.​

3.​ What are the common types of errors in assembly programs?​

Lesson 9: Data Transfer Instructions – MOV, XCHG,


LEA, Stack Operations
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Use advanced data transfer instructions.​


2.​ Exchange data between registers and memory.​

3.​ Load effective addresses into registers.​

Lesson Content

1. MOV Instruction (Review)

●​ Moves data from source to destination.​

2. XCHG Instruction

●​ Swaps contents of two operands.​

MOV AX, 5
MOV BX, 10
XCHG AX, BX ; AX=10, BX=5

3. LEA Instruction (Load Effective Address)

●​ Loads the address of a variable or memory location into a register.​

LEA BX, MYARRAY ; BX = address of MYARRAY

4. Stack Operations (Introduction)

●​ Stack: LIFO (Last In First Out) memory structure​

●​ Instructions: PUSH, POP​

Example:

MOV AX, 5
PUSH AX ; Save AX on stack
MOV AX, 0
POP AX ; Retrieve value from stack
Summary

●​ XCHG allows swapping values efficiently.​

●​ LEA loads addresses for pointer operations.​

●​ Stack operations are essential for subroutines and temporary storage.​

Key Terms

●​ XCHG, LEA, Stack, PUSH, POP, Effective Address​

Exercises / Self-Assessment

1.​ Swap AX and BX using XCHG.​

2.​ Load the address of a variable VAR1 into BX.​

3.​ Push AX onto the stack, change AX, then pop to restore original value.​

Lesson 10: Stack Operations


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand the concept of a stack in assembly programming.​


2.​ Perform PUSH and POP operations.​

3.​ Use the stack for subroutine calls and temporary data storage.​

Lesson Content

1. Stack Concept

●​ Stack is a Last In First Out (LIFO) memory structure.​

●​ Used for temporary storage of registers, return addresses, and parameters.​

2. Stack Registers

●​ SP (Stack Pointer): Points to the top of the stack​

●​ SS (Stack Segment): Segment base address of the stack​

3. PUSH Instruction

●​ Pushes data onto the stack: decreases SP and stores value at new SP​

MOV AX, 5
PUSH AX ; AX is pushed onto stack

4. POP Instruction

●​ Pops data from the stack: loads value from SP into destination and increases SP​

POP BX ; Value from stack goes to BX

5. Example: Subroutine Call Using Stack

CALL SUB1 ; Push return address


...
SUB1:
PUSH AX
; operations
POP AX
RET ; Return to caller

Summary

●​ Stack is essential for temporary storage and subroutine handling.​

●​ PUSH saves data; POP restores it.​

●​ Stack Pointer and Stack Segment registers manage stack memory.​

Key Terms

●​ Stack, LIFO, SP, SS, PUSH, POP, Subroutine​

Exercises / Self-Assessment

1.​ Push AX and BX onto the stack and then pop them back.​

2.​ Explain why the stack is important in subroutine calls.​

3.​ Show how SP changes after each PUSH and POP.​

Lesson 11: Arithmetic Instructions – Add, Sub, Inc,


Dec, Neg, Mul, Div
Learning Objectives:​
By the end of this lesson, students should be able to:
1.​ Use arithmetic instructions for integer operations.​

2.​ Understand signed and unsigned arithmetic in assembly.​

3.​ Detect overflow conditions in arithmetic operations.​

Lesson Content

1. ADD Instruction

●​ Adds source operand to destination and stores result in destination​

ADD AX, BX
ADD AL, 5

2. SUB Instruction

●​ Subtracts source from destination​

SUB AX, BX
SUB AL, 2

3. INC and DEC Instructions

●​ INC: Increments operand by 1​

●​ DEC: Decrements operand by 1​

INC AX
DEC BX

4. NEG Instruction

●​ Negates the operand (two’s complement)​

MOV AX, 5
NEG AX ; AX = -5
5. MUL and DIV Instructions

●​ MUL: Unsigned multiplication​

●​ DIV: Unsigned division​

MOV AL, 5
MOV BL, 2
MUL BL ; AL*BL → AX
DIV BL ; AX / BL → AL remainder in AH

6. Notes:

●​ Overflow flag (OF) may be set for signed operations.​

●​ Carry flag (CF) may be set for unsigned operations.​

Summary

●​ ADD, SUB, INC, DEC, NEG, MUL, and DIV perform basic arithmetic in assembly.​

●​ Flags help detect overflow and carry conditions.​

Key Terms

●​ ADD, SUB, INC, DEC, NEG, MUL, DIV, Overflow Flag, Carry Flag​

Exercises / Self-Assessment

1.​ Write assembly instructions to add 7 and 3, then subtract 5.​

2.​ Multiply 4 by 6 using MUL and show the result in registers.​

3.​ Explain the difference between signed and unsigned division.​


Lesson 12: Writing Arithmetic Expressions in Assembly
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Convert arithmetic expressions into assembly instructions.​


2.​ Understand operator precedence in assembly.​

3.​ Implement complex calculations using registers and memory.​

Lesson Content

1. Arithmetic Expressions Example

●​ Expression: X = A + B - C​

MOV AX, [A] ; Load A into AX


ADD AX, [B] ; AX = A + B
SUB AX, [C] ; AX = A + B - C
MOV [X], AX ; Store result in X

2. Expression with Multiplication/Division

●​ Expression: Y = (A + B) * C​

MOV AX, [A]


ADD AX, [B]
MOV BX, [C]
MUL BX ; AX = (A + B) * C
MOV [Y], AX

3. Using Temporary Registers

●​ Use registers to hold intermediate results to simplify calculations.​

●​ Example: (A - B) + (C * D)​

MOV AX, [A]


SUB AX, [B] ; AX = A - B
MOV BX, [C]
MUL [D] ; BX = C * D
ADD AX, BX ; AX = (A - B) + (C * D)
MOV [RESULT], AX
4. Notes

●​ Operator precedence must be considered manually in assembly.​

●​ Use temporary registers wisely to avoid overwriting values.​

Summary

●​ Arithmetic expressions require breaking down into simple instructions.​

●​ Intermediate results are stored in registers before final storage.​

●​ Careful planning ensures correct calculation order.​

Key Terms

●​ Arithmetic Expression, Operator Precedence, Temporary Register, Intermediate


Result​

Exercises / Self-Assessment

1.​ Write assembly instructions for Z = (X + Y) - (A * B).​

2.​ Explain how to handle division when the divisor is a memory location.​

3.​ Use temporary registers to calculate (M + N) / (P - Q).​

Lesson 13: Boolean Instructions – AND, OR, NOT, XOR,


SHL, SHR, ROL, ROR, TEST, CMP
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Perform bitwise operations using Boolean instructions.​


2.​ Understand the use of shift and rotate instructions.​

3.​ Compare values using TEST and CMP.​

Lesson Content

1. AND Instruction

●​ Performs bitwise AND between two operands​

MOV AL, 11001100B


AND AL, 10101010B ; AL = 10001000B

2. OR Instruction

●​ Performs bitwise OR between operands​

MOV AL, 11001100B


OR AL, 10101010B ; AL = 11101110B

3. NOT Instruction

●​ Inverts all bits of operand​

MOV AL, 00001111B


NOT AL ; AL = 11110000B

4. XOR Instruction

●​ Bitwise exclusive OR​

MOV AL, 11001100B


XOR AL, 10101010B ; AL = 01100110B

5. Shift Instructions (SHL, SHR)

●​ SHL: Shift bits left (multiply by 2)​


●​ SHR: Shift bits right (divide by 2)​

SHL AL, 1 ; Left shift by 1


SHR AL, 1 ; Right shift by 1

6. Rotate Instructions (ROL, ROR)

●​ Rotate bits through carry flag​

ROL AL, 1 ; Rotate left


ROR AL, 1 ; Rotate right

7. TEST Instruction

●​ Performs AND without storing result; affects flags​

MOV AL, 1100B


TEST AL, 0100B ; ZF set if result is zero

8. CMP Instruction

●​ Compares two operands; affects flags but does not store result​

MOV AL, 5
CMP AL, 3 ; Sets ZF, CF, SF accordingly

Summary

●​ Boolean instructions manipulate individual bits.​

●​ Shift and rotate are used for multiplication, division, and data manipulation.​

●​ TEST and CMP are essential for conditional operations.​

Key Terms
●​ AND, OR, NOT, XOR, SHL, SHR, ROL, ROR, TEST, CMP, ZF, CF, SF​

Exercises / Self-Assessment

1.​ Use AND to mask lower nibble of AL.​

2.​ Rotate AL left by 2 positions using ROL.​

3.​ Compare AX and BX using CMP and explain flag results.​

Lesson 14: Advanced Boolean Instructions


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Apply advanced Boolean operations in assembly.​

2.​ Understand multi-bit operations and masking.​


3.​ Implement practical examples of bit manipulation.​

Lesson Content

1. Combining Boolean Instructions

●​ Example: Set lower 4 bits of AL to 1​

MOV AL, 11000000B


OR AL, 00001111B ; AL = 11001111B

2. Clearing Bits Using AND

●​ Clear upper nibble of AL​

MOV AL, 10101111B


AND AL, 00001111B ; AL = 00001111B

3. Toggle Bits Using XOR

MOV AL, 10101010B


XOR AL, 11110000B ; AL = 01011010B

4. Practical Applications

●​ Setting/clearing flags, masking data, bit-level encryption, port manipulation.​

Summary

●​ Advanced Boolean instructions allow precise control of individual bits.​

●​ Essential in low-level hardware programming and embedded systems.​

Key Terms
●​ Masking, Bit Manipulation, Toggle, Clear, Set​

Exercises / Self-Assessment

1.​ Clear bits 3 and 4 of AL.​

2.​ Toggle the upper nibble of BL.​

3.​ Use OR to set bits 0 and 1 of a register.​

Lesson 15: Unconditional / Conditional Jumps and


Loops (LOOP, JMP, Jxx)
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Use unconditional and conditional jumps.​


2.​ Implement loops using CX and LOOP instruction.​

3.​ Apply jump instructions based on flag conditions.​

Lesson Content

1. Unconditional Jump – JMP

●​ Always transfers control to the specified label​

JMP START

2. Conditional Jumps – Jxx

●​ Based on flags:​
| Instruction | Condition |​
|-------------|-----------|​
| JE / JZ | Zero Flag set |​
| JNE / JNZ | Zero Flag not set |​
| JC | Carry Flag set |​
| JNC | Carry Flag not set |​
| JO | Overflow Flag set |​
| JNO | Overflow Flag not set |​
| JS | Sign Flag set |​
| JNS | Sign Flag not set |​

3. LOOP Instruction

●​ Decrements CX and jumps if CX ≠ 0​

MOV CX, 5
LOOP_LABEL:
; instructions
LOOP LOOP_LABEL

4. Notes

●​ Conditional jumps control program flow based on arithmetic/logical results.​

●​ LOOP is efficient for counting iterations using CX.​


5. Example:

MOV CX, 3
MOV AX, 0
LOOP_START:
ADD AX, 2
LOOP LOOP_START
; AX = 6

Summary

●​ JMP provides unconditional branching.​

●​ Jxx instructions allow decision-making based on flags.​

●​ LOOP instruction simplifies repetitive operations.​

Key Terms

●​ JMP, LOOP, Conditional Jump, Unconditional Jump, CX Register, Flags​

Exercises / Self-Assessment

1.​ Write a loop to add numbers 1 to 5 using LOOP.​

2.​ Use JZ to jump to a label if AX = 0.​

3.​ Explain the difference between JMP and JE.​


Lesson 16: Program Examples
Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Write complete assembly programs using learned instructions.​

2.​ Apply arithmetic, Boolean, data transfer, and control instructions.​

3.​ Debug and execute simple programs.​


Lesson Content

1. Example 1: Addition of Two Numbers

DATA SEGMENT
NUM1 DB 5
NUM2 DB 3
RESULT DB ?
DATA ENDS

CODE SEGMENT
START:
MOV AL, NUM1
ADD AL, NUM2
MOV RESULT, AL
; terminate program
MOV AH, 4CH
INT 21H
CODE ENDS
END START

2. Example 2: Find Maximum of Two Numbers

MOV AL, NUM1


CMP AL, NUM2
JGE NUM1_GREATER
MOV AL, NUM2
NUM1_GREATER:
MOV MAX, AL

3. Example 3: Loop to Sum 1 to 5

MOV CX, 5
MOV AX, 0
SUM_LOOP:
ADD AX, CX
LOOP SUM_LOOP
MOV SUM_RESULT, AX

4. Notes
●​ Break programs into data segment and code segment.​

●​ Use labels for loops and conditional jumps.​

●​ Save and restore registers when using subroutines.​

Summary

●​ Writing complete programs integrates all learned instructions.​

●​ Proper structure and debugging are key for successful execution.​

Key Terms

●​ Data Segment, Code Segment, Loop, CMP, ADD, Label​

Exercises / Self-Assessment

1.​ Write a program to subtract two numbers and store the result.​

2.​ Write a loop to multiply numbers from 1 to 4 using repeated addition.​

3.​ Debug a program that finds the smallest of three numbers.​

Lesson 17: Interrupts / I-O Instructions – INT, IN, OUT


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Understand the concept of interrupts in assembly.​

2.​ Use software and hardware interrupts for input/output.​

3.​ Communicate with I/O ports using IN and OUT instructions.​


Lesson Content

1. Interrupt Concept

●​ Interrupt: Signal to the processor to temporarily halt current execution and


execute a service routine.​

●​ Types:​

○​ Software interrupts (e.g., INT 21H)​

○​ Hardware interrupts (from external devices)​

2. INT Instruction

●​ Calls interrupt service routines (ISR)​

●​ Example: Print character on screen​

MOV DL, 'A'


MOV AH, 02H
INT 21H

3. IN and OUT Instructions

●​ IN: Reads data from an input port​

●​ OUT: Sends data to an output port​

IN AL, 60H ; Read from keyboard port


OUT 61H, AL ; Send data to port

4. Notes

●​ INT instructions are used to access DOS services.​

●​ IN/OUT instructions are essential for hardware interfacing.​

Summary
●​ Interrupts allow handling events without polling.​

●​ INT, IN, and OUT instructions provide I/O capabilities in assembly.​

Key Terms

●​ Interrupt, ISR (Interrupt Service Routine), INT, IN, OUT, I/O Port​

Exercises / Self-Assessment

1.​ Write a program to print the character 'B' using INT 21H.​

2.​ Explain the difference between software and hardware interrupts.​

3.​ Read a byte from a port 60H and write it to port 61H.​

Lesson 18: Practical Exercises with Interrupts / I-O


Learning Objectives:​
By the end of this lesson, students should be able to:

1.​ Implement small programs using interrupts and I/O instructions.​

2.​ Apply learned instructions to interact with hardware.​

3.​ Debug and test I/O programs.​


Lesson Content

1. Example: Input a Character and Display It

MOV AH, 01H ; DOS input function


INT 21H ; AL = input character
MOV DL, AL
MOV AH, 02H ; DOS output function
INT 21H ; Display character

2. Example: Keyboard to Screen Echo

KEY_LOOP:
MOV AH, 01H
INT 21H ; Get char
MOV DL, AL
MOV AH, 02H
INT 21H ; Display char
CMP AL, 0DH ; Check Enter key
JNZ KEY_LOOP

3. Example: Simple Port Output

MOV AL, 0FFH


OUT 61H, AL ; Send value to port 61H

4. Notes

●​ Always check flags and return values.​

●​ Ensure correct port numbers for hardware I/O.​

●​ Use loops for continuous reading and writing.​

Summary

●​ Interrupts and I/O instructions are essential for interactive programs.​


●​ DOS services and port I/O expand the capabilities of assembly programs.​

●​ Debugging ensures reliability and correct program flow.​

Key Terms

●​ Keyboard Input, Screen Output, Port, INT, IN, OUT​

Exercises / Self-Assessment

1.​ Write a program to read a character from the keyboard and convert lowercase to
uppercase before displaying.​

2.​ Create a loop that echoes characters until Enter is pressed.​

3.​ Send a pattern (e.g., 0xAA) repeatedly to port 61H.​

Course Conclusion
●​ Assembly Language Programming teaches low-level programming using the 8086
microprocessor.​

●​ Students have learned instruction formats, registers, arithmetic/Boolean instructions,


jumps, loops, stack operations, interrupts, and I/O.​

●​ Practical exercises and program examples develop problem-solving and debugging


skills.​

●​ Mastery of this course forms a foundation for systems programming, embedded


systems, and computer architecture understanding.​

References and Online Learning Resources


Books:
1.​ Peter Abel, Assembly Language Programming and Organization of the IBM PC,
2019.​

2.​ Kip R. Irvine, Assembly Language for x86 Processors, 7th Edition, 2015.​

3.​ Richard Detmer, The 8086 Microprocessor Architecture, 2017.​

Online Resources (Free):

1.​ Tutorialspoint – x86 Assembly​

2.​ NASM Documentation​

3.​ PC Assembly Language​

4.​ YouTube – Assembly Language Tutorials

You might also like