Computer Organization - Basic Computer Instructions
Computer organization refers to the way in which the components of a computer system are organized and interconnected to perform specific tasks. One of the most fundamental aspects of computer organization is the set of basic computer instructions that the system can execute.
Basic Computer Instructions
Basic computer instructions are commands given to a computer to perform specific tasks. These instructions are typically divided into three categories:
- Data Transfer Instructions: Move data between memory and registers (e.g., Load, Store).
- Arithmetic and Logic Instructions: Perform math or logic operations (e.g., Add, Subtract, AND, OR).
- Control Instructions: Guide the flow of the program (e.g., Jump, Branch, Call).
Data Transfer Instructions
These instructions deal with moving data from one location to another within the computer. Think of it as copying or transferring information between various components like memory, registers, or storage.
Common Data Transfer Instructions:
- Load: Copies data from memory to a register (temporary storage inside the CPU).
- Store: Transfers data from a register to memory.
- Move: Transfers data from one register to another.
Arithmetic and Logic Instructions
These instructions are used to perform mathematical and logical operations. They enable computers to handle calculations and make decisions based on certain conditions.
Arithmetic Instructions:
- Add: Adds two numbers.
- Subtract: Subtracts one number from another.
- Multiply: Multiplies two numbers.
- Divide: Divides one number by another.
Logic Instructions:
- AND: Compares two bits and returns 1 if both are 1; otherwise, returns 0.
- OR: Compares two bits and returns 1 if at least one is 1.
- NOT: Inverts a bit (1 becomes 0, and 0 becomes 1).
- XOR (Exclusive OR): Returns 1 if the bits are different, 0 if they are the same.
Control Instructions
Control instructions determine the flow of execution in a program. They guide the computer on which instruction to execute next, allowing flexibility in decision-making and repeated actions.
Common Control Instructions:
- Jump (JMP): Directs the program to execute a specific instruction elsewhere in the code.
- Conditional Branch: Jumps to another instruction only if a specific condition is true. Example: Branch if zero (BZ) or branch if not zero (BNZ).
- Call: Transfers control to a subroutine (a set of instructions performing a specific task) and returns afterward.
- Return: Brings back control to the main program after a subroutine is executed.
Instruction Set of a Basic Computer
The basic computer has 16-bit instruction register (IR) which can denote either memory reference or register reference or input-output instruction.
Memory Reference Instructions
These instructions refer to memory address as an operand. The other operand is always accumulator. Specifies 12-bit address, 3-bit opcode (other than 111) and 1-bit addressing mode for direct and indirect addressing.
Register Reference Instructions
These instructions perform operations on registers rather than memory addresses. The IR(14 - 12) is 111 (differentiates it from memory reference) and IR(15) is 0 (differentiates it from input/output instructions). The rest 12 bits specify register operation.
Input/Output Instructions
These instructions are for communication between computer and outside environment. The IR(14 - 12) is 111 (differentiates it from memory reference) and IR(15) is 1 (differentiates it from register reference instructions). The rest 12 bits specify I/O operation.
Essential Instructions in a Basic Computer
Program Counter (PC) is a key part of a computer, and its instructions are the basic tasks a computer performs. These instructions are handled by the computer's CPU (Central Processing Unit) and form the foundation for more complex operations. Some examples of basic PC instructions include:
Symbol | Hexadecimal Code | Description |
---|---|---|
AND | 0xxx, 8xxx | AND memory word to AC |
ADD | 1xxx, 9xxx | Add memory word to AC |
LDA | 2xxx, Axxx | Load memory word to AC |
STA | 3xxx, Bxxx | Store AC content in memory |
BUN | 4xxx, Cxxx | Branch Unconditionally |
BSA | 5xxx, Dxxx | Branch and Save Return Address |
ISZ | 6xxx, Exxx | Increment and skip if 0 |
CLA | 7800 | Clear AC |
CLE | 7400 | Clear E(overflow bit) |
CMA | 7200 | Complement AC |
CME | 7100 | Complement E |
CIR | 7080 | Circulate right AC and E |
CIL | 7040 | Circulate left AC and E |
INC | 7020 | Increment AC |
SPA | 7010 | Skip next instruction if AC > 0 |
SNA | 7008 | Skip next instruction if AC < 0 |
SZA | 7004 | Skip next instruction if AC = 0 |
SZE | 7002 | Skip next instruction if E = 0 |
HLT | 7001 | Halt computer |
INP | F800 | Input character to AC |
OUT | F400 | Output character from AC |
SKI | F200 | Skip on input flag |
SKO | F100 | Skip on output flag |
ION | F080 | Interrupt On |
IOF | F040 | Interrupt Off |
Note: In the given table,
- AC (Accumulator): A register that temporarily stores data during arithmetic or logic operations.
- E (Carry/Overflow Bit): A single-bit register used for carry operations or overflow detection in arithmetic calculations.
Example of Instruction Execution
- ADD Instruction:
Suppose the memory address0001
contains the value5
, and the AC currently holds10
. TheADD
instruction fetches the value from memory, adds it to the AC, and stores the result in the AC.
AC ← AC + M[0001]
Result: AC = 10 + 5 = 15
Uses of Basic Computer Instructions
- Data manipulation: Basic computer instructions are used to handle data in the computer system, including moving data between memory and the CPU.
- Control flow: Basic instructions guide the flow of a program by branching to different parts based on conditions.
- Input/output operations: Instructions are used to transfer data between the computer and external devices like keyboards, printers, or monitors.
- Program execution: They load programs into memory and control their execution by moving data in and out of the program.
- System maintenance: These instructions handle tasks like memory allocation, interrupt management, error detection and correction.
Issues of Basic Computer Instructions
- Complexity: Instructions can be hard to understand, especially for beginners, making programming challenging.
- Limited functionality: Basic instructions can handle only simple tasks. Programmers require to write extra code for complex operations.
- Compatibility: Instructions may vary across different computer systems This can require programmers to write separate code for each system, which can be time-consuming and inefficient.
- Security: Basic computer instructions can be vulnerable to security threats, such as buffer overflows and code injection attacks.
- Maintenance: Basic computer instructions can be difficult to maintain, particularly as systems become more complex and code becomes more extensive. This can require significant resources, time and effort.
Related Articles
- Computer Organization - Instruction Formats
- Computer Organization and Architecture Tutorials
- Computer Organization - Addressing Mode