[Recover Note] For Computer Organisation Quiz 3
[Recover Note] For Computer Organisation Quiz 3

[Recover Note] For Computer Organisation Quiz 3


作者:Harkerbest

声明:本文章为原创文章,本文章永久链接:https://www.harkerbest.cn/p/1013 转载请注明原文地址,盗版必究!!!


Microarchitecture – Lecture Notes

Key Concepts

  1. ISA (Instruction Set Architecture)
  • Defines what hardware does but not how.
  • Interface for assembly programmers or compiler writers.
  • Multiple microarchitectures can implement the same ISA.
  1. Microarchitecture
  • Connects circuits to implement ISA.
  • Specifies how hardware functions are carried out.

The von Neumann Architecture

  • Principles:
  • Memory stores both data and instructions.
  • CPU fetches and executes instructions sequentially.
  • Components:
  • Single main memory for data and program storage.
  • CPU acts as the “brain” of the computer.

Memory

  • Structure:
  • Array of stored bits with unique addresses.
  • Basic operations:
    • LOAD: Read value from memory.
    • STORE: Write value to memory.
  • Addressability: 8-bit.
  • Address space: (2^4).
  • Interface to Memory:
  • MAR (Memory Address Register): Holds address for memory access.
  • MDR (Memory Data Register): Holds data to be read/written.

CPU Components

  1. Registers
  • Small, fast storage for intermediate data.
  • Implemented using D flip-flops.
  1. ALU (Arithmetic Logic Unit)
  • Performs arithmetic and logic operations (e.g., ADD, AND, NOT).
  1. Control Unit
  • Coordinates program execution using a Finite State Machine (FSM).
  • Key components:
    • IR (Instruction Register): Holds the current instruction.
    • PC (Program Counter): Points to the next instruction.

Instruction Processing Phases

  1. Fetch:
  • Load instruction from memory into IR.
  • Increment PC to point to the next instruction.
  1. Decode:
  • Identify opcode (first 4 bits in LC-3).
  • Decode operands from remaining bits.
  1. Evaluate Address:
  • Compute memory access address, if required.
  1. Fetch Operands:
  • Obtain source operands (e.g., load data from memory or registers).
  1. Execute:
  • Perform operations (e.g., ADD, store, etc.).
  1. Store:
  • Write results to destination (register or memory).

LC-3 Highlights

  • Memory:
  • Address space: (2^{16}) locations.
  • Addressability: 16-bit.
  • I/O Devices:
  • Keyboard (KBDR, KBSR).
  • Monitor (DDR, DSR).
  • Processing Unit:
  • ALU and general-purpose registers (R0 to R7).
  • Control Unit:
  • FSM-based instruction coordination.

Key LC-3 Instructions

  1. ADD Instruction:
  • Opcode: 0001.
  • Operation: Src1 + Src2 → Dst.
  • Example: R6 = R6 + R2.
  1. LDR Instruction:
  • Opcode: 0110.
  • Operation: Load memory content at Base + Offset to a register.
  • Example: Load (R3 + 6) to R2.

Control Flow

  • Instructions like jumps and branches modify the PC to alter execution order.
  • Example: Add an offset to a register and set PC to the result.

Clock-Driven Operation

  • The clock drives the FSM in the control unit.
  • Instruction cycles are synchronized with clock ticks.

LC-3 ISA – Lecture Notes

Instruction Set Architecture (ISA) Overview

  • Purpose: Specifies what software needs to know about the computer hardware.
  • Key Features:
  • Memory:
    • Address Space: Number of addressable locations.
    • Addressability: Word size or byte, and organization.
  • Registers:
    • Number and type of registers.
  • Instructions:
    • Operations (what is executable).
    • Data types and addressing modes.

LC-3 Specifics

Memory Organization

  • Memory space and addressing handled through addressing modes.

Registers

  • LC-3 has 8 general-purpose registers (R0 to R7).
  • Condition Codes: Special single-bit flags (N, Z, P) updated based on the result of operations:
  • N (Negative), Z (Zero), P (Positive).

Instructions

  1. Structure:
  • Opcode: Defines the operation (e.g., ADD, AND, NOT).
  • Operands: Data or location affected by the operation.
  • LC-3 opcode: 4 bits → ( 2^4 = 16 ) possible instructions.
  1. Data Types:
  • Supports 2’s complement integers.

Addressing Modes

  1. Operate Instructions:
  • Perform operations like arithmetic or logic.
  • Examples: NOT, AND, ADD.
  1. Data Movement Instructions:
  • PC-Relative Mode:
    • Instructions: LD (Load), ST (Store).
  • Base + Offset Mode:
    • Instructions: LDR, STR.
  • Indirect Addressing Mode:
    • Indirect addressing involves two memory accesses: one to get the operand’s address and another to retrieve the operand itself.
    • Instructions: LDI (Load Indirect), STI (Store Indirect).
  1. LEA (Load Effective Address):
  • Opcode: 1110.
  • Operands are obtained immediately without memory access.

Control Instructions

  1. BR (Branch):
  • Conditional branching based on condition codes (N, Z, P).
  • Used for flow control like if-then statements or loops.
  • Example Use Case: Building loops for adding integers.
  1. JMP (Jump):
  • Directly alters program flow to a specified address.
  1. TRAP:
  • Invokes a system routine or service.

Programming Examples

  1. Adding 12 Integers:
  • Techniques include sentinel control and counter control.
  • Implemented using branching instructions.
  1. Flowcharts:
  • Used to visually design program control flow.

Next Steps:

  • Transition to learning LC-3 Assembly Language.

From Machine Language to Assembly Language – Lecture Notes

Machine Language vs. Assembly Language

  • Machine Language:
  • Comprised of binary instructions (e.g., 0001 110 010 0 00 110).
  • Preferred by computers.
  • Assembly Language:
  • Uses symbolic instructions (e.g., ADD R6, R2, R6).
  • Preferred by humans for readability.
  • Requires an assembler to convert symbols into binary machine instructions.

Structure of an Assembly Language Program

  • Each line can include:
  1. Instruction: Specifies an operation (e.g., ADD, LD).
  2. Assembler Directive (Pseudo-op): Provides metadata or instructions for the assembler (e.g., .ORIG, .END).
  3. Comments: Begin with ; and are ignored by the assembler.

LC-3 Assembly Language Syntax

Opcodes and Operands:

  • Opcodes: Reserved symbols corresponding to instructions (e.g., ADD, AND, LD).
  • Operands:
  • Registers: Symbolic (e.g., R0, R1).
  • Numbers: Represented in decimal (#) or hexadecimal (x).
  • Labels: Symbolic names for memory locations.

Examples:

  • Instruction: ADD R1, R2, R3 (Add contents of R2 and R3, store in R1).
  • Label Example:
  LOOP   ADD R1, R1, #-1
         BRp LOOP

Assembler Directives

  • Help define the structure and purpose of the program.
  • Examples:
  • .ORIG: Defines the starting address of the program.
  • .END: Marks the end of the program.
  • Question: What is the difference between HALT and .END?
  • HALT: Stops the program execution.
  • .END: Marks the logical end of the program file.

Trap Codes

  • Special LC-3 instructions that invoke system routines.
  • Examples:
  • TRAP x23: Input a character from the keyboard.
  • TRAP x25: Halt the program.

Style Guidelines

  • Use comments effectively:
  • Avoid restating obvious operations (e.g., “decrement R1”).
  • Provide additional insights (e.g., “accumulate product in R6”).
  • Separate logical sections of the program with comments for clarity.

The Assembly Process

  1. First Pass: Constructing the Symbol Table
  • Identify labels and associate them with memory addresses.
  • Example: In Figure 7.1, create a table of symbols.
  1. Second Pass: Generating Machine Language
  • Translate assembly language into binary instructions using the symbol table.
  • Example: Use the symbol table to encode LC-3 instructions.

Assembler Output

  • Object File:
  • Contains binary representation of instructions and data for execution.
  • Multiple Object Files:
  • Can be linked together to form a complete program.

Next Steps

  • Learn about calling subroutines and linking them into larger programs.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

CAPTCHAis initialing...