ASSEMBLY LANGUAGE 01

Assembly Language

Overview

  • Definition: Assembly language is a specific set of instructions tailored for a particular computer system.
  • Characteristics: It is classified as a Low Level Programming Language.
  • Importance of Learning Assembly Language:
    • Enhances algorithmic/coding skills.
    • Provides an introduction to low-level programming concepts.

Industrial Applications of Assembly Language

  • Uses:
    • Device Drivers
    • Real-Time Systems
    • Embedded Computing Systems
  • Companies: Utilized in products from IBM, Dell, HP, etc.
  • Advantages:
    • Programs are lighter and faster.
    • Requires less memory.
    • Examples of Assembly language applications include: Printers, Mice, USB devices.

Machine Instructions

  • Definition: A machine instruction is a binary code that instructs a computer’s CPU to perform specific tasks.
  • Representation: Machine instructions are often represented using hexadecimal numbers to minimize the amount of writing space needed.

Central Processing Unit (CPU) Architecture

  • Registers:
    • The following are the registers found inside the Intel 8086 CPU:
    • General Purpose Registers: AX, AH, AL, BX, BH, BL, CX, CH, CL, DX, DH, DL
    • Special Purpose Registers: CS, LP, SS, SP, BP, SI, DI, ES, DS

What are Registers?

  • Definition: Registers are memory devices used for storing data.
  • Specification: In the 8086 architecture, all registers are 16 bits in size.

General Purpose Registers in the 8086 CPU

  • The 8086 CPU contains 8 General Purpose Registers:
    1. AX - Accumulator Register (divided into AH and AL)
    2. BX - Base Address Register (divided into BH and BL)
    3. CX - Count Register (divided into CH and CL)
    4. DX - Data Register (divided into DH and DL)
    5. SI - Source Index Register
    6. DI - Destination Index Register
    7. BP - Base Pointer
    8. SP - Stack Pointer

Segment Registers

  • Definition: Segments are specific memory areas defined in a program.
  • Types of Segment Registers:
    • CS (Code Segment): Points to the segment containing the current program.
    • DS (Data Segment): Generally points to the segment where variables are defined.
    • ES (Extra Segment): An additional segment defined by the coder based on need.
    • SS (Stack Segment): Points to the segment containing the stack.

Understanding the First Four Registers (AX, BX, CX, DX)

  • These registers comprise two separate 8-bit registers.
  • Example:
    • If AX=0011000000111001bAX = 0011 0000 0011 1001_b then:
      • AH=00110000bAH = 0011 0000_b
      • AL=00111001bAL = 0011 1001_b
    • This means AX=AH+ALAX = AH + AL

Variable Declaration in 8086 Assembly Language

  • Comparison with C/C++:
    • C/C++ Example:
    • int x = 10;
    • double y = 20.0;
    • 8086 Assembler Data Types:
    1. DB (Define Byte) – 1 byte
    2. DW (Define Word) – 2 bytes
    3. DD (Define Double Word) – 4 bytes
    4. DQ (Define Quad Word) – 8 bytes
Examples of Variable Declarations
  • Example for DB (Define Byte):
    • For smaller values:
    • Var_Name Type Value
    • A DB 9
    • Message DB 'HelloWorld'
  • Example for DW (Define Word):
    • For larger values:
    • Var_Name Type Value
    • Var DW 1122H
String Variables in Assembly Language
  • Declaration:
    • STR1 DB 'Hello World'
    • STR2 DB 'Hello World', '$' // '$' indicates end of string
    • STR3 DB 10,13, 'Hello World', '$' // 10, 13 is for new line
Array Declarations in 8086 Assembly Language
  • Example of Array Declaration:
    • Name Type Value
    • a DB 1h,2h,3Fh,7Fh
    • b DB 1111h,2222h,3333h
Accessing Array Values
  • Accessing Elements in an Array:
    • Given array example:
    • a DB 22h,23h,24h,25h
    • Locations:
      • a[0] -> 22
      • a[1] -> 23
      • a[2] -> 24
      • a[3] -> 25
    • Example Instructions:
    • MOV AL, a[2]
    • Using Index Registers:
      • MOV SI, 2
      • MOV AL, a[SI]
Declaration using DUP in 8086 Assembly Language
  • Usage:
    • DUP or dup stands for duplicate.
  • Examples:
    • X DB 3 DUP (7)
    • Similar to:
    • X DB 7,7,7
    • Y DB 3 DUP (5,6)
    • Similar to:
      • Y DB 5,6,5,6,5,6

MOV Instruction in 8086 Assembly Language

  • Definition: The MOV instruction copies the second operand (the source) to the first operand (the destination).
  • Types of Operand Supported:
    • MOV Reg, Memory
    • MOV Memory, Reg
    • MOV Reg, Reg
    • MOV Memory, Immediate
    • MOV Reg, Immediate
  • Note: MOV Mem, Mem is not supported.
Operand Types
  • Registers Used:
    • For example: AX, BX, CX, DX, AL, DI, AH, etc.
  • Immediate Values:
    • Examples: 7, -11, 4FH (Hexadecimal)
  • Memory Access:
    • Examples: [BX] or [BX+SI] + Displacement
    • BX, SI, DI, BP can be used to access memory.
Examples of MOV Instructions
  • MOV AX, BX // Register to Register
  • MOV [BX], AX // Memory to Register
  • MOV AX, [BX] // Register to Memory
  • MOV [BX+SI], 5 // Memory to Immediate
  • MOV AX, 5 // Register to Immediate

Arithmetic Operations

  • Arithmetic Operation Examples in C/C++/Java/C#:
    • Addition, Subtraction, Multiplication
    • Example code:
      int a = 11; int b = 14; int sum = 0, sub = 0, mul = 0; sum = a + b; // sum = 25 sub = a - b; // sub = -3 mul = a * b; // mul = 154

Arithmetic Instructions in 8086

  • Includes Multiple Operations:
    1. Addition
    2. Subtraction
    3. Multiplication
    4. Division
Addition Syntax in 8086
  • Syntax: ADD Destination, Source
  • Result: The outcome gets stored in the destination.
  • Example:
    • Case Study:
    • If AX=11HAX = 11H and BX=14HBX = 14H, then:
      • ADD AX, BX results in AX = 25H
Supported Operand Types for Addition
  • Types of Operands:
    • Operands:
    • Register to Register: ADD AX, BX
    • Memory to Register: ADD [BX], AX
    • Register to Memory: ADD AX, [BX]
    • Memory to Immediate: ADD [BX], 7
    • Register to Immediate: ADD CL, 40H
Example of Addition in Assembly Language
  • Instructions:
    • MOV AX, 11H // Set AX = 11H
    • MOV BX, 14H // Set BX = 14H
    • ADD AX, BX // AX now contains 25H
  • Binary Representation:
    • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1
    • Representations for 11H, 14H, and 25H respectively.