PadhaikoAll subjects

Instruction & Data Formats, Addressing Modes

Microprocessors (ENEX 201)

Open in the Padhaiko app

2.4 Instruction format and data format

An instruction is a binary command given to the microprocessor to perform a specific operation on designated data. The entire set of instructions that a microprocessor is designed to execute is called its instruction set.

In assembly language, an instruction is written as a human-readable mnemonic statement. Every instruction consists of two essential parts:

  1. Opcode (Operation Code): Specifies the task to be performed by the processor (e.g., MOV, ADD, SUB, JMP, STA).
  2. Operand: Specifies the data to be operated upon. Depending on the instruction, the operand may be an 8-bit or 16-bit numerical constant, an internal CPU register, a memory address, an I/O port address, or may be implicitly understood by the opcode.
Text
+---------------------------+-----------------------------------+
|   OPCODE (Task to do)     |     OPERAND (Data or Location)    |
|   e.g., MOV, ADD, MVI     |     e.g., A, B or 2050H or 32H    |
+---------------------------+-----------------------------------+

Instruction Formats by Byte Size

In the Intel 8085 microprocessor, instructions are classified into three formats based on the number of memory bytes required to store them in primary memory:

Classification of 8085 Instructions by Size
Format TypeByte SizeFormat StructureDescriptionExamples with Hex Machine Codes
One-Byte Instruction1 byte[Opcode / Operands]Opcode and operands are encoded together within a single 8-bit memory byte. No extra bytes needed.MOV A, B (78H), ADD C (81H), CMA (2FH), HLT (76H), XCHG (EBH)
Two-Byte Instruction2 bytesByte 1: [Opcode]
Byte 2: [8-bit Data or Port]
Byte 1 contains the operation code; Byte 2 contains an 8-bit immediate data byte or an 8-bit I/O port address.MVI A, 32H (3EH 32H), ADI 05H (C6H 05H), IN 01H (DBH 01H), CPI 50H (FEH 50H)
Three-Byte Instruction3 bytesByte 1: [Opcode]
Byte 2: [Low-Order Addr/Data]
Byte 3: [High-Order Addr/Data]
Byte 1 contains the opcode; Bytes 2 and 3 specify a 16-bit memory address or 16-bit immediate data. Stored in Little-Endian format.LDA 2050H (3AH 50H 20H), STA 3000H (32H 00H 30H), LXI H, 4000H (21H 00H 40H), JMP 2500H (C3H 00H 25H)

Data Formats Supported by 8085

The 8085 is an 8-bit processor, so all data items are handled in byte units (or pairs of bytes). The processor natively manipulates five fundamental binary data formats:

  1. ASCII Characters: 7-bit or 8-bit alphanumeric characters encoded according to the American Standard Code for Information Interchange (e.g., ASCII '0' = 30H, 'A' = 41H, 'a' = 61H).
  2. Unsigned Binary Numbers: 8-bit binary integers where all 8 bits represent numerical magnitude from 0 (00H = 0000 0000B) to 255 (FFH = 1111 1111B).
  3. Signed Binary Numbers (Two's Complement): 8-bit signed integers where bit D7 represents the sign (0 = positive, 1 = negative). Positive numbers range from 0 to +127 (00H to 7FH), while negative numbers are stored as two's complement ranging from -1 (FFH) to -128 (80H).
  4. Unpacked BCD (Binary Coded Decimal): Each 4-bit decimal digit (0 through 9) is stored in the lower nibble of an 8-bit byte, with the upper nibble set to 0000B (e.g., decimal 7 = 07H = 0000 0111B).
  5. Packed BCD: Two 4-bit decimal digits (0 through 9 each) are packed together into a single 8-bit byte (e.g., decimal 59 is stored as 59H = 0101 1001B). The valid range of packed BCD is 00H to 99H.
AspectUnpacked BCDPacked BCD
Digits per ByteExactly one decimal digit (0–9) per 8-bit byte.Two decimal digits (0–9 each) packed per byte.
Storage Efficiency50% efficient; upper nibble (0000B) is wasted.100% efficient; both nibbles carry numerical data.
Numeric Range per Byte0 to 9 (00H to 09H).0 to 99 (00H to 99H).
Example for Decimal 84Stored in two bytes: 08H followed by 04H.Stored in one byte: 84H (1000 0100B).
Arithmetic AdjustmentSimple masking (ANI 0FH).Requires DAA (Decimal Adjust Accumulator).

2.5 Addressing modes of 8085

The addressing mode refers to the technique or mechanism by which an instruction specifies the location of an operand upon which an operation is to be performed. An operand may be located in an internal CPU register, in an immediate instruction byte, in memory, or at an I/O port.

The Intel 8085 provides five distinct addressing modes:

Definition

The Five Addressing Modes of Intel 8085

  1. Immediate Addressing Mode: The data operand is specified directly within the instruction bytes following the opcode. Byte 2 (or Bytes 2 and 3) contains the actual numerical value.
    • Example: MVI A, 45H (Loads immediate byte 45H into Accumulator).
    • Example: LXI H, 2050H (Loads 16-bit immediate address 2050H into HL register pair).
    • Example: ADI 10H (Adds immediate byte 10H to Accumulator).
  2. Register Addressing Mode: The data operand is located within one of the general-purpose CPU registers (A, B, C, D, E, H, L). The instruction manipulates registers internally without generating external memory read or write cycles.
    • Example: MOV A, B (Copies contents of register B into register A).
    • Example: ADD C (Adds contents of register C to Accumulator).
    • Example: XRA D (Bitwise XOR of register D with Accumulator).
  3. Direct Addressing Mode: The 16-bit memory address where the operand is stored (or the 8-bit I/O port address) is specified explicitly as part of the instruction in Bytes 2 and 3.
    • Example: LDA 2050H (Loads Accumulator directly from memory address 2050H).
    • Example: STA 3000H (Stores Accumulator contents directly into memory address 3000H).
    • Example: LHLD 2500H (Loads L from 2500H and H from 2501H).
    • Example: IN 01H (Reads 8-bit data from I/O port address 01H into Accumulator).
  4. Register Indirect Addressing Mode: The 16-bit memory address of the operand is held in a register pair. The instruction specifies the register pair (primarily the H-L pair, referred to as memory operand M, or B-C / D-E for LDAX/STAX).
    • Example: MOV A, M (Loads Accumulator from memory location pointed to by HL pair).
    • Example: ADD M (Adds memory byte at address in HL to Accumulator).
    • Example: STAX B (Stores Accumulator byte into memory address pointed to by BC pair).
  5. Implicit (Implied) Addressing Mode: The operand is hidden or implied within the opcode itself. No explicit register or memory operand is specified in the mnemonic statement.
    • Example: CMA (Complements all bits of the Accumulator).
    • Example: STC (Sets Carry flag to logic 1).
    • Example: CMC (Complements Carry flag).
    • Example: RLC / RRC / RAL / RAR (Rotates Accumulator bits).
    • Example: EI / DI (Enables / Disables interrupts).
Summary of 8085 Addressing Modes
Addressing ModeLocation of OperandTypical InstructionByte SizeMachine CyclesT-States
ImmediateInside instruction (Byte 2 / Byte 3)MVI A, 32H2OF, MR7
RegisterInside CPU general register (A–L)MOV A, B1OF4
DirectAt 16-bit address specified in instructionLDA 2050H3OF, MR, MR, MR13
Register IndirectAt memory address held in register pair (HL/BC/DE)MOV A, M1OF, MR7
Implicit (Implied)Inherent in the opcode definitionCMA1OF4

Worked Examples

Example 1

1 (6 marks)

A programmer writes the following 8085 assembly language program starting at memory address 2000H:

Text
2000H: LXI H, 3050H
       MOV A, M
       ADI 08H
       STA 3060H
       HLT

Given the standard hex opcodes: LXI H = 21H, MOV A, M = 7EH, ADI = C6H, STA = 32H, HLT = 76H.

  1. Determine the byte length (1, 2, or 3 bytes) and addressing mode of each instruction.
  2. Construct a memory map table showing the hexadecimal memory address, machine code byte (in hex), and assembly mnemonic for every byte of this program.
  3. Calculate the total memory space occupied by this program in bytes.

1. Analyzing Instruction Length and Addressing Modes:

  • LXI H, 3050H: 3 bytes. Opcode = 21H, followed by 16-bit immediate data 3050H. Addressing mode = Immediate Addressing Mode.
  • MOV A, M: 1 byte. Opcode = 7EH. Operand is memory location pointed to by HL pair. Addressing mode = Register Indirect Addressing Mode.
  • ADI 08H: 2 bytes. Opcode = C6H, followed by 8-bit immediate operand 08H. Addressing mode = Immediate Addressing Mode.
  • STA 3060H: 3 bytes. Opcode = 32H, followed by 16-bit direct address 3060H. Addressing mode = Direct Addressing Mode.
  • HLT: 1 byte. Opcode = 76H. No operand needed. Addressing mode = Implicit (Implied) Addressing Mode.

2. Constructing the Memory Map Table: Remember to store 16-bit addresses in Little-Endian format (low byte first, then high byte):

  • For LXI H, 3050H: Low byte = 50H, High byte = 30H.
  • For STA 3060H: Low byte = 60H, High byte = 30H.
Memory Allocation and Machine Code Layout
Memory AddressMachine Code (Hex)Assembly Language InstructionComment
2000H21HLXI H, 3050HOpcode for LXI H
2001H50H(Low byte of data)LSB of 3050H
2002H30H(High byte of data)MSB of 3050H
2003H7EHMOV A, MOpcode: Load A from [HL]
2004HC6HADI 08HOpcode for ADI
2005H08H(Immediate data)Add 08H to Accumulator
2006H32HSTA 3060HOpcode for STA
2007H60H(Low byte of address)LSB of 3060H
2008H30H(High byte of address)MSB of 3060H
2009H76HHLTOpcode: Halt processor

3. Computing Total Memory Consumed: Total bytes = 3 + 1 + 2 + 3 + 1 = 10 bytes. The program occupies memory addresses from 2000H to 2009H. Next free memory location is 200AH.

Answer:
  1. Instruction classification: LXI H (3 bytes, Immediate), MOV A, M (1 byte, Register Indirect), ADI (2 bytes, Immediate), STA (3 bytes, Direct), HLT (1 byte, Implicit).
  2. Machine codes occupy 2000H to 2009H as: 21 50 30 7E C6 08 32 60 30 76.
  3. Total memory space occupied = 10 bytes.
Example 2

2 (4 marks)

A decimal number 85 is to be processed by an 8085 microprocessor.

  1. Represent decimal 85 as an 8-bit unsigned binary integer and express it in hexadecimal.
  2. Represent decimal 85 as an 8-bit packed BCD number and express it in hexadecimal.
  3. Represent decimal -85 as an 8-bit signed two's complement integer and express it in hexadecimal.

1. Unsigned Binary Integer Representation: Convert decimal 85 to binary by successive division by 2: 85 = 64 + 16 + 4 + 1 = 0101 0101B. In hexadecimal: 0101B = 5H, 0101B = 5H -> 55H. Decimal 85 in unsigned binary is 0101 0101B = 55H.

2. Packed BCD Representation: In packed BCD, each decimal digit is encoded directly as a 4-bit binary nibble (0–9):

  • Decimal digit 8 = 1000B.
  • Decimal digit 5 = 0101B.

Combining the two nibbles: Packed BCD = 1000 0101B. In hexadecimal: 1000B = 8H, 0101B = 5H -> 85H. Note: While the bit pattern resembles hex 85H, its numerical value in pure binary would be 133, demonstrating why packed BCD must be adjusted using DAA.

3. Signed Two's Complement Representation of -85: Step A: Find true binary for positive +85: +85 = 0101 0101B. Step B: Take one's complement (invert all bits): 1010 1010B. Step C: Add 1 to obtain two's complement: 1010 1010B + 1 = 1010 1011B. Convert 1010 1011B to hexadecimal: 1010B = AH, 1011B = BH -> ABH.

Answer:
  1. Unsigned binary integer = 0101 0101B = 55H.
  2. Packed BCD representation = 1000 0101B = 85H.
  3. Signed two's complement integer (-85) = 1010 1011B = ABH.
Example 3

3 (6 marks)

(Tribhuvan University Past exam questions Guide) For each of the following 8085 instructions: (a) XCHG (b) MVI M, 55H (c) LDA 4000H (d) STAX B (e) RAL Identify:

  1. The addressing mode employed.
  2. The instruction length in bytes.
  3. The machine cycles executed and total T-states required.

Analysis of Each Instruction:

  1. XCHG (Exchange HL with DE registers):
    • Addressing Mode: Register Addressing Mode (all source and destination operands are internal CPU register pairs).
    • Length: 1 byte (Opcode: EBH).
    • Machine Cycles: 1 machine cycle (Opcode Fetch: OF = 4T). Total = 4 T-states.
  2. MVI M, 55H (Move immediate data 55H into memory [HL]):
    • Addressing Mode: Immediate Addressing Mode for the data, combined with Register Indirect Addressing Mode for the target memory pointer. Categorized primarily as Immediate Addressing Mode.
    • Length: 2 bytes (Opcode: 36H, Data: 55H).
    • Machine Cycles: 3 machine cycles (OF = 4T, Memory Read for data = 3T, Memory Write to [HL] = 3T). Total = 10 T-states.
  3. LDA 4000H (Load Accumulator direct from 4000H):
    • Addressing Mode: Direct Addressing Mode (16-bit memory address specified explicitly in instruction).
    • Length: 3 bytes (Opcode: 3AH, Low Addr: 00H, High Addr: 40H).
    • Machine Cycles: 4 machine cycles (OF = 4T, MR low address = 3T, MR high address = 3T, MR data operand = 3T). Total = 13 T-states.
  4. STAX B (Store Accumulator into memory [BC]):
    • Addressing Mode: Register Indirect Addressing Mode (memory address is held in register pair BC).
    • Length: 1 byte (Opcode: 02H).
    • Machine Cycles: 2 machine cycles (OF = 4T, Memory Write = 3T). Total = 7 T-states.
  5. RAL (Rotate Accumulator Left through Carry):
    • Addressing Mode: Implicit (Implied) Addressing Mode (operates inherently on Accumulator and Carry flag).
    • Length: 1 byte (Opcode: 17H).
    • Machine Cycles: 1 machine cycle (OF = 4T). Total = 4 T-states.
Answer:

(a) XCHG: Register, 1 byte, 1 cycle (OF), 4 T-states. (b) MVI M, 55H: Immediate / Indirect, 2 bytes, 3 cycles (OF, MR, MW), 10 T-states. (c) LDA 4000H: Direct, 3 bytes, 4 cycles (OF, MR, MR, MR), 13 T-states. (d) STAX B: Register Indirect, 1 byte, 2 cycles (OF, MW), 7 T-states. (e) RAL: Implicit, 1 byte, 1 cycle (OF), 4 T-states.


Exercises

Exercises

Question 1

Define an instruction and distinguish between the opcode and operand. Explain the 1-byte, 2-byte, and 3-byte instruction formats of the Intel 8085 microprocessor with two examples of each.

Definition of Instruction, Opcode, and Operand: An instruction is a binary command given to the microprocessor to execute a specific elementary operation.

  • Opcode (Operation Code): The part of the instruction that tells the processor what operation to perform (e.g., add, subtract, move, branch).
  • Operand: The data or location upon which the operation is performed (e.g., register name, memory address, constant byte).

The Three 8085 Instruction Formats:

  1. One-Byte Instructions:
    • Both opcode and operand are encoded together in a single 8-bit memory byte.
    • Examples:
      • MOV A, B (Opcode: 78H): Moves data from register B to A.
      • ADD M (Opcode: 86H): Adds data at memory location pointed to by HL to Accumulator.
  2. Two-Byte Instructions:
    • The first byte specifies the opcode, and the second byte specifies an 8-bit immediate data operand or an 8-bit I/O port address.
    • Examples:
      • MVI A, 32H (Bytes: 3EH 32H): Loads immediate byte 32H into Accumulator.
      • IN 05H (Bytes: DBH 05H): Reads data from input port 05H into Accumulator.
  3. Three-Byte Instructions:
    • The first byte specifies the opcode, the second byte specifies the lower-order 8 bits of a 16-bit address/data, and the third byte specifies the higher-order 8 bits.
    • Examples:
      • LDA 2050H (Bytes: 3AH 50H 20H): Loads Accumulator from memory address 2050H.
      • JMP 3000H (Bytes: C3H 00H 30H): Unconditional jump to address 3000H.
Answer:

An instruction contains an opcode (task) and operands (data). The 8085 uses 1-byte formats (MOV A, B, ADD M), 2-byte formats with 8-bit data/port (MVI A, 32H, IN 05H), and 3-byte formats with 16-bit addresses in little-endian order (LDA 2050H, JMP 3000H).

Question 2

Define addressing mode. List and explain all five addressing modes supported by the Intel 8085 microprocessor with two distinct examples for each mode.

Definition of Addressing Mode: An addressing mode is the method by which an instruction specifies the location of an operand (data byte) upon which it operates.

The Five 8085 Addressing Modes:

  1. Immediate Addressing Mode:
    • The operand is specified directly within the instruction bytes following the opcode.
    • Examples: MVI B, 40H, LXI D, 3000H.
  2. Register Addressing Mode:
    • The operand is stored in one of the general-purpose CPU registers.
    • Examples: MOV B, C, SUB E.
  3. Direct Addressing Mode:
    • The 16-bit memory address where the operand resides is explicitly stated in Bytes 2 and 3 of the instruction.
    • Examples: STA 2050H, LHLD 4000H.
  4. Register Indirect Addressing Mode:
    • The 16-bit memory address of the operand is held in a register pair (primarily the HL pair, denoted as M).
    • Examples: MOV M, A, ADD M.
  5. Implicit (Implied) Addressing Mode:
    • The operand is inherent in the opcode itself; no explicit register or address operand is stated in the mnemonic.
    • Examples: CMA (Complement Accumulator), STC (Set Carry Flag).
Answer:

The five addressing modes are: (1) Immediate (MVI B, 40H), (2) Register (MOV B, C), (3) Direct (STA 2050H), (4) Register Indirect (MOV M, A), and (5) Implicit (CMA, STC).

Question 3

Compare direct addressing mode and register indirect addressing mode in the 8085 with respect to instruction size, execution speed (T-states), flexibility in loop processing, and suitable application scenarios.

Detailed Comparison Table:

  • Instruction Size:
    • Direct Addressing: 3 bytes (Opcode + 2 address bytes). Consumes more program memory.
    • Register Indirect: 1 byte (e.g., MOV A, M). Extremely compact code size.
  • Execution Speed:
    • Direct Addressing: Slower (typically 13 T-states, e.g., LDA 2050H), because the CPU must execute two Memory Read cycles just to fetch the 16-bit target address before reading the data operand.
    • Register Indirect: Faster (typically 7 T-states, e.g., MOV A, M), because the target 16-bit address is already present in internal CPU registers (HL) and can be placed on the address bus immediately.
  • Flexibility in Loops & Arrays:
    • Direct Addressing: Inflexible. The target address is fixed in ROM code; scanning an array requires self-modifying code (impossible in ROM).
    • Register Indirect: Highly flexible. The HL register pair acts as a pointer and can be incremented (INX H) or decremented (DCX H) inside a loop to traverse arrays and tables dynamically.
  • Typical Use Cases:
    • Direct Addressing: Accessing isolated global variables or memory-mapped I/O registers.
    • Register Indirect: Iterating through blocks of data, string searching, and sorting arrays.
Answer:

Direct addressing uses 3 bytes and ~13 T-states with a fixed target address (best for single variables), while register indirect uses 1 byte and 7 T-states with a pointer in HL that can be dynamically incremented (ideal for loops and arrays).

Question 4

Explain the data formats handled by the 8085 microprocessor. Convert decimal 47 into:

  1. An 8-bit unsigned binary integer (in binary and hexadecimal).
  2. An 8-bit packed BCD number (in binary and hexadecimal).
  3. Two bytes of unpacked BCD numbers.

8085 Data Formats Overview: The 8085 processes ASCII characters (8-bit), unsigned binary integers (0 to 255), signed two's complement integers (-128 to +127), unpacked BCD (1 digit per byte), and packed BCD (2 digits per byte).

1. Decimal 47 as an Unsigned Binary Integer: 47 = 32 + 8 + 4 + 2 + 1 = 0010 1111B. In hexadecimal: 0010B = 2H, 1111B = FH -> 2FH.

2. Decimal 47 as a Packed BCD Number: Each decimal digit is encoded as a 4-bit BCD nibble:

  • Digit 4 = 0100B.
  • Digit 7 = 0111B.

Packed into one byte: Packed BCD = 0100 0111B. In hexadecimal: 47H.

3. Decimal 47 as Two Unpacked BCD Bytes: Each digit occupies the lower 4 bits of its own byte, with the upper 4 bits zeroed:

  • First byte (tens digit 4): 0000 0100B = 04H.
  • Second byte (units digit 7): 0000 0111B = 07H.
Answer:
  1. Unsigned binary = 0010 1111B = 2FH.
  2. Packed BCD = 0100 0111B = 47H.
  3. Unpacked BCD = two bytes: 04H and 07H.
Question 5

Identify the addressing mode, instruction length in bytes, and total number of machine cycles for each of the following 8085 instructions:

  1. MVI B, 50H
  2. ADD M
  3. STA 2500H
  4. CMA
  5. LDAX D

Step-by-Step Analysis:

  1. MVI B, 50H:
    • Addressing Mode: Immediate Addressing Mode (data 50H is inside instruction).
    • Length: 2 bytes (Opcode: 06H, Data: 50H).
    • Machine Cycles: 2 machine cycles (Opcode Fetch + Memory Read). Total = 7 T-states.
  2. ADD M:
    • Addressing Mode: Register Indirect Addressing Mode (address in HL pair).
    • Length: 1 byte (Opcode: 86H).
    • Machine Cycles: 2 machine cycles (Opcode Fetch + Memory Read). Total = 7 T-states.
  3. STA 2500H:
    • Addressing Mode: Direct Addressing Mode (address 2500H in instruction bytes 2 and 3).
    • Length: 3 bytes (Opcode: 32H, Low Addr: 00H, High Addr: 25H).
    • Machine Cycles: 4 machine cycles (Opcode Fetch + Memory Read + Memory Read + Memory Write). Total = 13 T-states.
  4. CMA:
    • Addressing Mode: Implicit (Implied) Addressing Mode (operates on Accumulator).
    • Length: 1 byte (Opcode: 2FH).
    • Machine Cycles: 1 machine cycle (Opcode Fetch). Total = 4 T-states.
  5. LDAX D:
    • Addressing Mode: Register Indirect Addressing Mode (address in DE pair).
    • Length: 1 byte (Opcode: 0AH).
    • Machine Cycles: 2 machine cycles (Opcode Fetch + Memory Read). Total = 7 T-states.
Answer:
  1. MVI B, 50H: Immediate, 2 bytes, 2 cycles (OF, MR).
  2. ADD M: Register Indirect, 1 byte, 2 cycles (OF, MR).
  3. STA 2500H: Direct, 3 bytes, 4 cycles (OF, MR, MR, MW).
  4. CMA: Implicit, 1 byte, 1 cycle (OF).
  5. LDAX D: Register Indirect, 1 byte, 2 cycles (OF, MR).

Past exam questions for Microprocessors

← 8085 Features, Internal Architecture & Pin Configuration8085 Instruction Set →