Instruction System – A Comprehensive Guide | Generated by AI

Home PDF

1. Introduction to the Instruction System

An Instruction Set Architecture (ISA) defines the interface between software and hardware. It specifies the instructions a processor can execute, their formats, and how they interact with memory and registers. Understanding ISA is crucial for both programming (especially in assembly language) and designing computer hardware.


2. Instruction Set Architecture (ISA)

2.1 What is ISA?

The Instruction Set Architecture (ISA) is the part of the processor’s design that handles execution of instructions, including:

2.2 Types of ISAs

  1. CISC (Complex Instruction Set Computing)
    • A single instruction can perform multiple operations.
    • Example: x86 architecture (Intel, AMD).
    • Advantages: Fewer instructions per program, easier to program in assembly.
    • Disadvantages: Slower instruction execution due to complexity.
  2. RISC (Reduced Instruction Set Computing)
    • Each instruction performs a simple operation and executes in a single cycle.
    • Example: ARM, MIPS, RISC-V.
    • Advantages: Faster execution, simpler hardware.
    • Disadvantages: More instructions needed for complex tasks.

3. Instruction Formats

3.1 What is an Instruction Format?

An instruction format defines how an instruction is structured in memory. It consists of the following fields:

  1. Opcode (Operation Code): Specifies the operation (e.g., ADD, LOAD, STORE).
  2. Operands: Specifies the data (registers, memory addresses).
  3. Addressing Mode: Specifies how to access operands.

3.2 Common Instruction Formats

  1. Fixed Format:
    • All instructions are the same size (e.g., 32-bit in MIPS).
    • Easy to decode but may waste space.
  2. Variable Format:
    • Instructions vary in size (e.g., x86, ARM).
    • Efficient memory use but harder to decode.
  3. Hybrid Format:
    • Combination of fixed and variable formats (e.g., ARM Thumb instructions).

3.3 Example Instruction Format (MIPS Architecture)

In MIPS, an instruction is 32 bits long and has three main formats:

  1. R-Type (Register-Type)
    | Opcode (6) | Rs (5) | Rt (5) | Rd (5) | Shamt (5) | Funct (6) |
    
    • Example: add $t1, $t2, $t3
    • Meaning: $t1 = $t2 + $t3
  2. I-Type (Immediate-Type)
    | Opcode (6) | Rs (5) | Rt (5) | Immediate (16) |
    
    • Example: addi $t1, $t2, 10
    • Meaning: $t1 = $t2 + 10
  3. J-Type (Jump-Type)
    | Opcode (6) | Address (26) |
    
    • Example: j 10000 (Jump to memory address 10000)

4. Addressing Modes

Addressing modes determine how operands are accessed in an instruction.

4.1 Common Addressing Modes

  1. Immediate Addressing: The operand is directly specified in the instruction.
    • Example: addi $t1, $t2, 10 (10 is an immediate value)
  2. Register Addressing: The operand is stored in a register.
    • Example: add $t1, $t2, $t3 (all operands are in registers)
  3. Direct Addressing: The instruction contains the memory address of the operand.
    • Example: load $t1, 1000 (load value from memory address 1000)
  4. Indirect Addressing: The address of the operand is stored in a register.
    • Example: load $t1, ($t2) (fetch value from the address stored in $t2)
  5. Indexed Addressing: The address is calculated by adding an offset to a register.
    • Example: load $t1, 10($t2) (fetch value from $t2 + 10)
  6. Base+Offset Addressing: A base register and offset determine the address.
    • Example: lw $t1, 4($sp) (fetch from $sp + 4)

4.2 Importance of Addressing Modes


5. Assembly Language Programming

5.1 What is Assembly Language?

Assembly language is a low-level programming language that directly corresponds to machine code.

5.2 Structure of an Assembly Program

A basic assembly program consists of:

5.3 Basic MIPS Assembly Program

.data
msg: .asciiz "Hello, World!"

.text
.globl main
main:
    li $v0, 4       # Load syscall code for print_string
    la $a0, msg     # Load address of string
    syscall         # Print string

    li $v0, 10      # Exit syscall
    syscall

5.4 Key Assembly Instructions

| Instruction | Meaning | Example | |————|———|———| | add | Add two registers | add $t1, $t2, $t3 | | sub | Subtract two registers | sub $t1, $t2, $t3 | | lw | Load word from memory | lw $t1, 0($t2) | | sw | Store word to memory | sw $t1, 0($t2) | | beq | Branch if equal | beq $t1, $t2, label | | j | Jump to address | j label |

5.5 Assembly vs High-Level Languages

| Feature | Assembly | High-Level Language (C, Python) | |———|———|——————————| | Speed | Faster | Slower (more overhead) | | Control | Full control over hardware | Abstracted from hardware | | Difficulty | Complex syntax | Easier syntax | | Portability | CPU-specific | Works across different CPUs |


6. Summary

Key Takeaways

Practice Exercises

  1. Convert the MIPS instruction addi $t1, $t2, 5 into binary format.
  2. Write an assembly program to add two numbers stored in registers.
  3. Explain the difference between direct and indirect addressing with examples.

Understanding the instruction system is essential for learning computer organization and architecture, especially if you aim to work with low-level programming, embedded systems, or processor design. Let me know if you need more examples or explanations! 🚀


Back 2025.03.23 Donate