Instruction & Data Formats, Addressing Modes
Open in the Padhaiko app2.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:
- Opcode (Operation Code): Specifies the task to be performed by the processor (e.g.,
MOV,ADD,SUB,JMP,STA). - 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.
+---------------------------+-----------------------------------+
| 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:
| Format Type | Byte Size | Format Structure | Description | Examples with Hex Machine Codes |
|---|---|---|---|---|
| One-Byte Instruction | 1 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 Instruction | 2 bytes | Byte 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 Instruction | 3 bytes | Byte 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:
- 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). - Unsigned Binary Numbers: 8-bit binary integers where all 8 bits represent numerical magnitude from
0(00H=0000 0000B) to255(FFH=1111 1111B). - Signed Binary Numbers (Two's Complement): 8-bit signed integers where bit D7 represents the sign (
0 = positive,1 = negative). Positive numbers range from0to+127(00Hto7FH), while negative numbers are stored as two's complement ranging from-1(FFH) to-128(80H). - 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., decimal7=07H=0000 0111B). - Packed BCD: Two 4-bit decimal digits (0 through 9 each) are packed together into a single 8-bit byte (e.g., decimal
59is stored as59H=0101 1001B). The valid range of packed BCD is00Hto99H.
| Aspect | Unpacked BCD | Packed BCD |
|---|---|---|
| Digits per Byte | Exactly one decimal digit (0–9) per 8-bit byte. | Two decimal digits (0–9 each) packed per byte. |
| Storage Efficiency | 50% efficient; upper nibble (0000B) is wasted. | 100% efficient; both nibbles carry numerical data. |
| Numeric Range per Byte | 0 to 9 (00H to 09H). | 0 to 99 (00H to 99H). |
| Example for Decimal 84 | Stored in two bytes: 08H followed by 04H. | Stored in one byte: 84H (1000 0100B). |
| Arithmetic Adjustment | Simple 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:
The Five Addressing Modes of Intel 8085
- 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 byte45Hinto Accumulator). - Example:
LXI H, 2050H(Loads 16-bit immediate address2050Hinto HL register pair). - Example:
ADI 10H(Adds immediate byte10Hto Accumulator).
- Example:
- 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).
- Example:
- 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 address2050H). - Example:
STA 3000H(Stores Accumulator contents directly into memory address3000H). - Example:
LHLD 2500H(Loads L from2500Hand H from2501H). - Example:
IN 01H(Reads 8-bit data from I/O port address01Hinto Accumulator).
- Example:
- 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 forLDAX/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).
- Example:
- 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).
- Example:
| Addressing Mode | Location of Operand | Typical Instruction | Byte Size | Machine Cycles | T-States |
|---|---|---|---|---|---|
| Immediate | Inside instruction (Byte 2 / Byte 3) | MVI A, 32H | 2 | OF, MR | 7 |
| Register | Inside CPU general register (A–L) | MOV A, B | 1 | OF | 4 |
| Direct | At 16-bit address specified in instruction | LDA 2050H | 3 | OF, MR, MR, MR | 13 |
| Register Indirect | At memory address held in register pair (HL/BC/DE) | MOV A, M | 1 | OF, MR | 7 |
| Implicit (Implied) | Inherent in the opcode definition | CMA | 1 | OF | 4 |
Worked Examples
1
A programmer writes the following 8085 assembly language program starting at memory address 2000H:
2000H: LXI H, 3050H
MOV A, M
ADI 08H
STA 3060H
HLTGiven the standard hex opcodes: LXI H = 21H, MOV A, M = 7EH, ADI = C6H, STA = 32H, HLT = 76H.
- Determine the byte length (1, 2, or 3 bytes) and addressing mode of each instruction.
- Construct a memory map table showing the hexadecimal memory address, machine code byte (in hex), and assembly mnemonic for every byte of this program.
- 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 data3050H. 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 operand08H. Addressing mode = Immediate Addressing Mode.STA 3060H: 3 bytes. Opcode =32H, followed by 16-bit direct address3060H. 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 Address | Machine Code (Hex) | Assembly Language Instruction | Comment |
|---|---|---|---|
2000H | 21H | LXI H, 3050H | Opcode for LXI H |
2001H | 50H | (Low byte of data) | LSB of 3050H |
2002H | 30H | (High byte of data) | MSB of 3050H |
2003H | 7EH | MOV A, M | Opcode: Load A from [HL] |
2004H | C6H | ADI 08H | Opcode for ADI |
2005H | 08H | (Immediate data) | Add 08H to Accumulator |
2006H | 32H | STA 3060H | Opcode for STA |
2007H | 60H | (Low byte of address) | LSB of 3060H |
2008H | 30H | (High byte of address) | MSB of 3060H |
2009H | 76H | HLT | Opcode: 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.
- 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). - Machine codes occupy
2000Hto2009Has:21 50 30 7E C6 08 32 60 30 76. - Total memory space occupied = 10 bytes.
2
A decimal number 85 is to be processed by an 8085 microprocessor.
- Represent decimal 85 as an 8-bit unsigned binary integer and express it in hexadecimal.
- Represent decimal 85 as an 8-bit packed BCD number and express it in hexadecimal.
- 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.
- Unsigned binary integer =
0101 0101B= 55H. - Packed BCD representation =
1000 0101B= 85H. - Signed two's complement integer (-85) =
1010 1011B= ABH.
3
(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:
- The addressing mode employed.
- The instruction length in bytes.
- The machine cycles executed and total T-states required.
Analysis of Each Instruction:
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.
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.
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.
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.
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.
(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
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:
- 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.
- 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 byte32Hinto Accumulator.IN 05H(Bytes:DBH 05H): Reads data from input port05Hinto Accumulator.
- 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 address2050H.JMP 3000H(Bytes:C3H 00H 30H): Unconditional jump to address3000H.
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).
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:
- Immediate Addressing Mode:
- The operand is specified directly within the instruction bytes following the opcode.
- Examples:
MVI B, 40H,LXI D, 3000H.
- Register Addressing Mode:
- The operand is stored in one of the general-purpose CPU registers.
- Examples:
MOV B, C,SUB E.
- 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.
- 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.
- The 16-bit memory address of the operand is held in a register pair (primarily the HL pair, denoted as
- 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).
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).
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.
- Direct Addressing: Slower (typically 13 T-states, e.g.,
- 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.
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).
Explain the data formats handled by the 8085 microprocessor. Convert decimal 47 into:
- An 8-bit unsigned binary integer (in binary and hexadecimal).
- An 8-bit packed BCD number (in binary and hexadecimal).
- 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.
- Unsigned binary =
0010 1111B= 2FH. - Packed BCD =
0100 0111B= 47H. - Unpacked BCD = two bytes: 04H and 07H.
Identify the addressing mode, instruction length in bytes, and total number of machine cycles for each of the following 8085 instructions:
MVI B, 50HADD MSTA 2500HCMALDAX D
Step-by-Step Analysis:
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.
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.
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.
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.
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.
MVI B, 50H: Immediate, 2 bytes, 2 cycles (OF, MR).ADD M: Register Indirect, 1 byte, 2 cycles (OF, MR).STA 2500H: Direct, 3 bytes, 4 cycles (OF, MR, MR, MW).CMA: Implicit, 1 byte, 1 cycle (OF).LDAX D: Register Indirect, 1 byte, 2 cycles (OF, MR).