Microprocessor and Computer ArchitectureUnit 912 min read
Instruction Formats & Assembly: 8085 Assembly, Mnemonics, Operands & Pipeline
Unit 9 of Microprocessor and Computer Architecture covers how 8085 instructions are encoded in binary (opcodes, operands), how assembly language maps to machine code, and how pipelining speeds up execution. Includes instruction formats, addressing modes, and real-world assembly programming examples.
TAKEAWAYS:
- Assembly language translates human-readable mnemonics (e.g.,
MOV,ADD) into binary machine code (e.g.,78hforMOV A,B). - Instruction formats define how opcodes and operands are structured (1-byte, 2-byte, 3-byte) in 8085.
- Addressing modes determine how operands are specified (immediate, direct, register, etc.), affecting instruction length and execution time.
- Pipelining overlaps instruction fetch, decode, execute, and write-back stages to improve CPU throughput (e.g., 4-segment pipeline in 8085).
- Real-world use: Assembly is critical in embedded systems (e.g., NTC’s smart meters), bootloaders (e.g., BIOS), and performance-critical apps (e.g., Pathao’s ride-matching algorithms).
- Exam focus: Trace instruction execution (e.g.,
MVI A,32H), compare instruction formats, and explain pipelining stages with timing diagrams.
1. Instruction Formats in 8085
The 8085 microprocessor uses three primary instruction formats to encode operations, operands, and addresses. Each format determines the length of the instruction (1-byte, 2-byte, or 3-byte) and how operands are specified.
1.1 Types of Instruction Formats
classDiagram
class InstructionFormat {
+name: String
+length: Int
+fields: String[]
}
class OneByteFormat {
+opcode: 8 bits
}
class TwoByteFormat {
+opcode: 8 bits
+operand: 8 bits
}
class ThreeByteFormat {
+opcode: 8 bits
+address: 16 bits
}
InstructionFormat <|-- OneByteFormat
InstructionFormat <|-- TwoByteFormat
InstructionFormat <|-- ThreeByteFormat| Format | Example Instruction | Binary Representation | Use Case |
|---|---|---|---|
| 1-byte | NOP |
00000000 (00h) |
No operation (idle cycle). |
MOV A,B |
11000010 (78h) |
Register-to-register transfer. | |
| 2-byte | MVI A,32H |
00110110 00110010 (3Eh 32h) |
Move immediate data to register. |
LXI H,2000H |
00000110 00100000 00000000 (26h 20h 00h) |
Load 16-bit address into HL register pair. | |
| 3-byte | STA 3000H |
00111010 00110000 00000000 (32h 30h 00h) |
Store accumulator to memory location. |
1.2 How Instructions Are Encoded
- Opcode: The first byte (or part of it) specifies the operation (e.g.,
MOV,ADD,JMP). - Operand: Additional bytes specify data, addresses, or registers.
- Immediate data: Directly embedded in the instruction (e.g.,
MVI A,32Hloads32HintoA). - Memory address: 16-bit address for memory operations (e.g.,
STA 3000HstoresAto3000H). - Register: 3-bit code for registers (e.g.,
B=000,C=001).
- Immediate data: Directly embedded in the instruction (e.g.,
2. Assembly Language Programming
Assembly language is a low-level programming language where each instruction corresponds to a machine code opcode. It uses mnemonics (e.g., MOV, JMP) and symbolic addresses (e.g., START, LOOP) for readability.
2.1 Mnemonics and Operands
- Mnemonic: Shortcode for an operation (e.g.,
ADDfor addition). - Operand: Specifies the source/destination (register, memory, or immediate value).
- Example:
ADD B(add registerBtoA). - Example:
ADD M(add memory location pointed to byHLtoA).
- Example:
2.2 Example: Adding Two Numbers
Problem: Add two numbers stored in memory locations 3000H and 3001H, store the result in 3002H.
Solution:
LXI H,3000H ; Load HL with address 3000H
MOV A,M ; Load A with data at [HL] (first number)
INX H ; Increment HL to point to 3001H
ADD M ; Add data at [HL] (second number) to A
STA 3002H ; Store result in 3002H
HLT ; Halt the processor
Binary Execution Trace:
| Instruction | Opcode (Hex) | Operation |
|---|---|---|
LXI H,3000H |
21h 30h 00h | Load HL with 3000H. |
MOV A,M |
7Eh | Move [HL] to A. |
INX H |
23h | Increment HL (now points to 3001H). |
ADD M |
86h | Add [HL] to A. |
STA 3002H |
32h 30h 02h | Store A to 3002H. |
3. Addressing Modes in 8085
Addressing modes define how the operand is specified in an instruction. The 8085 supports 6 primary addressing modes:
mindmap
root((Addressing Modes in 8085))
Immediate
Register
Direct
Register Indirect
Implied
Jump/Calls| Mode | Example | Description | Instruction Length |
|---|---|---|---|
| Immediate | MVI A,32H |
Operand is part of the instruction (e.g., 32H). |
2-byte |
| Register | MOV A,B |
Operand is a register (e.g., B, C). |
1-byte |
| Direct | STA 3000H |
Operand is a 16-bit memory address (e.g., 3000H). |
3-byte |
| Register Indirect | ADD M |
Operand is memory location pointed to by HL (or BC, DE). |
1-byte |
| Implied | DAA |
Operand is implied (e.g., A for DAA, HL for INX H). |
1-byte |
| Jump/Calls | JMP 2000H |
Operand is a 16-bit address for branching. | 3-byte |
Real-World Example:
- NTC Smart Meters: Use direct addressing to read energy consumption data from specific memory locations in the meter’s microcontroller.
- Pathao Ride Matching: Uses register indirect addressing to dynamically access driver/ride data stored in arrays (e.g.,
HLpoints to the next available ride request).
4. Instruction Pipeline in 8085
Pipelining is a technique to overlap instruction execution to improve throughput. The 8085 uses a 4-segment pipeline:
stateDiagram-v2
[*] --> Fetch: Opcode Fetch
Fetch --> Decode: Instruction Decode
Decode --> Execute: Execute ALU/Control
Execute --> Writeback: Write Result
Writeback --> [*]4.1 Pipeline Stages
| Stage | Action |
|---|---|
| Fetch (T1-T2) | Fetch opcode from memory using PC (Program Counter). |
| Decode (T3) | Decode opcode to determine operation and fetch operands if needed. |
| Execute (T4) | Perform ALU operation or control action (e.g., memory read/write). |
| Writeback (T5) | Write result to destination (register/memory). |
Example: Execute ADD B (opcode 80h).
- T1-T2: Fetch
80hfrom memory. - T3: Decode
80h→ADD B(addBtoA). - T4: Execute
A = A + Bin ALU. - T5: Write result back to
A.
Advantages of Pipelining:
- Higher throughput: Multiple instructions in different stages at once.
- Reduced idle time: Overlaps fetch/decode/execute/writeback.
Disadvantages:
- Pipeline hazards: Stalls if data is not ready (e.g.,
ADDwaiting forMOVto complete). - Complex control logic: Requires careful timing and synchronization.
5. RISC vs. CISC: Instruction Format Comparison
While 8085 is a CISC (Complex Instruction Set Computer), modern CPUs like ARM (RISC) differ in instruction design.
| Feature | CISC (8085) | RISC (ARM) |
|---|---|---|
| Instruction Length | Variable (1-3 bytes) | Fixed (e.g., 32-bit ARM instructions). |
| Addressing Modes | Many (6 modes) | Few (e.g., register, immediate). |
| Complex Instructions | Single instruction for complex tasks (e.g., MUL). |
Simple instructions; complex tasks require multiple steps. |
| Pipeline Depth | Shallow (4 stages) | Deep (e.g., ARM Cortex has 15+ stages). |
| Hardware Complexity | High (microprogrammed control unit). | Low (hardwired control). |
| Example Use Case | Legacy embedded systems (e.g., calculators). | Smartphones (e.g., Snapdragon in Pathao’s app). |
Real-World Tie-In:
- Khalti Payments: Uses RISC-based ARM processors in payment terminals for faster transaction processing (fixed-length instructions reduce decoding time).
- Nepal Rastra Bank’s Core Banking: Relies on CISC architectures for legacy system compatibility (e.g., complex financial calculations in a single instruction).
6. Worked Example: Tracing MVI A,32H Execution
Instruction: MVI A,32H (Move Immediate to Accumulator).
Binary: 3Eh 32h (2-byte format).
Step-by-Step Execution:
Fetch Opcode (T1-T2):
PCholds3000H(assume instruction starts here).- Fetch
3Eh(opcode forMVI) from3000H. - Increment
PCto3001H.
Fetch Operand (T3-T4):
- Fetch
32h(immediate data) from3001H. - Increment
PCto3002H.
- Fetch
Execute (T5-T6):
- Decode
MVI A,32h→ Load32hintoA. - Update
Aregister to32h.
- Decode
Writeback (T7):
- No explicit writeback (result is in
A).
- No explicit writeback (result is in
Timing Diagram:
Real-World Link:
- Ncell’s USSD Menu System: Uses
MVIinstructions to load menu options into registers for quick display (e.g.,MVI A,01Hto show "Balance Inquiry").
In the Real World
eSewa’s Payment Processing:
- Uses assembly-level optimizations (e.g.,
MVIfor loading transaction IDs) in embedded systems to minimize latency during payment verification. - Why? Immediate addressing (
MVI) is faster than memory access for critical data like transaction amounts.
- Uses assembly-level optimizations (e.g.,
Pathao’s Ride-Matching Algorithm:
- Employs register indirect addressing (
ADD M,MOV M,A) to dynamically update driver/ride statuses in real-time. - Example:
LXI H,2000Hloads the address of the next ride request, thenMOV A,Mfetches the request ID.
- Employs register indirect addressing (
NTC’s Smart Grid Monitoring:
- Pipelining is used in microcontrollers to overlap:
- Fetching sensor data (e.g., voltage readings).
- Decoding commands (e.g.,
ADDfor totalizing consumption). - Writing results to memory for billing.
- Result: Faster response times for grid adjustments.
- Pipelining is used in microcontrollers to overlap:
Exam Tip
Instruction Execution Questions:
- Always trace T-states (e.g.,
MVI A,32Htakes 7 T-states: 2 for opcode fetch, 2 for operand fetch, 3 for execution). - Draw timing diagrams for multi-cycle instructions (e.g.,
STA 3000H).
- Always trace T-states (e.g.,
Assembly Programming:
- For data manipulation (e.g., adding two tables), use:
LXI H,start_addressto load the base address.MOV A,M/ADD Mfor element-wise operations.INX Hto move to the next element.
- Example: Adding two 10-byte arrays at
3000Hand3010H, storing results at3020H:LXI H,3000H ; Point to first array LXI D,3010H ; DE = second array LXI B,3020H ; BC = result array MVI C,0Ah ; Counter = 10 LOOP: MOV A,M ; Load from first array ADD M ; Add corresponding element from second array STAX B ; Store result INX H ; Move to next element in first array INX D ; Move to next in second array INX H ; BC already points to result DCR C ; Decrement counter JNZ LOOP ; Repeat until C=0
- For data manipulation (e.g., adding two tables), use:
Pipelining:
- Explain stalls (e.g., data hazard if
ADD BfollowsMOV B,Cwithout a wait state). - Compare 8085’s 4-stage pipeline with modern RISC pipelines (e.g., ARM’s 15+ stages).
- Explain stalls (e.g., data hazard if
Addressing Modes:
- Direct vs. Indirect: Direct (
STA 3000H) is slower (3-byte) than indirect (STAX BforBC-indirect). - Immediate vs. Register:
MVI A,32H(2-byte) is faster thanMOV A,B(1-byte) ifBisn’t preloaded.
- Direct vs. Indirect: Direct (
Common Pitfalls:
- Forgetting to increment
PCafter multi-byte instructions (e.g.,LXI H,2000Hskips 2 bytes). - Misusing
HLin indirect addressing (e.g.,ADD MusesHL, notBCorDE). - Overlooking carry flags in arithmetic operations (e.g.,
DAAafterADD).
- Forgetting to increment
Based on the TU BCA syllabus for Microprocessor and Computer Architecture (CACS155), unit 9.
Discussion
Loading…