Instruction Sets, Addressing Modes, and Processor Structure

Machine Instruction Principles and Instruction Set Architecture

  • Definition and Operational Role of Machine Instructions:

    • The operational behavior of a processor is fundamentally determined by the instructions it executes, referred to as machine instructions or computer instructions.
    • The complete collection of distinct instructions that a processor can execute is defined as the processor's instruction set.
    • Each instruction must encapsulate all information required by the processor for execution, dictating operations, data sources, destinations, and subsequent sequencing.
  • Constituent Elements of a Machine Instruction:

    • Operation Code (Opcode): Specifies the operation to be performed using a binary code known as the opcode.
    • Source Operand Reference: The operation may involve one or more source operands, which serve as inputs for the operation.
    • Result Operand Reference: The operation may produce a result that needs to be stored in a designated destination.
    • Next Instruction Reference: Informs the processor where to fetch the next instruction after the execution of the current instruction is complete (typically sequential unless a branch or jump occurs).
  • Operand Storage Locations:

    • Source and result operands can reside in four primary areas:
    • Processor Register: The processor contains one or more internal registers. If multiple registers exist, each is assigned a unique name or numerical identifier, and the instruction explicitly references the desired register (e.g., ADD R1, R2, R3\text{ADD R1, R2, R3}, which adds the contents of R2\text{R2} and R3\text{R3} and stores the sum in R1\text{R1}).
    • Main or Virtual Memory: The instruction supplies the memory address of the operand (e.g., LOAD R1, 5000\text{LOAD R1, 5000}, which fetches data from memory address 50005000 into R1\text{R1}).
    • I/O Device: The instruction specifies the I/O module and device. When memory-mapped I/O is employed, the device port is referenced simply as another main or virtual memory address (e.g., IN R1, KeyboardPort\text{IN R1, KeyboardPort}).
    • Immediate Value: The operand value is stored directly in an immediate field within the instruction itself, requiring no memory or register reference (e.g., ADD R1, R2, #5\text{ADD R1, R2, \#5}, which adds the literal value 55 to R2\text{R2} and stores the result in R1\text{R1}).
  • Instruction Representation and Fields:

    • Within the computer, each instruction is represented physically as a sequence of bits.
    • The instruction is partitioned into structured bit fields corresponding to its constituent elements (Opcode, Operand References, Addressing Modes).
    • Opcodes are represented in assembly language and technical literature using human-readable abbreviations called mnemonics:
    • ADD\text{ADD}: Add numeric values
    • SUB\text{SUB}: Subtract numeric values
    • MUL\text{MUL}: Multiply numeric values
    • DIV\text{DIV}: Divide numeric values
    • LOAD\text{LOAD}: Load data from memory into processor registers
    • STOR\text{STOR}: Store data from processor registers into memory

Simple Instruction Field Format

  • Instruction Addressing Architectures (Three, Two, and One Address):
    • To compute the expression Y=A−BD×E+CY = \frac{A - B}{D \times E + C}, architectures utilize different instruction formats depending on the number of address references allowed per instruction:
    • Three-Address Instructions:
    • Format specifies two source operand addresses and one destination address (Opcode Destination, Source1, Source2\text{Opcode Destination, Source1, Source2}).
    • Program sequence:
      • SUB Y, A, B\text{SUB Y, A, B} →\rightarrow Computes Y←A−BY \leftarrow A - B
      • MPY T, D, E\text{MPY T, D, E} →\rightarrow Computes temporary variable T←D×ET \leftarrow D \times E
      • ADD T, T, C\text{ADD T, T, C} →\rightarrow Computes T←T+CT \leftarrow T + C
      • DIV Y, Y, T\text{DIV Y, Y, T} →\rightarrow Computes Y←Y÷TY \leftarrow Y \div T
    • Characteristics: Results in short programs with fewer instructions, but requires longer instruction bit lengths to encode three distinct address fields.
    • Two-Address Instructions:
    • One address field doubles as both an operand source and the destination for the result (Opcode Destination/Source1, Source2\text{Opcode Destination/Source1, Source2}).
    • Program sequence:
      • MOVE Y, A\text{MOVE Y, A} →\rightarrow Copies Y←AY \leftarrow A
      • SUB Y, B\text{SUB Y, B} →\rightarrow Computes Y←Y−BY \leftarrow Y - B
      • MOVE T, D\text{MOVE T, D} →\rightarrow Copies temporary variable T←DT \leftarrow D
      • MPY T, E\text{MPY T, E} →\rightarrow Computes T←T×ET \leftarrow T \times E
      • ADD T, C\text{ADD T, C} →\rightarrow Computes T←T+CT \leftarrow T + C
      • DIV Y, T\text{DIV Y, T} →\rightarrow Computes Y←Y÷TY \leftarrow Y \div T
    • Characteristics: Balances instruction length and program length; requires explicit move instructions to avoid overwriting needed operands.
    • One-Address Instructions:
    • Relies on an implicit processor register, the Accumulator (AC\text{AC}), as a source and destination for all computations (Opcode Source\text{Opcode Source}).
    • Program sequence:
      • LOAD D\text{LOAD D} →\rightarrow Loads AC←D\text{AC} \leftarrow D
      • MPY E\text{MPY E} →\rightarrow Computes AC←AC×E\text{AC} \leftarrow \text{AC} \times E
      • ADD C\text{ADD C} →\rightarrow Computes AC←AC+C\text{AC} \leftarrow \text{AC} + C
      • STOR Y\text{STOR Y} →\rightarrow Stores Y←ACY \leftarrow \text{AC}
      • LOAD A\text{LOAD A} →\rightarrow Loads AC←A\text{AC} \leftarrow A
      • SUB B\text{SUB B} →\rightarrow Computes AC←AC−B\text{AC} \leftarrow \text{AC} - B
      • DIV Y\text{DIV Y} →\rightarrow Computes AC←AC÷Y\text{AC} \leftarrow \text{AC} \div Y
      • STOR Y\text{STOR Y} →\rightarrow Stores Y←ACY \leftarrow \text{AC}
    • Characteristics: Very short instruction word lengths, but requires a higher total instruction count and frequent memory access cycles.

Operands and Hardware Data Types

  • General Types of Operands:

    • Addresses: Unsigned integers that reference specific memory locations or offset values (e.g., LOAD X\text{LOAD X} fetches content from memory address XX).
    • Numbers: All digital machines process numerical data across three standard formats:
    • Binary Integer (signed fixed-point or unsigned).
    • Binary Floating Point (scientific notation: sign, exponent, and significand/mantissa).
    • Decimal (base-1010 representations).
    • Packed Decimal:
    • Each decimal digit (00 to 99) is encoded using a 4-bit4\text{-bit} binary nibble.
    • Two decimal digits are packed into each 8-bit8\text{-bit} byte (representing values from 0000 to 9999 per byte).
    • Multiple consecutive bytes are concatenated to represent arbitrarily large decimal numbers without rounding errors, widely used in financial computation.
    • Characters:
    • Textual strings composed of alphabetic characters, numerals, and punctuation symbols encoded as binary values.
    • Common standards: ASCII (7-bit7\text{-bit} or 8-bit8\text{-bit} code) and Unicode.
    • Example: Character 'A' corresponds to decimal code 6565, encoded as binary byte 01000001201000001_2.
    • Logical Data:
    • Treats an n-bitn\text{-bit} unit (word, byte) as an array of individual bits, where each bit represents a Boolean truth value (1=TRUE1 = \text{TRUE}, 0=FALSE0 = \text{FALSE}).
    • Operates on individual bits directly via Boolean logic gates rather than treating the unit as a collective numeric quantity.
  • Comprehensive Classification of Data Types:

    • General: Byte, word (16 bits16\text{ bits}), doubleword (32 bits32\text{ bits}), quadword (64 bits64\text{ bits}), and double quadword (128 bits128\text{ bits}) locations with arbitrary binary contents.
    • Integer: Signed binary value contained within a byte, word, or doubleword using two's complement representation.
    • Ordinal: Unsigned binary integer contained within a byte, word, or doubleword.
    • Unpacked Binary Coded Decimal (BCD): Representation of a single BCD digit in the range 00 through 99, stored with one digit per byte.
    • Packed BCD: Byte representation packing two BCD digits into one byte, spanning values from 00 to 9999.
    • Near Pointer: A 16-bit16\text{-bit}, 32-bit32\text{-bit}, or 64-bit64\text{-bit} effective address representing an offset within a segment; used for all pointers in nonsegmented memory architectures and references within a segment in segmented models.
    • Far Pointer: A logical address comprising a 16-bit16\text{-bit} segment selector combined with a 16-bit16\text{-bit}, 32-bit32\text{-bit}, or 64-bit64\text{-bit} offset; required when accessing memory across segmented boundaries where the target segment identity must be explicitly stated.
    • Bit Field: A contiguous sequence of bits where the position of each bit is evaluated independently; can originate at any bit position in any byte and span up to 32 bits32\text{ bits}.
    • Bit String: A contiguous bit sequence spanning anywhere from 00 to 232−1 bits2^{32} - 1\text{ bits}.
    • Byte String: A contiguous sequence of bytes, words, or doublewords spanning from 00 to 232−1 bytes2^{32} - 1\text{ bytes}.
    • Packed SIMD (Single Instruction, Multiple Data): Dedicated packed data configurations structured in 64-bit64\text{-bit} and 128-bit128\text{-bit} chunks containing multiple parallel sub-elements.

Numeric Data Formats

  • Numeric Data Format Structural Bit Layouts:
    • Byte Unsigned Integer: Bits 7 down to 07\text{ down to }0.
    • Word Unsigned Integer: Bits 15 down to 015\text{ down to }0.
    • Doubleword Unsigned Integer: Bits 31 down to 031\text{ down to }0.
    • Quadword Unsigned Integer: Bits 63 down to 063\text{ down to }0.
    • Byte Signed Integer (Two's Complement): Bit 77 is sign bit; bits 6 down to 06\text{ down to }0 represent value magnitude.
    • Word Signed Integer (Two's Complement): Bit 1515 is sign bit; bits 14 down to 014\text{ down to }0 represent value magnitude.
    • Doubleword Signed Integer (Two's Complement): Bit 3131 is sign bit; bits 30 down to 030\text{ down to }0 represent value magnitude.
    • Quadword Signed Integer (Two's Complement): Bit 6363 is sign bit; bits 62 down to 062\text{ down to }0 represent value magnitude.
    • Half Precision Floating Point: 16-bit16\text{-bit} layout; Bit 1515 is sign bit; bits 14 to 914\text{ to }9 encode the exponent; bits 8 to 08\text{ to }0 represent the significand.
    • Single Precision Floating Point: 32-bit32\text{-bit} layout; Bit 3131 is sign bit; bits 30 to 2230\text{ to }22 encode the exponent; bits 21 to 021\text{ to }0 represent the significand.
    • Double Precision Floating Point: 64-bit64\text{-bit} layout; Bit 6363 is sign bit; bits 62 to 5162\text{ to }51 encode the exponent; bits 50 to 050\text{ to }0 represent the significand.
    • Double Extended Precision Floating Point: 80-bit80\text{-bit} layout; Bit 7979 is sign bit; bits 78 to 6478\text{ to }64 encode the exponent; bit 6363 is an explicit integer bit; bits 62 to 062\text{ to }0 represent the fractional significand.

Types of Operations in Instruction Sets

  • High-Level Functional Categories of Machine Instructions:

    • Data Processing: Computational instructions executing arithmetic and logical evaluations on data words inside the Arithmetic Logic Unit (ALU).
    • Data Storage: Memory instructions responsible for moving data between processor registers and memory locations.
    • Data Movement: I/O instructions moving data between processor/memory registers and external peripheral interfaces.
    • Control: Test and branch instructions examining computational conditions and directing programmatic control flow.
  • Data Transfer Operations:

    • The most fundamental and frequently executed type of machine instruction.
    • Must unambiguously specify three parameters:
    • The exact location of the source operand and destination operand (memory address, processor register, stack top).
    • The length (number of bits/bytes) of data to be transferred.
    • The addressing mode for each operand.
    • Standard operations:
    • Move (transfer)\text{Move (transfer)}: Transfer a word or block from source to destination.
    • Store\text{Store}: Transfer a word from processor register to memory.
    • Load (fetch)\text{Load (fetch)}: Transfer a word from memory to processor register.
    • Exchange\text{Exchange}: Swap the contents of source and destination.
    • Clear (reset)\text{Clear (reset)}: Transfer a word of binary 0s0\text{s} to destination.
    • Set\text{Set}: Transfer a word of binary 1s1\text{s} to destination.
    • Push\text{Push}: Transfer a word from source to top of the system stack.
    • Pop\text{Pop}: Transfer a word from top of the system stack to destination.
    • IBM EAS/390 Data Transfer Example Implementations:
    • L\text{L} (Load): 32 bits32\text{ bits}; transfer from memory to general register.
    • LH\text{LH} (Load Halfword): 16 bits16\text{ bits}; transfer from memory to register.
    • LR\text{LR} (Load): 32 bits32\text{ bits}; transfer from register to register.
    • LER\text{LER} (Load Short): 32 bits32\text{ bits}; transfer from floating-point register to floating-point register.
    • LE\text{LE} (Load Short): 32 bits32\text{ bits}; transfer from memory to floating-point register.
    • LDR\text{LDR} (Load Long): 64 bits64\text{ bits}; transfer from floating-point register to floating-point register.
    • LD\text{LD} (Load Long): 64 bits64\text{ bits}; transfer from memory to floating-point register.
    • ST\text{ST} (Store): 32 bits32\text{ bits}; transfer from register to memory.
    • STH\text{STH} (Store Halfword): 16 bits16\text{ bits}; transfer from register to memory.
    • STC\text{STC} (Store Character): 8 bits8\text{ bits}; transfer from register to memory.
    • STE\text{STE} (Store Short): 32 bits32\text{ bits}; transfer from floating-point register to memory.
    • STD\text{STD} (Store Long): 64 bits64\text{ bits}; transfer from floating-point register to memory.
  • Arithmetic Operations:

    • Core arithmetic primitives provided for signed fixed-point integers, binary floating-point numbers, and packed decimal numbers:
    • Add\text{Add}: Compute sum of two operands (A+BA + B).
    • Subtract\text{Subtract}: Compute difference of two operands (A−BA - B).
    • Multiply\text{Multiply}: Compute product of two operands (A×BA \times B).
    • Divide\text{Divide}: Compute quotient of two operands (A÷BA \div B).
    • Single-operand arithmetic instructions:
    • Absolute\text{Absolute}: Replace operand by its absolute magnitude (∣A∣|A|).
    • Negate\text{Negate}: Change the mathematical sign of the operand via two's complement negation (−A-A).
    • Increment\text{Increment}: Add 11 to the operand (A+1A + 1).
    • Decrement\text{Decrement}: Subtract 11 from the operand (A−1A - 1).
  • Logical Operations:

    • Treat words as strings of individual binary bits to execute Boolean evaluations:
    • AND\text{AND} (∧\land): Output is 11 if and only if both input bits are 11.
    • OR\text{OR} (∨\lor): Output is 11 if at least one input bit is 11.
    • NOT\text{NOT} (¬\neg): Complement/reverses each bit (1→01 \rightarrow 0, 0→10 \rightarrow 1).
    • Exclusive-OR (XOR)\text{Exclusive-OR (XOR)} (⊕\oplus): Output is 11 if inputs differ; 00 if inputs are identical.
  • Standard Boolean Truth Table Verification:

    • When P=0,Q=0P = 0, Q = 0: ¬P=1\neg P = 1, P∧Q=0P \land Q = 0, P∨Q=0P \lor Q = 0, P⊕Q=0P \oplus Q = 0, (P=Q)=1(P = Q) = 1.
  • When P=0,Q=1P = 0, Q = 1: ¬P=1\neg P = 1, P∧Q=0P \land Q = 0, P∨Q=1P \lor Q = 1, P⊕Q=1P \oplus Q = 1, (P=Q)=0(P = Q) = 0.

  • When P=1,Q=0P = 1, Q = 0: ¬P=0\neg P = 0, P∧Q=0P \land Q = 0, P∨Q=1P \lor Q = 1, P⊕Q=1P \oplus Q = 1, (P=Q)=0(P = Q) = 0.

  • When P=1,Q=1P = 1, Q = 1: ¬P=0\neg P = 0, P∧Q=1P \land Q = 1, P∨Q=1P \lor Q = 1, P⊕Q=0P \oplus Q = 0, (P=Q)=1(P = Q) = 1.

    • Specialized logical instructions:
    • Test\text{Test}: Test a specified bit or condition without modifying data; updates hardware processor flags.
    • Compare\text{Compare}: Performs an arithmetic subtraction or logical comparison to set processor condition codes without saving the subtraction result.
    • Set Control Variables\text{Set Control Variables}: Class of instructions modifying hardware controls for memory protection, interrupt management, and timer operations.
  • Shift and Rotate Operations:

    • Bitwise manipulation instructions altering the position of bits within an operand word.

Shift and Rotate Operations

  • Shift Operations:

    • Bits shift linearly in the specified direction; vacated positions are filled with constant binary values (usually zero), and bits dropping off the end are discarded.
    • Logical Right Shift: Bits move right; 00 is inserted at the most significant bit (MSB); dropped least significant bits (LSB) are discarded.
    • Logical Left Shift: Bits move left; 00 is inserted at the LSB; dropped MSB bits are discarded.
    • Arithmetic Right Shift: Preserves signed numbers; bits shift right, but the sign bit (MSB) is replicated into vacated positions to preserve arithmetic sign.
    • Arithmetic Left Shift: Bits move left, filling LSB with 00 (identical to logical left shift, though overflow is signaled if sign bit changes).
  • Rotate Operations:

    • Wraparound operations preserving all bits; bits displaced out of one end are circulated back into the vacated position at the opposite end.
    • Right Rotate: Bits shifted right; displaced LSB wraps around to enter the MSB.
    • Left Rotate: Bits shifted left; displaced MSB wraps around to enter the LSB.
  • Worked Reference Examples (3-Bit3\text{-Bit} Displacements on Input Byte 10100110210100110_2):

    • Input Byte: 10100110210100110_2

    • Logical Right Shift (3 bits3\text{ bits}): Result = 00010100200010100_2

    • Logical Left Shift (3 bits3\text{ bits}): Result = 00110000200110000_2

    • Arithmetic Right Shift (3 bits3\text{ bits}): Result = 11110100211110100_2 (sign bit 11 replicated)

    • Arithmetic Left Shift (3 bits3\text{ bits}): Result = 00110000200110000_2

    • Right Rotate (3 bits3\text{ bits}): Result = 11010100211010100_2

    • Left Rotate (3 bits3\text{ bits}): Result = 00110101200110101_2

    • Conversion Operations:

  • Transform data representation or numeric base format:

    • Converting binary to decimal, or packed BCD to binary representation.

    • Translate\text{Translate}: Translates a buffer of byte values in memory according to an indexed conversion table of correspondences.

    • Convert\text{Convert}: Converts the internal representation of a word (e.g., packed decimal to signed binary integer).

    • Input/Output Operations:

  • Architectural mechanisms implemented for peripheral interfacing:

    • Isolated programmed I/O (separate address space and control lines for I/O ports).
    • Memory-mapped programmed I/O (I/O registers occupy standard memory address space).
    • Direct Memory Access (DMA) (hardware controller moves data directly between memory and device without constant processor intervention).
    • Dedicated I/O Processor (channel architecture executing autonomous I/O programs).
  • Primitive operations:

    • Input (read)\text{Input (read)}: Transfer data from specified I/O port/device into register or memory.

    • Output (write)\text{Output (write)}: Transfer data from register or memory to specified I/O port/device.

    • Start I/O\text{Start I/O}: Dispatch control parameters to I/O processor to initiate asynchronous I/O transaction.

    • Test I/O\text{Test I/O}: Poll and transfer status flags from the I/O interface to verify availability or transfer completion.

    • System Control Operations:

  • Restricted instructions executable only when the processor operates in a privileged supervisory state or executes code located inside protected kernel memory.

  • Operating system functions executing via system control:

    • Reading or altering hardware control registers.

    • Reading or modifying storage protection keys.

    • Accessing and swapping Process Control Blocks (PCBs) in a multiprogramming operating system.

    • Transfer of Control Operations:

  • Fundamental necessity for program flow:

    • Permits executing instruction sequences multiple times (iterative loops).
    • Facilitates runtime conditional decision-making.
    • Enables modular software construction by decomposing tasks into modular subroutines.
  • Primary control transfer types:

    • Branch (Jump)\text{Branch (Jump)}: Changes execution sequence to a specified memory address; can be unconditional or conditional upon testing processor condition codes.
    • Skip\text{Skip}: Conditionally increments the Program Counter (PC\text{PC}) to bypass the immediately following instruction without requiring an explicit destination address.
    • Procedure Call (Jump to Subroutine)\text{Procedure Call (Jump to Subroutine)}: Saves current program execution state and return address (to stack or link register) before jumping to a target procedure address.
    • Return\text{Return}: Restores the stored return address and processor state from the stack or link register back to the Program Counter, resuming parent execution.
    • Execute\text{Execute}: Fetches an instruction from a remote memory address and executes it without modifying the Program Counter.
    • Halt\text{Halt}: Terminates program instruction execution.
    • Wait (Hold)\text{Wait (Hold)}: Suspends instruction execution, continually testing for an external condition/interrupt until satisfied.
    • No Operation (NOP)\text{No Operation (NOP)}: Executes no state modification; processor simply advances the Program Counter to the next instruction.

Addressing Modes and Mechanics

  • Purpose and Need for Addressing Modes:
    • In typical instruction word formats, the number of bits allocated to address fields is strictly limited.
    • Addressing modes allow programs to access very large physical and virtual memory spaces using compact bit allocations in instruction fields, providing reference versatility.

Summary of Basic Addressing Modes

  • Comprehensive Breakdown of Basic Addressing Modes:

    • Immediate Addressing:

    • Algorithm: Operand=A\text{Operand} = A

    • Mechanics: The operand value is contained explicitly within the instruction address field itself; no address calculation is performed.

    • Example: ADD R2, #100\text{ADD R2, \#100} directly adds integer constant 100100 to register R2\text{R2}.

    • Advantage: Zero memory references; fetches instantly with the instruction.

    • Disadvantage: Limited operand magnitude restricted to the bit width of field AA.

    • Direct Addressing:

    • Algorithm: Effective Address (EA)=A\text{Effective Address (EA)} = A

    • Mechanics: The address field AA directly specifies the physical/virtual memory address of the target operand.

    • Example: ADD R1, 4000\text{ADD R1, 4000} directs the CPU to access memory cell 40004000 (holding data value 100100) and add it to register R1\text{R1}.

Direct Addressing Mode

  • Advantage: Simple architecture; requires only one memory reference to obtain the operand.

  • Disadvantage: Limited address space restricted directly to the address range expressible within field AA.

    • Indirect Addressing:
  • Algorithm: Effective Address (EA)=(A)\text{Effective Address (EA)} = (A)

  • Mechanics: Address field AA contains the memory address of a pointer location, which in turn contains the true effective address of the operand.

  • Example: MOV A, @R0\text{MOV A, @R0} or MOV A, (R0)\text{MOV A, (R0)}, where register R0\text{R}_0 contains address 30H30\text{H}, which references memory cell 30H30\text{H} holding pointer 0707, resolving the actual data location.

Indirect Addressing Mode

  • Advantage: Huge address space (2N2^N where NN is word length).

  • Disadvantage: Multiple memory references required to access a single operand, significantly degrading execution speed.

    • Register Addressing:
  • Algorithm: Effective Address (EA)=R\text{Effective Address (EA)} = R

  • Mechanics: The operand is held inside a processor register specified by register identifier field RR.

  • Example: ADD R4, R3\text{ADD R4, R3} adds operand in register R3\text{R3} directly to register R4\text{R4}.

Register Addressing Mode

  • Advantage: No memory reference required; highest possible operand access speed.

  • Disadvantage: Severely limited address space restricted solely to the small set of internal CPU registers.

    • Register Indirect Addressing:
  • Algorithm: Effective Address (EA)=(R)\text{Effective Address (EA)} = (R)

  • Mechanics: The instruction refers to register RR, which contains the effective memory address of the operand.

  • Example: LOAD R3, (R2)\text{LOAD R3, (R2)}, where register R2\text{R2} holds address value 200200, directing the CPU to fetch data value AA from memory address 200200 and store it into register R3\text{R3}.

Register Indirect Addressing Mode

  • Advantage: Enormous address space accessible with very small instruction field allocations; one less memory access cycle than full indirect addressing.

  • Disadvantage: Requires one memory reference cycle compared to pure register addressing.

    • Displacement Addressing:
  • Algorithm: Effective Address (EA)=A+(R)\text{Effective Address (EA)} = A + (R)

  • Mechanics: Combines direct addressing and register indirect addressing; the effective address is computed by summing constant address offset AA with the contents of register RR.

Displacement Addressing Mode

  • Mathematical Examples:
    • If a base register holds value 10001000 and displacement A=50A = 50, the effective address is EA=1000+50=1050\text{EA} = 1000 + 50 = 1050.
    • If base register holds content 10011001 and displacement is 22, the effective address is EA=1001+2=1003\text{EA} = 1001 + 2 = 1003.

Displacement Addressing Calculation Example

  • Advantage: High architectural flexibility (supports base-register addressing, index addressing, and program-counter relative addressing).

  • Disadvantage: Increased instruction calculation complexity and hardware overhead.

    • Stack Addressing:
  • Algorithm: Effective Address (EA)=Top of Stack\text{Effective Address (EA)} = \text{Top of Stack}

  • Mechanics: Operands are implicitly referenced from the top of a Last-In-First-Out (LIFO) stack managed via a dedicated Stack Pointer (SP) register.

  • Example: Stack addition pops the top two values (33 and 77), adds them to produce 1010, and pushes 1010 back onto the stack top.

Stack Addressing Mode

  • Advantage: Zero memory references within the instruction format itself; compact zero-address machine format.
  • Disadvantage: Severely limited applicability to general-purpose computing tasks.

ARM Architecture, Instruction Formats, and Bit Allocation

  • ARM Architectural Foundations:

    • Advanced RISC Machine (ARM) is a microprocessor architecture family based upon Reduced Instruction Set Computer (RISC) design principles.
    • Core RISC principles emphasize simple, highly optimized, uniform instructions designed for high-speed single-cycle execution.
    • Operates on a load/store architecture: memory is accessed solely through explicit load and store instructions; all arithmetic and logic processing operates exclusively between registers.
  • ARM Data Access Addressing Mechanisms:

    • Implements a uniform, regular addressing strategy across instructions (Load, Store, Add, Subtract).
    • Three standard operand formats:
    • Immediate: Direct constant embedded in instruction: ADD R0, R1, #5\text{ADD R0, R1, \#5} (adds literal 55 to R1\text{R1}, writes to R0\text{R0}).
    • Register: Value located inside a register: ADD R0, R1, R2\text{ADD R0, R1, R2} (adds R1\text{R1} and R2\text{R2}, writes to R0\text{R0}).
    • Shifted Register: Second register operand scaled on-the-fly via the internal barrel shifter before execution: ADD R0, R1, R2, LSL #2\text{ADD R0, R1, R2, LSL \#2} (shifts R2\text{R2} left by 2 bits2\text{ bits}, effectively multiplying it by 44, adds to R1\text{R1}, writes to R0\text{R0}).
    • The Five ARM Hardware Shift Operators:
    • LSL\text{LSL}: Logical Shift Left
    • LSR\text{LSR}: Logical Shift Right
    • ASR\text{ASR}: Arithmetic Shift Right (preserves sign bit)
    • ROR\text{ROR}: Rotate Right
    • RRX\text{RRX}: Rotate Right Extended through the carry flag
  • Comparison: Data Processing vs. Branch Instructions:

    • Data Processing Instructions:
    • Function: Computations and logical operations (ADD\text{ADD}, SUB\text{SUB}, AND\text{AND}, OR\text{OR}).
    • Main Purpose: Process data inside the CPU.
    • Addressing Type: Register addressing, immediate addressing, or shifted register addressing.
    • Operands: Numeric data, raw values in registers.
    • Execution Unit: Inside the Arithmetic Logic Unit (ALU).
    • Branch Instructions:
    • Function: Direct control transfer (B LABEL\text{B LABEL}).
    • Main Purpose: Alter program execution flow.
    • Addressing Type: Immediate addressing only.
    • Operands: Memory destination addresses.
    • Execution Unit: Inside the Control Unit and Program Counter (PC\text{PC}).
    • Branch Mechanics: Contains a signed 24-bit24\text{-bit} immediate offset. This 24-bit24\text{-bit} field is shifted left by 2 bits2\text{ bits} to achieve 32-bit32\text{-bit} word alignment, yielding an effective branching displacement range of ±32 MB\pm 32\,\text{MB} relative to the Program Counter.
  • ARM Instruction Length and Bit Allocation:

    • Every ARM instruction has a fixed length of exactly 32 bits32\text{ bits} (4 bytes4\text{ bytes}), simplifying instruction fetch, pipeline decoding, and execution alignment.
    • Every instruction begins with a 4-bit4\text{-bit} condition code field (cond, bits 31 down to 2831\text{ down to }28), allowing every instruction to be executed conditionally based on processor status flags.

ARM Instruction Formats

  • Detailed Field Breakdown of ARM Instruction Formats:

    • Data Processing (Immediate Shift): Bits 31–2831\text{--}28: cond; Bits 27–2527\text{--}25: 000; Bits 24–2124\text{--}21: opcode; Bit 2020: S; Bits 19–1619\text{--}16: Rn; Bits 15–1215\text{--}12: Rd; Bits 11–711\text{--}7: shift amount; Bits 6–56\text{--}5: shift; Bit 44: 0; Bits 3–03\text{--}0: Rm.
    • Data Processing (Register Shift): Bits 31–2831\text{--}28: cond; Bits 27–2527\text{--}25: 000; Bits 24–2124\text{--}21: opcode; Bit 2020: S; Bits 19–1619\text{--}16: Rn; Bits 15–1215\text{--}12: Rd; Bits 11–811\text{--}8: Rs; Bit 77: 0; Bits 6–56\text{--}5: shift; Bit 44: 1; Bits 3–03\text{--}0: Rm.
    • Data Processing (Immediate): Bits 31–2831\text{--}28: cond; Bits 27–2527\text{--}25: 001; Bits 24–2124\text{--}21: opcode; Bit 2020: S; Bits 19–1619\text{--}16: Rn; Bits 15–1215\text{--}12: Rd; Bits 11–811\text{--}8: rotate; Bits 7–07\text{--}0: immediate.
    • Load/Store (Immediate Offset): Bits 31–2831\text{--}28: cond; Bits 27–2627\text{--}26: 01; Bit 2525: 0; Bits 24–2024\text{--}20: P, U, B, W, L; Bits 19–1619\text{--}16: Rn; Bits 15–1215\text{--}12: Rd; Bits 11–011\text{--}0: immediate.
    • Load/Store (Register Offset): Bits 31–2831\text{--}28: cond; Bits 27–2627\text{--}26: 01; Bit 2525: 1; Bits 24–2024\text{--}20: P, U, B, W, L; Bits 19–1619\text{--}16: Rn; Bits 15–1215\text{--}12: Rd; Bits 11–711\text{--}7: shift amount; Bits 6–56\text{--}5: shift; Bit 44: 0; Bits 3–03\text{--}0: Rm.
    • Load/Store Multiple: Bits 31–2831\text{--}28: cond; Bits 27–2527\text{--}25: 100; Bits 24–2024\text{--}20: P, U, S, W, L; Bits 19–1619\text{--}16: Rn; Bits 15–015\text{--}0: register list.
    • Branch / Branch with Link: Bits 31–2831\text{--}28: cond; Bits 27–2527\text{--}25: 101; Bit 2424: L; Bits 23–023\text{--}0: 24-bit offset.
  • Function of Specific Control and Status Bits:

    • SS Bit:
    • In Data Processing instructions: specifies whether the execution updates the condition code flags (S=1S=1 updates; S=0S=0 preserves flags).
    • In Load/Store Multiple instructions: indicates whether execution is restricted to privileged supervisor mode.
    • P,U,WP, U, W Bits: Distinguish among addressing mode variants (Pre/Post indexing, Up/Down address offset arithmetic, Write-back to base register).
    • BB Bit: Distinguishes between unsigned byte (B=1B = 1) and full word (B=0B = 0) memory transfers.
    • LL Bit:
    • In Load/Store instructions: distinguishes between a Load (L=1L = 1) and a Store (L=0L = 0).
    • In Branch instructions: distinguishes between a standard Branch (L=0L = 0) and a Branch with Link (L=1L = 1), which saves the return address into the Link Register (R14\text{R14}).

Processor Function, Organization, and Register Structure

  • Core Processor Requirements:

    • The processor (Central Processing Unit) serves as the primary logic circuitry that interprets and processes basic instructions driving the computer.
    • Five fundamental operational requirements:
    • Fetch instruction: Reads an instruction from storage hierarchy (registers, cache, main memory).
    • Interpret instruction: Decodes the fetched instruction to determine required actions.
    • Fetch data: Reads operand data from memory or an I/O module as dictated by execution.
    • Process data: Executes arithmetic or logical operations upon operands.
    • Write data: Transmits operational results to memory or an I/O module.
  • Internal CPU Architecture and System Bus Interface:

    • The processor connects to the broader system via three distinct bus structures:
    • Control Bus: Carries command, synchronization, and timing signals.
    • Data Bus: Carries raw data and instruction words between system components.
    • Address Bus: Carries physical addresses determining memory cells or I/O ports targeted for access.
    • Internal CPU blocks include the Arithmetic Logic Unit (ALU), Registers, and the Control Unit.

CPU Internal Architecture with System Bus

  • Internal Register Organization:

    • Registers reside at the top of the storage hierarchy, providing rapid data storage.
    • Dual architectural roles of internal registers:
    • User-Visible Registers: Accessible by assembly/machine language programmers to minimize memory access overhead.
    • Control and Status Registers: Utilized by the control unit to regulate processor operations and by operating system software to manage execution state.
  • Categories of User-Visible Registers:

    • General Purpose: Flexible registers that can be assigned to diverse operations by programmers or compilers.
    • Data Registers: Dedicated exclusively to storing data operands; cannot be used in calculating effective operand addresses.
    • Address Registers: Dedicated to specific addressing modes or general address manipulation (e.g., segment pointers, index registers, stack pointers).
    • Condition Codes (Flags): Individual status bits set automatically by hardware in response to arithmetic, logical, or comparison results.
  • Essential Control and Status Registers:

    • Four registers are critical to instruction sequencing:
    • Program Counter (PC): Contains the memory address of the next instruction to be fetched.
    • Instruction Register (IR): Holds the instruction word most recently fetched from memory.
    • Memory Address Register (MAR): Connects directly to the address bus; holds the physical memory address for an impending read or write cycle.
    • Memory Buffer Register (MBR): Connects directly to the data bus; holds data received from memory or data ready to be written to memory.
  • Program Status Word (PSW):

    • A dedicated register holding status flags and control bits that define the processor's current operational state.
    • Key fields and condition flags:
    • Sign: Records the sign bit of the most recent arithmetic calculation result (1=Negative1 = \text{Negative}, 0=Positive0 = \text{Positive}).
    • Zero: Set to 11 when the result of an operation evaluates to zero.
    • Carry: Set to 11 if an arithmetic operation results in a carry out of or borrow into the most significant bit.
    • Equal: Set to 11 if a logical comparison evaluates to equality.
    • Overflow: Indicates an arithmetic overflow condition when a signed calculation exceeds the numeric limits of the target data width.
    • Interrupt Enable/Disable: Global mask bit enabling or inhibiting the CPU from servicing maskable external interrupts.
    • Supervisor: Flags whether the CPU runs in privileged Supervisor mode or restricted User mode.

The Instruction Cycle and Internal Micro-Operations

  • Stages of the Complete Instruction Cycle:

    • The operational lifecycle of each instruction consists of four primary stages:
    • Fetch Stage: Reads the next instruction from memory into the processor.
    • Indirect Stage: If the instruction specifies indirect addressing, fetches the effective address of the operand via additional memory read operations.
    • Execute Stage: Interprets the opcode and executes the specified operational logic.
    • Interrupt Stage: If interrupts are enabled and an interrupt signal is pending, saves the current process context and invokes the appropriate interrupt service handler.
  • Data Flow During the Fetch Cycle:

    • Sequence of micro-operations moving instruction data from memory into processor registers:
    • 1. The Program Counter (PC\text{PC}) contains the address of the next instruction to be fetched.
    • 2. The address in PC\text{PC} is transferred to the Memory Address Register (MAR\text{MAR}).
    • 3. MAR\text{MAR} asserts this address onto the Address Bus.
    • 4. The Control Unit issues an explicit memory read command on the Control Bus.
    • 5. Memory retrieves the instruction word and places it onto the Data Bus, which loads it into the Memory Buffer Register (MBR\text{MBR}).
    • 6. The contents of MBR\text{MBR} are transferred to the Instruction Register (IR\text{IR}).
    • 7. Simultaneously, the PC\text{PC} is incremented by the instruction word length to prepare for the subsequent fetch cycle.
  • Data Flow During the Indirect Cycle:

    • Required when an instruction uses indirect addressing to resolve operand locations:
    • 1. The address field portion of the instruction currently residing in IR\text{IR} (or MBR\text{MBR}) is transferred into MAR\text{MAR}.
    • 2. MAR\text{MAR} asserts this pointer address onto the Address Bus.
    • 3. The Control Unit asserts a memory read signal on the Control Bus.
    • 4. Memory returns the operand's true effective address across the Data Bus into the MBR\text{MBR}.
    • 5. MBR\text{MBR} now holds the resolved effective address needed for execution.
  • Data Flow During the Interrupt Cycle:

    • Executes upon completion of the execute cycle if an active interrupt is flagged and enabled:
    • 1. The current contents of the PC\text{PC} must be preserved so execution can resume seamlessly post-interrupt.
    • 2. The PC\text{PC} contents are transferred to MBR\text{MBR}.
    • 3. The Control Unit loads the target save location address (e.g., system stack pointer or fixed reserve address) into MAR\text{MAR}.
    • 4. MAR\text{MAR} asserts this address onto the Address Bus.
    • 5. The Control Unit asserts a memory write command on the Control Bus.
    • 6. The return address stored in MBR\text{MBR} is transmitted across the Data Bus and written to memory.
    • 7. The PC\text{PC} is loaded with the start address of the designated Interrupt Service Routine (ISR), redirecting processor execution to the handler.