Computer Instructions

The Language of the CPU - Understanding How Computers Execute Commands

🖥️

What Are Computer Instructions?

A computer instruction is a binary code that directs the computer to perform a specific operation. These instructions are fundamental to how a computer processes information, specifying a sequence of micro-operations for the computer to execute.

16-Bit Instruction Structure

1
1
1
0
0
0
0
1
1
0
1
0
0
1
1
1

■ Mode Bit (I) | ■ Opcode | ■ Address

🎯

Addressing Modes

Instructions can refer to memory locations in different ways:

Direct Addressing (I = 0)

Instruction: ADD 457
→ Directly access address 457
Get operand from location 457

Indirect Addressing (I = 1)

Instruction: ADD 300
→ Go to address 300
→ Read address stored there (1350)
→ Get operand from location 1350
📋

Types of Computer Instructions

Memory-Reference Instructions

Format: I (Mode) bit + 3-bit Opcode (000-110) + 12-bit address

  • AND: Bitwise AND with memory
    • Direct (I=0): 0xxx
    • Indirect (I=1): 8xxx
  • ADD: Add memory content to AC
    • Direct (I=0): 1xxx
    • Indirect (I=1): 9xxx
  • LDA: Load AC from memory
    • Direct (I=0): 2xxx
    • Indirect (I=1): Axxx
  • STA: Store AC to memory
    • Direct (I=0): 3xxx
    • Indirect (I=1): Bxxx
  • BUN: Branch unconditionally
    • Direct (I=0): 4xxx
    • Indirect (I=1): Cxxx
  • BSA: Branch and save return address
    • Direct (I=0): 5xxx
    • Indirect (I=1): Dxxx
  • ISZ: Increment and skip if zero
    • Direct (I=0): 6xxx
    • Indirect (I=1): Exxx

xxx - Represent 12-bit address for Memory

Register-Reference Instructions

Format: 0 (I bit) + 111 (Opcode bit) + 12-bit operation

  • CLA (7800): Clear Accumulator
  • CLE (7400): Clear E flip-flop
  • CMA (7200): Complement Accumulator
  • CME (7100): Complement E
  • CIR (7080): Circular shifts Right AC and E
  • CIL (7040): Circular shifts Left AC and E
  • INC (7020): Increment Accumulator
  • SPA (7010): Skip on AC sign Positive
  • SNA (7008): Skip on AC sign Negative
  • SZA (7004): Skip next instruction if AC zero
  • SZE (7002): Skip next instruction if E is 0
  • HLT (7001): Halt computer

Input-Output Instructions

Format: 1 (I bit) + 111 (Opcode bit) + 12-bit I/O operation

  • INP: Input character to AC
  • OUT: Output character from AC
  • SKI: Skip if input flag on
  • SKO: Skip if output flag on
  • ION: Turn interrupt on
  • IOF: Turn interrupt off
🔧

Pseudo-Instructions

🏷️ Assembly Language Directives

Pseudo-instructions provide information to the assembler but do not translate into machine code themselves. They control the assembly process and define program structure.

ORG (Origin)

ORG N
Sets the starting address (origin) of the program. Tells the assembler where to place the first instruction in memory.

END

END
Marks the end of the assembly language program. No instructions should follow this directive.

DEC (Decimal)

DEC N
Defines a signed decimal number. The assembler converts it to binary and stores it in memory.

HEX (Hexadecimal)

HEX N
Defines a hexadecimal number. The assembler converts it to binary format for storage.

BSS (Block Started by Symbol)

BSS N
Reserves N memory locations without initializing them. Used for declaring uninitialized variables.

EQU (Equate)

SYMBOL EQU VALUE
Assigns a symbolic name to a value or address. Creates constants for use throughout the program.
/ Example Assembly Program with Pseudo-Instructions

ORG 100 / Start program at address 100
LOAD, LDA X / Load value of X into AC
      ADD Y / Add value of Y to AC
      STA Z / Store result in Z
      HLT / Halt the program

   X, DEC 25 / Declare X = 25 (decimal)
   Y, HEX 1A / Declare Y = 26 (hex 1A)
   Z, BSS 1 / Reserve 1 location for Z
      END / End of program
🔄

Instruction Cycle

Computer instructions are executed through a sequence of subcycles:

1
FETCH
Get instruction from memory
2
DECODE
Interpret operation code
3
ADDRESS
Calculate effective address
4
EXECUTE
Perform the operation
💻

Programming Languages

Machine Language

Binary codes (0s and 1s) that the computer directly understands and executes.

Assembly Language

Symbolic program using operation codes and addresses instead of binary values.

Start Timing and Control