Microprocessor51 Notes
Microprocessor51 Notes
This document covers all key topics including 8086 architecture, pipelining, operating modes, flags, addressing
modes, instruction sets, interrupts, DMA, peripheral ICs (8255 / 8254 / 8251 / 8279), and the 8051 microcontroller
— memory map, PSW, timers, interrupts, and interfacing.
Section Topics
5. Peripheral ICs 8255 PPI, 8254 PIT, 8251 USART, 8279 Keyboard/Display
BIU Bus Interface Unit Handles all bus operations: fetches instructions from memory into a 6-byte
queue, generates 20-bit physical addresses, and manages data transfers
between CPU and memory/IO.
EU Execution Unit Decodes and executes instructions fetched by the BIU. Contains the ALU,
general-purpose registers, flag register, and the instruction decoder.
BIU Components:
• Instruction Queue: 6-byte FIFO queue that prefetches instructions (pipelining)
• Segment Registers: CS, DS, SS, ES — each 16-bit, used for memory segmentation
• IP (Instruction Pointer): 16-bit register pointing to the next instruction
• Address Adder: Computes physical address = Segment × 16 + Offset
EU Components:
• General Purpose Registers: AX, BX, CX, DX (each 16-bit, split into high/low 8-bit halves)
• Index Registers: SI (Source Index), DI (Destination Index)
• Pointer Registers: SP (Stack Pointer), BP (Base Pointer)
• ALU: Performs arithmetic (ADD, SUB, MUL, DIV) and logical (AND, OR, XOR) operations
• Flag Register: 16-bit register; 9 bits used for status and control flags
Stage 1: Fetch BIU Fetches instruction bytes from memory and stores them in the 6-byte instruction
queue.
Stage 2: Execute EU Reads instruction from the queue, decodes it, and executes it using the ALU.
Queue Behaviour:
• BIU fetches bytes into the queue whenever the queue has 2 or more empty bytes.
• If a branch/jump instruction is executed, the queue is flushed and refilled from the new address.
• The queue is empty only during a branch; in sequential code it is nearly always full.
Benefit: Bus idle time is minimised; the CPU does not stall waiting for instruction bytes in normal sequential programs,
increasing execution speed by up to 50%.
Q3. Explain the Difference Between Minimum Mode and Maximum Mode
The 8086 has a pin called MN/MX# (pin 33) that selects the operating mode:
Control Signals 8086 itself generates all bus control signals (RD#, Bus control signals generated by external 8288
WR#, IO/M#, DT/R#, DEN#, ALE, INTA#) Bus Controller
Pins 24–31 Used for control signals (RD, WR, etc.) Used for status signals (S0, S1, S2, LOCK#, QS0,
QS1, RQ/GT0#, RQ/GT1#)
Bus arbitration Not needed (single master) Required — handled via RQ/GT# pins
Cost / Complexity Lower — fewer ICs needed Higher — needs 8288 and bus arbitration logic
PF Parity Flag 2 Low byte of result has even number of 1-bits Result 03H (00000011) → PF=1
AF Auxiliary Carry 4 Carry from bit 3 to bit 4 (BCD arithmetic) 09H + 01H → AF=1
OF Overflow Flag 11 Signed overflow: result too large/small for 7FFFH + 01H → OF=1
signed 16-bit
DF Direction Flag 10 (Control) SI/DI auto-decrement in string ops STD sets DF; CLD clears DF
when set
IF Interrupt Flag 9 (Control) Maskable interrupts enabled when set STI sets IF; CLI clears IF
TF Trap Flag 8 (Control) Single-step mode; INT 1 after every Used by debuggers
instruction
T-State Activity
T1 ALE (Address Latch Enable) goes HIGH. BIU puts the 20-bit physical address on AD0–AD15 and A16–A19. ALE
goes LOW to latch the address in external latch (e.g., 8282).
T2 Address is removed. AD0–AD15 float (tristated) to become a data bus. RD# goes LOW, indicating a read
operation. Status signals are asserted.
T3 [+ TW] CPU waits for data. Memory or I/O device drives data onto AD0–AD15. If the device is slow, READY is sampled; if
LOW, TW wait states are inserted.
T4 CPU samples (reads) data on the rising edge of T4 clock. RD# returns HIGH. Bus is released.
T-State Activity
T1 ALE goes HIGH. 20-bit address placed on bus. ALE goes LOW to latch address.
T2 WR# goes LOW. CPU places data on AD0–AD15 for the memory/IO device to accept.
T3 [+ TW] Data is held stable on the bus. READY is sampled; TW wait states inserted if needed.
T4 WR# returns HIGH. Data removed from bus. Write cycle complete.
SECTION 3 — Addressing Modes, Instructions & Interrupts
Q6. Explain All Addressing Modes of the 8086 with Examples
Addressing mode specifies how the operand (data) is accessed. The 8086 supports the following modes:
1. Immediate Operand is part of the instruction itself MOV AX, 1234H → AX = 1234H
3. Direct Effective address (EA) is given directly as MOV AX, [2000H] → AX = memory[DS:2000H]
a 16-bit displacement in the instruction
8. Based Indexed with EA = Base + Index + displacement (most MOV AX, [BX+SI+04H] → EA = BX+SI+0004H
Displacement general mode)
9. Implied Operand is implicit in the opcode itself CLC (clear carry — CF implied); XLAT (AL implied)
10. String (Auto) SI/DI auto-incremented or decremented MOVSB copies [DS:SI] to [ES:DI], then SI±1, DI±1
after each string operation depending on
DF
Segment used by default: DS for most data accesses; SS when BP is the base register; CS for code; ES for
string destination. Any segment can be overridden with a segment prefix.
LEA dst, src Load effective address of src into dst LEA BX, [SI+4]
LDS / LES Load pointer: register ← offset, DS/ES ← LDS SI, [BX]
segment
ADC dst, src dst = dst + src + CF (add with carry) ADC AX, BX
SBB dst, src dst = dst − src − CF (subtract with borrow) SBB AX, BX
CMP dst, src Subtract src from dst; update flags only (no store) CMP AX, BX
(C) Logical Instructions
Perform bit-level operations; update ZF, SF, PF; always clear CF and OF.
Instruction Action Example / Use
AND dst, src Bitwise AND; used to CLEAR selected bits AND AL, 0FH → clear upper nibble
(masking)
OR dst, src Bitwise OR; used to SET selected bits OR AL, 80H → set bit 7
XOR dst, src Bitwise XOR; used to TOGGLE bits or zero a XOR AX, AX → AX=0 (fastest)
register
TEST dst, src AND result, update flags only (no store) TEST AL, 01H → check bit 0
SHL/SAL dst, cnt Shift left; MSB → CF, LSB filled with 0 SHL AX, 1 → AX × 2
SHR dst, cnt Shift right logical; MSB filled with 0 SHR AX, 1 → AX ÷ 2 unsigned
SAR dst, cnt Shift right arithmetic; MSB preserved (sign extend) SAR AX, 1 → AX ÷ 2 signed
ROL / ROR Rotate left/right; bits wrap around through CF ROL AL, 1
RCL / RCR Rotate left/right through carry; 9-bit rotation RCL AX, 1
Unconditional Jump JMP target Always jumps. Short (±128 B), Near (±32KB), Far (any
segment)
Conditional Jump JE/JZ, JNE/JNZ, JC, JNC, JG, JL, Jump if condition (flag) is true. Short range only (±127 bytes
JGE, JLE, etc. from next IP)
Loop LOOP label LOOPE label Decrement CX; jump if CX≠0. LOOPE also requires ZF=1.
LOOPNE label LOOPNE requires ZF=0.
Call / Return CALL proc RET [n] Save return address on stack, jump to subroutine. RET pops
IP (near) or CS:IP (far).
Software Interrupt INT n Push flags, CS, IP; jump to interrupt vector n×4 in IVT.
Return from ISR IRET Pop IP, CS, Flags — return from interrupt service routine.
Q8. Explain the Types of Interrupts and How They Work in 8086
An interrupt is a signal that suspends the current program, saves state, and transfers control to an Interrupt
Service Routine (ISR). The 8086 supports up to 256 interrupt types (INT 0–255). Vectors are stored in the
Interrupt Vector Table (IVT) at addresses 00000H–003FFH (4 bytes per vector: IP low, IP high, CS low, CS high).
Hardware NMI Triggered by NMI pin (pin 17). Cannot be disabled by software. Always processed.
(External) (Non-Maskable) Used for memory parity errors, power failure. Maps to INT 2.
INTR (Maskable) Triggered via INTR pin. Only processed when IF=1 (STI). An external PIC (8259A)
sends an 8-bit vector number on the data bus. CPU acknowledges with two INTA#
pulses. Can be disabled with CLI.
Software (Internal) INT n Explicit instruction in code. Saves flags, CS, IP on stack; vectors through IVT[n×4].
INT 21H → DOS services; INT 10H → BIOS video; INT 0 → divide error.
INTO Interrupt on Overflow. Triggers INT 4 if OF=1. Used after signed arithmetic.
Single-Step (Trap) If TF=1, INT 1 is generated after every instruction execution. Used by debuggers
([Link], CodeView) for step-through execution.
Exception INT 0 Divide Error Automatically generated when DIV or IDIV instruction produces quotient too large
(Dedicated) for the destination or when divisor is 0.
Q9. Draw the Block Diagram of DMA Controller and Explain Each Function
A DMA (Direct Memory Access) Controller (e.g., Intel 8257 or 8237) allows peripherals to transfer data to/from
memory without CPU intervention, freeing the CPU for other tasks during large data transfers (disk, audio,
network).
DACK0–DACK3 (DMA Output Acknowledgement to the requesting peripheral. DACKn goes active when the
Acknowledge) 8257 wins the bus and starts transferring for channel n.
HRQ (Hold Request) Output → Asserted by DMA controller to request control of the system bus from the CPU.
CPU HOLD
HLDA (Hold Acknowledge) Input ← CPU CPU grants bus to DMA by asserting HLDA. CPU then tristates its
address/data/control lines.
A0–A3 Input/Output Address lines for register selection during programming by CPU; output lower
address bits during DMA transfer.
A4–A7 Output Higher address bits output during DMA transfer cycles.
DB0–DB7 Bidirectional Data bus for CPU to program internal registers (base address, word count) and
for data transfer.
MEMR# / MEMW# Output Memory read/write control during DMA transfer.
TC (Terminal Count) Output Goes HIGH when programmed word count reaches zero; signals end of block
transfer.
MARK Output Goes HIGH every 128th transfer cycle (used for synchronisation in some
systems).
CS# Input Chip select — enables DMA controller for CPU register access.
Port A (PA0–PA7) 8-bit General I/O; can be input, output, or bidirectional (Mode 2 only). Used for data
transfer.
Port B (PB0–PB7) 8-bit General I/O; input or output. Supports Mode 0 and Mode 1 (strobe I/O).
Port C (PC0–PC7) 8-bit Can be split: PC0–PC3 (lower) and PC4–PC7 (upper). Often used for
handshake/status signals in Mode 1 & 2.
Control Register 8-bit Written to address with A1=1, A0=1. D7=1 → mode set; D7=0 → bit set/reset for
Port C.
Operating Modes:
• Mode 0 (Basic I/O): Simple input or output — no handshaking. Any port can be input or output independently.
Commonly used for LED/switch interfacing.
• Mode 1 (Strobe I/O): Port A and/or Port B used with handshake signals from Port C (OBF#, IBF, STB#,
ACK#). Useful for printer/keyboard interfacing.
• Mode 2 (Bidirectional): Port A only — full bidirectional handshake using 5 Port C signals. Used for
bidirectional bus communication.
Control Word Example: 10011010B (9AH) → Port A: Mode 1 Output, Port B: Mode 0 Input, PC upper: Output, PC lower:
Input.
Counter 0 16-bit System timer / IRQ0 (18.2 Hz real-time clock in IBM PC)
Asynchronous Mode Uses start bit, 5–8 data bits, optional parity bit, 1/1.5/2 stop bits. Standard UART communication
(RS-232).
Synchronous Mode Uses sync characters or external clock (SYNC pin). No start/stop bits — higher throughput. Internal
or external sync detection.
Baud Rate CLK ÷ baud rate factor (×1, ×16, ×64 for async). Maximum ~64K baud at 1MHz CLK.
Transmitter CPU writes byte to Tx buffer. 8251 serialises it, adds framing bits (async) or sync chars, sends on
TxD pin.
Receiver Detects start bit (async) or sync chars (sync), deserialises incoming bits on RxD, removes framing,
stores byte in Rx buffer for CPU.
Status Register Bits: TxRDY (ready for next byte), RxRDY (byte available), TxEMPTY, PE (parity error), OE
(overrun error), FE (framing error), SYNDET/BRKDET.
Control Registers Mode Register (written first): clocking, parity, stop bits. Command Register: TxEnable, RxEnable,
RTS, DTR, error reset, break, HUNT mode.
Handshake Pins CTS# (Clear-To-Send input), DSR# (Data-Set-Ready input), RTS# (Request-To-Send output),
DTR# (Data-Terminal-Ready output).
Q13. What is the Function of 8279 (Programmable Keyboard/Display Interface)?
The Intel 8279 is a dedicated Keyboard and Display controller that automatically scans an external matrix
keyboard and multiplexed LED/7-segment display without constant CPU polling.
Block Function
Keyboard Scanner Automatically scans up to 8×8 = 64-key matrix keyboard. Provides key debouncing and FIFO
buffer for up to 8 keystrokes.
Display Scanner Drives up to 16 seven-segment or LED digit display positions using multiplexed scanning (one
digit ON at a time, cycling fast enough for persistence of vision).
FIFO/Sensor RAM 8-byte FIFO stores key codes when keyboard scanned. IRQ asserted when FIFO is not empty so
CPU is interrupted only when a key is pressed.
Display RAM 16×8-bit RAM stores digit data for display. CPU writes here; 8279 continuously reads and drives
display without further CPU involvement.
SL0–SL3 Scan lines (4 lines → decoded to 8 or 16 select lines) used to select keyboard row or display digit
being scanned.
RL0–RL7 Return lines — sense which column key is pressed in the keyboard matrix.
OUTA0–3 / OUTB0–3 8-bit display data output driving segment drivers (A and B buses independently for dual 4-bit or
combined 8-bit segment data).
IRQ Interrupt request to CPU — asserted when FIFO has at least one valid keycode.
CS#, A0, RD#, WR# Interface to 8086 bus. A0=0: data port. A0=1: command/status register.
Modes Keyboard: Scanned-Keyboard (8×8) or Scanned-Sensor (8×8 sensor matrix). Display: Left entry
or Right entry; 8 or 16 characters.
SECTION 5 — 8051 Microcontroller
Q14. What is the Difference Between Microprocessor and Microcontroller?
Feature Microprocessor (e.g., 8086) Microcontroller (e.g., 8051)
Definition CPU only; requires external RAM, ROM, I/O chips CPU + RAM + ROM + I/O + Timers all on a single
chip
Integration Low — needs many external ICs on PCB High — self-contained; minimal external
components
Speed High — designed for maximum MIPS Moderate — optimised for power and cost, not raw
speed
I/O Requires 8255 or similar ICs 4 × 8-bit I/O ports (P0–P3) on-chip
Interrupts Requires external 8259A PIC 5 interrupt sources on-chip with 2-level priority
Typical Use PC, workstation, server Embedded systems: washing machines, toys,
automotive ECUs, industrial control
00H – 1FH Register Banks 32 bytes 4 banks (RB0–RB3) × 8 registers (R0–R7). Active bank selected
by PSW bits RS0, RS1.
20H – 2FH Bit-Addressable Area 16 bytes 128 individual bits (20H.0 to 2FH.7) addressable using SETB,
CLR, MOV C, bit instructions.
30H – 7FH General Purpose RAM 80 bytes Scratch-pad RAM for data storage, temporary variables, and
stack (stack grows upward).
External Memory:
• External Code (ROM): up to 64 KB via MOVX/MOVC; EA# pin LOW forces all fetches externally.
• External Data (RAM): up to 64 KB accessed via MOVX @DPTR or MOVX @Ri instructions.
CY AC F0 RS1 RS0 OV — P
D6 — AC Auxiliary Carry Set if carry out of bit 3 during ADD. Used for BCD (DA A instruction).
D4 — RS1 Register Bank Select 1 RS1:RS0 = 00 → Bank 0 (00H–07H) RS1:RS0 = 01 → Bank 1 (08H–0FH)
RS1:RS0 = 10 → Bank 2 (10H–17H) RS1:RS0 = 11 → Bank 3 (18H–1FH)
D2 — OV Overflow Flag Set if signed overflow occurs in ADD/SUBB/MUL/DIV. For MUL: set if
result > 255. For DIV: set if divisor = 0.
D0 — P Parity Flag Set if ACC has an ODD number of 1-bits; cleared if even. Hardware-set
each instruction cycle. Used for serial communication parity checking.
Q17. What are the Functions of TMOD and TCON Registers?
The 8051 has two 16-bit timers: Timer 0 (T0) and Timer 1 (T1), each composed of two 8-bit registers (TH0/TL0,
TH1/TL1). They are controlled by two SFRs:
Bit 7/3 — GATE Gate control If GATE=1: timer runs only while INT0#/INT1# is HIGH AND TRx=1
(hardware control). If GATE=0: timer runs when TRx=1 (software control
only).
Bit 6/2 — C/T# Counter/Timer select C/T#=0: timer mode (counts internal clock cycles). C/T#=1: counter mode
(counts pulses on T0/T1 external pins).
Bit 5-4/1-0 — M1,M0 Mode select 00: Mode 0 — 13-bit timer (TH:TL[4:0]). 01: Mode 1 — 16-bit timer
(TH:TL). 10: Mode 2 — 8-bit auto-reload (TH holds reload value → loaded
into TL on overflow). 11: Mode 3 — Split mode (T0 splits into two 8-bit
timers; T1 stops).
D7 — TF1 Timer 1 Overflow Flag Set by hardware when Timer 1 overflows (FFFFh → 0000h in Mode 1).
Cleared when ISR is entered. Can also be polled.
D6 — TR1 Timer 1 Run Set/cleared by software. TR1=1 starts Timer 1; TR1=0 stops it.
D3 — IE1 External Int 1 Edge Flag Set when a falling edge (IT1=1) or LOW level (IT1=0) is detected on INT1# pin.
Cleared when ISR is entered.
D2 — IT1 Int 1 Type IT1=0: INT1# is level-triggered (LOW). IT1=1: INT1# is edge-triggered (falling
edge).
D1 — IE0 External Int 0 Edge Flag Same as IE1 but for INT0# pin.
1 (Highest) External Interrupt 0 (INT0# 0003H EX0 (IE.0) PX0 (IP.0) IE0 (TCON.1)
pin)
2 Timer 0 Overflow (TF0) 000BH ET0 (IE.1) PT0 (IP.1) TF0 (TCON.5)
3 External Interrupt 1 (INT1# 0013H EX1 (IE.2) PX1 (IP.2) IE1 (TCON.3)
pin)
4 Timer 1 Overflow (TF1) 001BH ET1 (IE.3) PT1 (IP.3) TF1 (TCON.7)
5 (Lowest) Serial Port (RI or TI) 0023H ES (IE.4) PS (IP.4) RI/TI cleared by software
Connection:
• 8051 Port P1 bits P1.0–P1.3 → ULN2003A inputs (open-collector Darlington driver)
• ULN2003A outputs → 4 coils of the stepper motor (A, B, C, D)
• External 12V supply powers the motor coils; 8051 provides only logic signals
Step P1.3 (D) P1.2 (C) P1.1 (B) P1.0 (A) Hex Value
1 0 0 0 1 01H
2 0 0 1 0 02H
3 0 1 0 0 04H
4 1 0 0 0 08H
Speed control: Change the DELAY subroutine duration. Reverse direction by using sequence: 08H, 04H, 02H, 01H.
Q20. Explain LCD Interfacing with the 8051
A 16×2 LCD (based on the HD44780 controller) is the most commonly interfaced display with the 8051. It has 16
pins and can be connected in 4-bit or 8-bit mode.
RW (Pin 5) P3.1 (or GND) RW=0: Write to LCD. RW=1: Read from LCD. Tie to GND for write-only.
EN (Pin 6) P3.2 Enable pulse. HIGH→LOW strobe latches data/command into LCD.
Segment dp g f e d c b a
Digit '6' segment analysis: Segments a (top), f (top-left), g (middle), e (bottom-left), d (bottom), c (bottom-right)
are ON. Segment b (top-right) is OFF.
Binary (dp g f e d c b a): 0 1 1 1 1 1 0 1 = 7DH (Common Cathode)
Note: For a common-anode display, invert the codes (CPL A before MOV P1,A) or use the CA column values from the table
above.
End of Notes
8086 Microprocessor & 8051 Microcontroller — Complete Reference