Programming the Basic Computer & 8085/8086
8085 and 8086 architecture overview, Basic computer registers, Machine vs Assembly language, One-pass and Two-pass Assemblers
- Understand 8085 and 8086 microprocessor internal architecture
- Trace instruction code formats and basic computer registers (AR, PC, DR, AC, IR)
- Explain One-Pass and Two-Pass assembler mechanics and symbol table generation
- Write and trace basic assembly-language loops and subroutine calls
π― Weightage: 3.4% β Smallest weightage chapter, but a reliable source of easy, direct-recall marks.
1 8085 & 8086 Basics
1.1 8085 Functional Block Diagram & Units
1 ββββββββββββββββββββββββββββββββββββββββββββββββ2 β 8085 CPU β3 β β4 β ββββββββββ βββββββββββββββ ββββββββββββββ β5 β β ALU ββββΊβ Accumulator β β Registers β β6 β β(Arith/ β β (A) β β B,C,D,E,H,L β β7 β β Logic) β βββββββββββββββ ββββββββββββββ β8 β ββββββββββ β9 β ββββββββββββββ ββββββββββββββ βββββββββββββββ10 β β Flag Reg. β β SP β β PC ββ11 β β(S,Z,AC,P,CY)β β(Stack Ptr) β β(Prog.Counter)ββ12 β ββββββββββββββ ββββββββββββββ βββββββββββββββ13 β βββββββββββββββββββββββββββββββββββββββββββββ β14 β β Control Unit (Timing & Control) β β15 β βββββββββββββββββββββββββββββββββββββββββββββ β16 βββββββββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ17 βΌ βΌ18 Address Bus (16-bit) Data Bus (8-bit)| Unit | Function |
|---|---|
| π΅ ALU | Performs arithmetic (add, subtract) & logical (AND, OR, XOR) operations |
| π’ Accumulator (A) | 8-bit register; primary register for ALU operations (implicit operand + result destination) |
| π‘ General Purpose Registers | B, C, D, E, H, L (8-bit each); can be paired as BC, DE, HL for 16-bit operations |
| π Flag Register | Holds condition flags: Sign, Zero, Auxiliary Carry, Parity, CarrY |
| π΄ Program Counter (PC) | 16-bit; holds the address of the NEXT instruction to fetch |
| π£ Stack Pointer (SP) | 16-bit; points to the top of the stack in memory |
| β« Control Unit | Generates timing & control signals to coordinate instruction fetch/decode/execute |
| βͺ Address Bus | 16-bit, unidirectional β allows addressing 2ΒΉβΆ = 64 KB of memory |
| π€ Data Bus | 8-bit, bidirectional β transfers data to/from memory/I/O |
1.2 8085 ISA & Addressing Modes Overview
- 8085 is an 8-bit microprocessor with a 16-bit address bus.
- Addressing modes supported: Immediate, Register, Direct, Register Indirect, Implied β mirroring the general addressing-mode concepts covered in Chapter 9.5.
- Instruction categories: Data transfer (MOV, MVI, LXI), Arithmetic (ADD, SUB, INR, DCR), Logical (ANA, ORA, XRA, CMA), Branching (JMP, CALL, RET), Machine control (HLT, NOP).
1.3 8086 Architecture Introduction
The 8086 is a 16-bit microprocessor, architecturally divided into two independent, concurrently operating units:
1βββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ2β Bus Interface Unit (BIU) β β Execution Unit (EU) β3β - Fetches instructions ββββββββΊβ - Decodes & executes β4β from memory (prefetch) β Queue β instructions β5β - Handles address β β - Contains ALU, general β6β calculation (segment:offset)β β registers, flag register β7β - Manages segment registers β β - Requests operands from BIU β8βββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ- BIU (Bus Interface Unit): Responsible for fetching instructions/data from memory (using a 6-byte prefetch instruction queue) and computing physical addresses via segment:offset addressing.
- EU (Execution Unit): Decodes and executes instructions, performs ALU operations, and requests the BIU to fetch/write data as needed.
- This BIU + EU split enables a simple form of pipelining: while EU executes one instruction, BIU can simultaneously fetch the NEXT instruction(s) into the queue.
1.4 Key Differences: 8085 vs 8086
| Feature | π¦ 8085 | π§ 8086 |
|---|---|---|
| Data bus width | 8-bit | 16-bit |
| Address bus width | 16-bit | 20-bit |
| Addressable memory | 2ΒΉβΆ = 64 KB | 2Β²β° = 1 MB |
| Internal architecture | Single unit (no BIU/EU split) | Two units: BIU + EU |
| Pipelining | None (strictly sequential fetch-execute) | Basic pipelining via instruction prefetch queue |
| Registers | 8-bit registers (pairable for 16-bit ops) | 16-bit registers natively |
| Addressing | Direct 16-bit addressing | Segment:Offset based addressing (segmented memory model) |
| Instruction set | Simpler, smaller | Larger, more complex (superset-like extensions) |
Solved/Conceptual Questions
Q1. How much memory can the 8085 microprocessor address directly?
Solution
: 16-bit address bus β 2ΒΉβΆ = 64 KB
Q2. How much memory can the 8086 microprocessor address directly?
Solution
: 20-bit address bus β 2Β²β° = 1 MB
Q3. Which unit in the 8086 is responsible for computing the physical address using segment and offset registers?
Solution
: BIU (Bus Interface Unit)
### β οΈ Common Traps & Exam Tips - π 8085 has a 16-bit address bus but only an 8-bit data bus β don't confuse the two widths; this asymmetry is frequently tested. - π The 8086's BIU+EU split is what enables its basic pipelining/prefetching β a key differentiator from the purely sequential 8085; remember this connects conceptually to Chapter 9.4 (Pipelining). - π 8086 addresses memory using Segment:Offset (physical address = SegmentΓ16 + Offset), giving it a 20-bit effective address space from 16-bit segment/offset registers β a commonly tested address-computation nuance.
2 Computer Instruction
2.1 Instruction Code Format (Opcode + Address)
1ββββββββββββββββ¬βββββββββββββββββββββββββ2β Opcode β Address (Operand) β3ββββββββββββββββ΄βββββββββββββββββββββββββ- Opcode: Specifies WHAT operation to perform.
- Address: Specifies WHERE the operand is located (memory address, register, or device).
2.2 Operation Code (Opcode) Design
- Opcode bit-width determines the maximum number of distinct operations supported:
mbits β up to 2^m distinct instructions. - In the classic Basic Computer model (Mano's design): 3-bit opcode + 1 indirect (I) bit + 12-bit address field = 16-bit instruction word.
2.3 Addressing of Operand (Direct/Indirect Basic Computer Context)
1βββββ¬βββββββββββ¬βββββββββββββββββββββ2β I β Opcode β Address (12-bit) β3βββββ΄βββββββββββ΄βββββββββββββββββββββ- I = 0 (Direct): The 12-bit address field directly gives the operand's memory address.
- I = 1 (Indirect): The 12-bit address field points to a memory location that HOLDS the actual operand's address (one extra dereference) β directly reusing the Indirect Addressing Mode concept from Chapter 9.5.
2.4 Computer Registers Overview (Basic Computer Model)
| Register | Full Form | Size | Purpose |
|---|---|---|---|
| π΅ AR | Address Register | 12-bit | Holds the memory address for the current operation |
| π’ PC | Program Counter | 12-bit | Holds address of the NEXT instruction to be fetched |
| π‘ DR | Data Register | 16-bit | Holds the operand read from/to be written to memory |
| π AC | Accumulator | 16-bit | General-purpose register for arithmetic/logic results |
| π΄ IR | Instruction Register | 16-bit | Holds the currently fetched instruction (opcode + address) |
| π£ TR | Temporary Register | 16-bit | Holds temporary/intermediate data during micro-operations |
| β« OUTR | Output Register | 8-bit | Holds data to be sent to an output device |
| βͺ INPR | Input Register | 8-bit | Holds data received from an input device |
2.5 Computer Instruction Formats
| Format | Structure | Description | ||
|---|---|---|---|---|
| π΅ Memory-Reference | `I \ | Opcode(3) \ | Address(12)` | Operates on data in memory; uses AR/DR; requires EA computation |
| π’ Register-Reference | `0111 \ | Register-Operation bits(12)` | Operates entirely within CPU registers, opcode = 111 with I=0 | |
| π‘ I/O | `1111 \ | I/O-Operation bits(12)` | Handles device communication, opcode = 111 with I=1 |
(Directly mirrors the instruction categorization introduced in Chapter 9.6, Section 1.)
Solved/Conceptual Questions
Q4. In the Basic Computer model, an instruction word is 16 bits, with a 3-bit opcode, 1 indirect bit, and the rest as address. How many bits are in the address field, and what is the maximum directly addressable memory?
Solution
: Address field = 16 β 3 β 1 = 12 bits β Max directly addressable memory = 2ΒΉΒ² = 4096 (4K) memory locations
Q5. Which register holds the operand fetched from memory before it is used in a computation?
Solution
: DR (Data Register)
Q6. If AC = 0011 and DR = 0101, what is AC after executing AC β AC + DR?
Solution
: AC = 0011 + 0101 = 1000
### β οΈ Common Traps & Exam Tips - π AR holds an ADDRESS; DR holds DATA β the same PC/MAR/MBR-style confusion from Chapter 9.1 resurfaces here with different register names; always map back to "address register vs data register." - π PC holds the NEXT instruction's address, IR holds the CURRENT instruction β this recurring trap appears again in the Basic Computer model too. - π INPR/OUTR are typically 8-bit, while AC/DR/IR/TR are 16-bit in the classic Basic Computer model β a specific width detail often directly tested.
3 Assembly & Assembler Design
3.1 Computer Languages Hierarchy
1 βββββββββββββββββββββββββββ2 β High-Level Language β (e.g., C, Python) β most abstract, human-friendly3 βββββββββββββββββββββββββββ€4 β Assembly Language β (e.g., MOV, ADD) β symbolic, mnemonic-based5 βββββββββββββββββββββββββββ€6 β Machine Language β (e.g., 10110000) β raw binary, directly executable7 βββββββββββββββββββββββββββ3.2 Machine Language Characteristics
- Consists purely of binary digits (0s and 1s) β the ONLY language the CPU can execute directly, with no translation needed.
- Extremely difficult for humans to write/read; highly hardware-specific (not portable across different architectures).
3.3 Assembly Language Syntax & Structure
- Uses mnemonics (symbolic names like
ADD,MOV,JMP) instead of raw binary opcodes, and symbolic labels for memory addresses instead of raw numeric addresses. - General syntax:
[Label:] Mnemonic Operand(s) [; Comment]
Example Assembly Program β Sum of two numbers:
1 ORG 100 ; Start program at address 1002 LDA A ; Load value at address A into AC3 ADD B ; AC = AC + value at address B4 STA RESULT ; Store AC into RESULT5 HLT ; Halt the program6A, DEC 5 ; Data: A = 57B, DEC 3 ; Data: B = 38RESULT, DEC 0 ; Reserved location for the sum9 END ; End of program3.4 Assembler Definition & Function
- An Assembler is a translator program that converts Assembly Language source code into Machine Language (binary) object code.
- Core functions: translating mnemonics β opcodes, resolving symbolic labels β actual numeric addresses, and handling pseudo-instructions/directives (e.g.,
ORG,END,DEC) that guide the assembly process but don't generate machine code directly.
3.5 Types of Assemblers: One-Pass vs Two-Pass
β One-Pass Assembler
- Scans the source code only ONCE.
- Attempts to translate instructions immediately; if a label is used BEFORE it's defined (a forward reference), the assembler must use a "backpatching" technique β leaving the address blank initially and fixing it later once the label's definition is found.
β Two-Pass Assembler
- Pass 1: Scans the ENTIRE source code to build a complete Symbol Table (mapping every label to its address) β no code generation happens yet.
- Pass 2: Scans the source code AGAIN, this time generating the actual machine code, using the completed Symbol Table from Pass 1 to resolve ALL label references correctly (including forward references) without needing backpatching.
1 ONE-PASS TWO-PASS2 βββββββββββββββββββββββ βββββββββββββββββββββββ3 β Single scan: β β Pass 1: Build Symbol β4 β Translate + patch β β Table only β5 β forward refs later β βββββββββββββββββββββββ€6 βββββββββββββββββββββββ β Pass 2: Generate code β7 β using completed table β8 βββββββββββββββββββββββComparison: One-Pass vs Two-Pass Assembler
| Feature | π¦ One-Pass Assembler | π§ Two-Pass Assembler |
|---|---|---|
| Number of source scans | 1 | 2 |
| Forward reference handling | Backpatching (fix-up after first pass) | Naturally resolved (symbol table built first) |
| Speed | Faster (single scan) | Slower (two full scans) |
| Memory usage | Lower | Higher (needs to store data across passes, or re-read source) |
| Complexity | Simpler in concept, but backpatching logic adds complexity | Conceptually cleaner; symbol resolution is straightforward |
| Symbol Table completeness | Built incrementally during the single pass | FULLY built after Pass 1, before any code generation |
### β οΈ Common Traps & Exam Tips - π Forward reference = using a label BEFORE its definition appears in the source β the defining challenge that distinguishes one-pass (needs backpatching) from two-pass (naturally handled) assemblers. - π In a Two-Pass assembler, NO machine code is generated during Pass 1 β it is PURELY for symbol table construction; a common exam trap is assuming partial code generation happens in Pass 1. - π Assembly language is NOT portable across different CPU architectures (unlike high-level languages) β since mnemonics map directly to a SPECIFIC processor's instruction set.
4 Program Control & I/O Handling
4.1 Program Loops Structure & Control
- A loop repeatedly executes a block of instructions until a termination condition is met, typically controlled via a counter or a conditional branch instruction.
Example: Loop to add 5 numbers stored in consecutive memory locations
1 ORG 1002 LDA COUNT ; Load loop counter (5) into AC3 STA CTR ; Store counter value4 LDA SUM ; Initialize SUM = 05 STA RESULT6 LDA PTR ; Load starting address pointer7LOOP, ... ; (Indirect load using pointer β conceptual)8 ADD RESULT ; Add current value to running result (conceptual)9 STA RESULT10 ISZ CTR ; Increment CTR; Skip next instruction if CTR becomes 011 BUN LOOP ; Branch Unconditionally back to LOOP (if not skipped)12 HLT ; Halt when loop completes13COUNT, DEC 514CTR, DEC 015SUM, DEC 016RESULT, DEC 017 ENDπ’ ISZ (Increment and Skip if Zero) is the classic Basic-Computer loop-control instruction β it increments a memory location, and SKIPS the next instruction if the result becomes zero, commonly used to implement a "branch back unless counter is done" pattern.
4.2 Subroutines Call/Return Mechanism & Stack Usage
- A subroutine is a reusable block of code that can be "called" from multiple points in a program, and RETURNS control back to the calling point once finished.
- Mechanism:
CALLinstruction: saves the RETURN ADDRESS (typically the current PC value) onto the stack, then jumps (branches) to the subroutine's starting address.- Subroutine executes its instructions.
RET(Return) instruction: pops the saved return address off the stack, and loads it back into PC β resuming execution right after the original CALL.
1 ORG 1002 CALL ADDSUB ; Call subroutine ADDSUB β return address pushed onto stack3 HLT ; Execution resumes here after RET4
5ADDSUB, LDA A ; --- Subroutine start ---6 ADD B7 STA RESULT8 RET ; Return β pop return address from stack back into PC4.3 Input/Output Programming Basics
- I/O Instructions (Basic Computer model examples):
INP(Input): Transfers character from INPR (Input Register) into AC.OUT(Output): Transfers character from AC into OUTR (Output Register).SKI(Skip on Input flag): Skips the next instruction if the input device has data ready (input flag = 1).SKO(Skip on Output flag): Skips the next instruction if the output device is ready to accept data (output flag = 1).
4.4 Handling INPR/OUTR Flags
- Input Flag (FGI): Set to 1 when an input device has NEW data ready in INPR (waiting to be read by CPU); cleared to 0 once the CPU reads it via
INP. - Output Flag (FGO): Set to 1 when the output device is READY to accept new data; cleared to 0 once the CPU writes new data via
OUT(until the device finishes processing and sets it back to 1). - This flag-based mechanism is essentially the Basic Computer's implementation of Programmed I/O (recall Chapter 9.3) β the CPU polls FGI/FGO using SKI/SKO in a loop before performing INP/OUT.
Example: Polling loop to input a character
1LOOP, SKI ; Skip next instruction if FGI = 1 (input ready)2 BUN LOOP ; If not ready, branch back and keep polling3 INP ; Input ready β transfer INPR into ACSolved/Conceptual Questions
Q7. Which instruction is used in the Basic Computer model to implement a loop counter that automatically terminates when it reaches zero?
Solution
: ISZ (Increment and Skip if Zero)
Q8. During a CALL instruction, what value is pushed onto the stack?
Solution
: The return address (the address of the instruction immediately following the CALL, i.e., the current PC value at the time of the call)
Q9. In the Basic Computer I/O model, which flag must be checked before executing an OUT instruction to safely send data to the output device?
Solution
: FGO (Output Flag) β must be 1 (device ready) before writing new data via OUT.
### β οΈ Common Traps & Exam Tips - π ISZ increments FIRST, then checks if the result is ZERO to decide whether to skip β not the other way around; a common sequencing error in loop-tracing questions. - π The return address is pushed BEFORE jumping to the subroutine (during CALL) and popped AFTER the subroutine finishes (during RET) β stack discipline (LIFO) must be respected, especially with NESTED subroutine calls. - π FGI/FGO polling (via SKI/SKO) is functionally IDENTICAL to the busy-waiting/polling loop discussed in Programmed I/O (Chapter 9.3) β recognize this as the SAME underlying technique applied specifically to the Basic Computer's I/O model.
Quick Revision Summary
1βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ2 8085 vs 80863 8085 β 8-bit data bus, 16-bit address bus, 64 KB memory, no pipelining4 8086 β 16-bit data bus, 20-bit address bus, 1 MB memory, BIU+EU (basic pipelining)5
6 BASIC COMPUTER REGISTERS7 AR (address) | PC (next instr.) | DR (data) | AC (accumulator)8 IR (current instr.) | TR (temp) | OUTR (8-bit, output) | INPR (8-bit, input)9
10 INSTRUCTION FORMAT (Basic Computer)11 I(1) + Opcode(3) + Address(12) = 16-bit word12 I=0 β Direct addressing | I=1 β Indirect addressing13
14 ASSEMBLERS15 One-Pass β 1 scan, backpatching for forward references, faster, less memory16 Two-Pass β Pass1: build Symbol Table | Pass2: generate code, no backpatching needed17
18 LOOPS & SUBROUTINES19 ISZ β increments a memory location, skips NEXT instruction if result = 020 CALL β pushes return address onto stack, jumps to subroutine21 RET β pops return address from stack back into PC22
23 I/O FLAGS24 FGI (Input Flag) β 1 = new input data ready in INPR25 FGO (Output Flag) β 1 = output device ready to accept new data26βββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Conceptual Recap
- 8085: 8-bit data/16-bit address, single sequential unit, 64 KB max memory. 8086: 16-bit data/20-bit address (segment:offset), BIU+EU split enabling basic pipelining, 1 MB max memory.
- Basic Computer Instruction: I-bit + 3-bit opcode + 12-bit address; Memory-Reference (opcodeβ 111) vs Register-Reference (111, I=0) vs I/O (111, I=1).
- Registers: AR=address, DR=data, AC=accumulator/results, PC=next instruction, IR=current instruction, TR=temp, INPR/OUTR=8-bit I/O buffers.
- Language Hierarchy: Machine (binary, direct-execute) β Assembly (mnemonics/labels) β High-Level (abstract, portable).
- Assemblers: One-Pass (single scan + backpatching) vs Two-Pass (Symbol Table first, then code generation β no backpatching needed).
- Program Control: ISZ drives classic loop termination; CALL/RET use the stack (LIFO) for subroutine return addresses.
- I/O Handling: FGI/FGO flags + SKI/SKO/INP/OUT instructions implement Programmed I/O (busy-waiting) at the Basic Computer level β directly tying back to Chapter 9.3's I/O organization concepts.
Mastery check
How well can you recall this?
Finished this lesson?