Prerequisites for Microprocessors
Microprocessor programming brings together number systems, digital logic, computer architecture, assembly language, memory addressing, interrupts, stack-based execution, input/output and basic electronics.
The soundest preparation is hands-on familiarity with binary and hexadecimal numbers, Boolean logic, programming, the organization of the CPU and memory, and basic digital electronics.
Core prerequisites
These topics lay the groundwork for the 8086 programming model, registers and pins, memory access with segment:offset, arithmetic and logic instructions, procedures, the stack, interrupts, I/O ports and BIOS/DOS services.
The binary number system
Microprocessors represent data and instructions as binary bit patterns.
Binary arithmetic is the foundation of registers, memory, opcodes, flags and digital logic.
- Converting between decimal and binary.
- Recognizing the powers of two.
- The ranges of 8-bit and 16-bit unsigned values.
Related topics: registers, opcodes, masks, addresses, flags.
The hexadecimal number system
The hexadecimal system is a way of writing binary values compactly.
8086 addresses, machine-code bytes, register values and bit masks are usually written in hexadecimal.
- Converting decimal↔hexadecimal and binary↔hexadecimal.
- One hexadecimal digit corresponds to four bits.
- Reading byte and word values in hexadecimal.
Related topics: addresses, memory dumps, opcodes, debugging.
Signed numbers and two's complement
Processors need a way to encode negative integers in binary.
Two's complement representation lets the same adder hardware serve both signed and unsigned arithmetic.
- The sign bit and the ranges of signed values.
- Finding the two's complement of a negative value.
- Telling carry apart from signed overflow.
Related topics: ADD/SUB, the sign flag (SF), the overflow flag (OF), conditional jumps.
ASCII character codes
Every character read from the keyboard or written to the screen is carried as a one-byte ASCII code.
Writing a number to the screen or reading one from the keyboard requires converting between a digit and its ASCII code. DOS and BIOS services take and return characters as these codes.
- Digits: '0'–'9' = 30h–39h. The value of a digit is found by subtracting 30h from its code.
- Uppercase letters 'A'–'Z' = 41h–5Ah, lowercase letters 'a'–'z' = 61h–7Ah. The difference is 20h, that is, only bit 5.
- Control characters: carriage return (CR) is 0Dh, line feed (LF) is 0Ah. The space is 20h and '$' is 24h.
Related topics: INT 21h character services, routines for reading and printing numbers, strings, DOS strings terminated with '$'.
Units and prefixes
Clock speeds, instruction times and memory sizes are given in units with prefixes.
Computing the running time of a piece of code requires the clock period, and interpreting the width of the address bus requires knowing memory sizes in binary prefixes.
- The period is the reciprocal of the frequency: T = 1/f. With a 5 MHz clock, one clock period is 200 ns.
- Time prefixes: 1 ms = 10⁻³ s, 1 µs = 10⁻⁶ s, 1 ns = 10⁻⁹ s.
- Time = number of clock cycles × clock period.
- Memory uses binary prefixes: 1 KB = 2¹⁰ = 1024 bytes, 1 MB = 2²⁰ bytes. n address lines give 2ⁿ different addresses; 20 lines mean an address space of 1 MB.
Related topics: the clock signal, instruction cycle counts, delay loops, address bus width, the memory map.
Boolean logic
Arithmetic and control circuits are built from Boolean operations.
Logical instructions expose these operations directly to assembly programs.
- Basic truth tables.
- Bit masking.
- Toggling bits with XOR; clearing a register by XORing it with itself.
Related topics: masks, flags, device control, bit fields.
Digital logic basics
A CPU consists of digital circuits that store and transform binary values.
Basic logic concepts make it easier to understand registers, ALUs, buses and control signals.
- The difference between combinational and sequential logic.
- Gates, multiplexers, decoders and flip-flops.
- A register as stored binary state.
Related topics: the ALU, the register file, the instruction decoder, the control unit.
Latches and three-state buffers
When several devices are connected to one bus, these building blocks decide which device drives the bus and when a value is captured.
In processors that put address and data on the same pins one after the other, the address has to be captured in a latch and the data bus has to be isolated with three-state buffers.
- A latch passes its input to its output while the enable input is active; when the enable is removed it holds the last value.
- A three-state output can take the high-impedance (Z) state in addition to 0 and 1. In this state the device is as if disconnected from the bus.
- Only one device should drive a bus at a time. Two outputs driving the bus at the same time is bus contention.
- An active-low signal is active when it is 0; it is shown with a ' at the end of its name or with a bar over it.
Related topics: ALE and address latches, data transceivers, the RD' and WR' signals, memory banks.
Basic programming
Assembly is easier to learn once you are used to the control flow of algorithms.
High-level programming concepts correspond to low-level instruction sequences.
- Assignment and arithmetic expressions.
- Tracing if/else structures and loops step by step.
- Arrays and functions.
Related topics: CMP/Jcc, loops, variables in memory, procedures.
C programming concepts
C is a useful bridge between high-level code and assembly.
Many processor concepts become clearer when they are related to variables, pointers, function calls and data sizes in C.
- Integer types and arrays.
- Basic pointer and address concepts.
- Function calls and local variables at a conceptual level.
Related topics: stack frames, calling conventions, data representation.
Bitwise operations
Working with bits is the foundation of low-level programming.
The 8086 has dedicated logic, shift and rotate instructions for bit-level control.
- Building and applying masks.
- Testing individual bits.
- The conceptual difference between logical and arithmetic shifts.
Related topics: SHL/SHR, ROL/ROR, device registers, flags.
Computer architecture basics
Microprocessor programming depends on knowing how the CPU exchanges data with memory and I/O.
Registers, buses, memory and control signals form the execution environment that assembly code sees.
- The basic roles of the CPU, memory and input/output (I/O).
- Address, data and control buses at a conceptual level.
- The fetch–decode–execute cycle.
Related topics: the 8086 bus interface, memory access, instruction execution.
Registers
The 8086 exposes a small set of named registers directly to programs.
Assembly instructions mostly work on the AX, BX, CX and DX registers and on the segment, index and pointer registers.
- Registers are small, fast storage areas inside the CPU.
- The distinction between general-purpose and special-purpose roles.
- 16-bit registers and, where available, 8-bit high/low halves.
Related topics: AX/AH/AL, BX, CX, DX, SP, BP, SI, DI, CS, DS, SS, ES.
Memory addressing
Assembly code reads and writes memory locations whose addresses it specifies explicitly.
Knowing how memory is organized is indispensable for variables, arrays, pointers and instructions.
- Byte-addressable memory.
- Little-endian representation at a conceptual level.
- Recognizing the effective address.
Related topics: data variables, arrays, pointers, instruction operands.
Segmentation on the 8086
The 8086 forms 20-bit physical addresses from 16-bit segment and offset values.
Segmentation explains how the original 8086, whose registers are 16 bits wide, could address up to 1 MB of memory.
- Physical address = segment × 16 + offset.
- Overlapping segments.
- The roles of the CS, DS, SS and ES registers.
Related topics: code, data, stack and extra segments, 20-bit addressing.
Arithmetic and flags
Arithmetic instructions update both the value in the destination and the processor's status flags.
Flags are used in comparisons, signed/unsigned decisions, loops and error detection.
- The carry, zero, sign and overflow flags at a conceptual level.
- CMP updates only the flags, without storing the result of the subtraction.
- The relation between flags and conditional jumps.
Related topics: ADD, SUB, CMP, Jcc, signed and unsigned comparisons.
Control flow in assembly
Assembly expresses decisions and repetition through labels and branch instructions.
High-level control structures turn into comparisons and jumps when compiled.
- Tracing conditional and unconditional jumps step by step.
- Labels as branch targets.
- Translating simple if/while logic into low-level steps.
Related topics: JMP, JE/JZ, JNE/JNZ, signed/unsigned conditional jumps.
Stack fundamentals
The stack is used for temporary storage, procedures, return addresses and interrupts.
Disciplined use of the stack is essential for procedure calls and interrupt handling to work correctly.
- LIFO (last in, first out) order.
- PUSH and POP at a conceptual level.
- The SP and SS registers that hold the state of the stack on the 8086.
Related topics: procedures, return addresses, parameters, interrupts.
Procedures and calls
Procedures divide assembly programs into reusable blocks.
CALL and RET rely on the stack to preserve the return information.
- CALL pushes the return address onto the stack.
- RET returns to the calling code.
- Passing parameters in registers and on the stack at a conceptual level.
Related topics: modularity, the stack, calling conventions.
Interrupts
Interrupts transfer control to a service routine in response to hardware or software events.
BIOS/DOS services, timers, keyboards and interaction with devices all rely on interrupts.
- The distinction between hardware and software interrupts.
- The idea of an interrupt vector.
- The need to save and restore the processor state.
Related topics: the INT instruction, the interrupt vector table (IVT), the interrupt service routine (ISR), BIOS/DOS services.
Input/output
Microprocessors communicate with peripherals through explicit I/O mechanisms.
Port-mapped and memory-mapped I/O connect the instructions in software to hardware devices.
- Device registers at a conceptual level.
- The purpose of the IN and OUT instructions on x86.
- Polling and interrupt-driven I/O.
Related topics: ports, peripherals, keyboards, displays, controllers.
Basic electronics
Microprocessors are not only abstract instruction machines but also digital systems that run on electricity.
Basic signal and timing concepts help explain the clock signal, buses, pins and interfacing.
- Binary voltage levels at a conceptual level.
- Clock signals.
- Input/output direction and signal timing.
Related topics: the clock, reset (RESET), bus timing, digital interfaces.
Assembly tools
Low-level programming requires a toolchain that turns symbolic assembly code into executable machine code.
Knowing the stages of the toolchain makes it easier to trace the source of syntax, symbol and runtime errors.
- The roles of the assembler and the linker.
- Reading a simple memory/register dump.
- Single-stepping and breakpoints at a conceptual level.
Related topics: a MASM/TASM/NASM-style workflow, the linker, the debugger.
Machine code basics
Assembly instructions are the symbolic representation of encoded machine instructions.
Instruction encoding explains why operands, addressing modes and instruction sizes matter.
- The difference between an opcode and an operand.
- Instructions occupy bytes in memory.
- The addressing mode affects the encoding.
Related topics: machine code, disassembly, instruction size.
Bus and timing basics
The processor communicates with the outside world through address, data and control signals that work together.
Bus timing explains how memory and peripherals know when to read, write or respond.
- The distinction between address information and data information.
- Read/write control signals at a conceptual level.
- Wait states and timing in broad terms.
Related topics: memory cycles, I/O cycles, control pins, interfacing.