Computer Architecture and Instructions Guide
Computer Architecture and Instructions Guide
Computer instruction
They can be categorized into two elements as Operation codes (Opcodes) and
Address. Opcodes specify the operation for specific instructions. An address
determines the registers or the areas that can be used for that operation.
Operands are definite elements of computer instruction that show what
information is to be operated on.
Instruction code structure
Opcode: A group of bits that defines the operation to be performed, such as addition,
subtraction, or a logical shift. The number of bits in the opcode determines the total
number of different operations the processor can perform.
Address: A group of bits that specifies the location of the data, or operand, on which
the operation is to be performed. This data can be numbers, characters, or even the
address of another location in memory.
Addressing mode: A field that determines how the address is interpreted, specifying
whether the address is direct, indirect, or immediate, among other methods.
Computer registers
Computer registers are small, high-speed storage locations built directly into the CPU used for
temporarily holding data, instructions, and memory addresses during processing. They are the
fastest type of memory in a computer, allowing the CPU to access critical information almost
instantly to execute instructions efficiently. Common types include the program counter, which
stores the address of the next instruction, the instruction register, which holds the current
instruction, and the memory address register, which holds a memory address for the CPU.
Store instructions: Registers hold instructions that are being executed or are about to be
executed.
Keep track of memory: They store memory addresses to allow the CPU to fetch or store data.
Program Counter (PC): Holds the memory address of the next instruction to be executed.
Instruction Register (IR): Holds the current instruction being executed by the CPU.
Memory Address Register (MAR): Holds the memory address of the data or instruction the CPU
wants to access.
Memory Buffer Register (MBR) / Memory Data Register (MDR): Holds the data being
transferred to or from memory.
Stack Pointer: Keeps track of the current position in the stack, a region of memory used for
function calls and local variables.
Instruction Cycle
The instruction cycle is the fundamental process for a CPU to execute a single instruction, which
is also known as the fetch–decode–execute cycle.
Fetch:
The CPU retrieves the next instruction from the memory address indicated by the program counter
(PC). The instruction is then loaded into the instruction register, and the PC is incremented to
point to the next instruction.
Decode:
The CPU's control unit decodes the instruction to understand what operation is required and which
operands (data) are needed.
Execute:
The CPU performs the action specified by the instruction, such as an arithmetic calculation or a
data transfer. This step may also involve fetching operands from memory, which is sometimes
called the "read effective address" phase.
The result of the execution is written back to a register or memory if the instruction requires it. This
step is sometimes included in the execute phase or treated as a separate stage in more complex
pipelines.
Repeat:
After the instruction is fully executed and any results are stored, the cycle begins again with the
next instruction pointed to by the program counter.
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 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
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.
Input-Output Interrupt
I/O Configuration
The terminals send and receive serial information. Each portion of serial data has
eight bits of alphanumeric code, where the leftmost bit is continually 0. The serial
data from the input register is transferred into the input register INPR. The output
register OUTR can save the serial data for the printer. These two registers interact
with the Accumulator (AC) in parallel and with a communication interface in a
serial structure.
The output register OUTR works equivalent to the input register INPR.
The flow of data by the OUTR is the opposite of INPR. Therefore, the output flag
FGO is set to 1 originally. The device tests the flag bit; if it is 1, the data from AC
is sent in parallel to OUTR, and FGO is cleared to 0. The new data cannot be
loaded into OUTR when the FGO is 0 because this condition denotes that the
output device is in the procedure of printing a character.
A Central Processing Unit (CPU) is the primary component of a computer, often called
the "brain," that executes instructions and performs calculations, logic, and data
management. It handles the majority of a computer's processing tasks, from running the
operating system and applications to making simple operations like typing a character
appear on the screen possible. The CPU receives instructions from memory, processes
them, and sends the results to other parts of the system, significantly impacting the overall
speed and efficiency of the device.
The CPU reads and processes instructions from computer programs, which are lists of
commands.
Performs calculations:
It handles the basic arithmetic and logical operations required for all computing tasks.
It controls the flow of data between different components of the computer system.
Controls other parts:
It sends signals to coordinate the actions of other hardware components, similar to how
a brain controls a body.
General Register Organization uses multiple general-purpose registers for fast data access,
allowing flexibility in source/destination selection, while Stack Organization uses a LIFO (Last-
In, First-Out) structure with push and pop operations, managed by a Stack Pointer , ideal for
expression evaluation and function calls but limited by fixed size. Both are CPU design types, with
general registers offering speed and flexibility, and stacks providing efficient data management
for specific tasks.
How it Works: Instructions specify which registers to use (e.g., ADD R1, R2, R3 for R1 ← R2
+ R3 ), enabling complex operations with fewer memory accesses.
Control: A control unit uses selection lines (like SELA , SELB , SELD ) to route data from
registers to the ALU and store results back into a destination register.
Advantages: Faster execution due to data locality, efficient for complex instructions, fewer
memory references.
Stack Organization
Concept: A hardware stack (memory locations + Stack Pointer register) follows the LIFO
principle, like a stack of plates.
Operations:
o Push: Adds an item to the top of the stack, incrementing the Stack Pointer (SP).
Instruction Format: Often uses zero-address instructions (operands implicitly on the stack),
reducing instruction size.
Advantages: Simplifies complex expressions (e.g., function calls, expression evaluation),
compact instructions.
Instruction formats are the bit patterns of instructions, defining the layout of an
operation code and its operands. The primary types are classified by the number of
addresses they contain: zero, one, two, and three-address instructions, with each format
specifying how data is accessed and manipulated.
These instructions do not have an address field, as the operands are implicitly stored,
often in a stack.
Example: A PUSH A instruction pushes the value of A onto the stack.
One-Address Instruction Format:
Uses a single address field and implicitly uses a special register, the accumulator, to
perform operations.
Example: LOAD C might load the value from memory location C into the accumulator,
and ADD B would then add the value of B to the accumulator.
Two-Address Instruction Format:
Uses two address fields. The destination is often the first operand, and the second
operand is the source.
Example: MOV R1, A moves the content of memory location A into register R1. A
subsequent ADD R1, B would add the content of B to R1, storing the result in R1.
Three-Address Instruction Format:
Specifies two source operands and a destination for the result.
Example: ADD R1, A, B adds the values from memory locations A and B, storing the
result in register R1.
Addressing Modes
Addressing modes are techniques used by the CPU to identify the location of
the operand(s) needed for executing an instruction. They provide rules for
interpreting the address field in an instruction, helping the CPU fetch
operands correctly.
Opcode – Tells the CPU what operation to perform (e.g., ADD, MOV).
Operands – The data or addresses on which the operation is performed.
It is used for special instructions or control commands like CLA, PUSH, and
RET, where the operand is automatically known from the instruction itself
Immediate Addressing
The operand is the part of the instruction itself. It is used when the value is
known while writing the program.
Example: MOV R1, #5 moves the value 5 into register R1, where #5 is the
immediate value.
Direct Addressing
The instruction contains the memory address of the operand. The CPU
accesses the data directly from that address.
Example: LOAD R1, 1000 loads data from memory address 1000 into register
R1.
Indirect Addressing
The instruction contains the address of a register or memory location that
holds the actual address of the operand. The CPU first fetches this address,
then accesses the operand.
Example: LOAD R1, (R2) loads data from the memory location whose
address is in register R2.
Register Addressing
The operand is located in a CPU register specified by the instruction.
Step:
The instruction specifies a register (R).
The CPU takes operand directly from register R.
Step:
The instruction specifies a register.
This register holds the address (A).
The CPU fetches the operand from memory location A.
Exchange ( XCHG or XCH ): Swaps the contents of two locations, such as two registers or a
register and memory.
Push ( PUSH ): Places data onto the top of a stack, typically used for temporary storage or function
calls.
Pop ( POP ): Retrieves data from the top of a stack and moves it to a register.
1. Arithmetic instructions
Perform mathematical operations on data.
Examples include ADD, SUB (subtract), MUL (multiply), DIV (divide), INC (increment),
and DEC (decrement).
Examples include:
o AND, OR, XOR (exclusive-or)
3. Shift instructions
Move bits within a register to the left or right.
Types include:
o Logical shift: Shifts bits and inserts zeros in the vacated positions. For
example, SHL (Shift Left) and SHR (Shift Right).
o Arithmetic shift: Shifts bits but preserves the sign bit during a right shift for signed
numbers.
o Rotate: Shifts bits while "rotating" the bits that are shifted out of one end back into the
other end, sometimes including the carry bit ( ROL, ROR, RORC, ROLC).
Single-cycle execution: Most instructions can be completed in one clock cycle, leading to faster
processing.
Fixed-length instructions: Instructions are typically of a fixed length, which simplifies the
instruction pipeline and allows for parallel execution.
Load/store architecture: Only specific "load" and "store" instructions access memory. Other
instructions operate on data that is already in registers, which speeds up execution.
Software-centric design: Compilers are responsible for breaking down complex tasks into many
simple instructions, which is a key part of the RISC design philosophy.
Advantages of RISC:
Simpler design: The simplified instruction set makes processor design easier and more efficient.
Faster execution: Simple instructions and single-cycle execution lead to faster overall
performance.
Efficient pipelining: The fixed length and simplicity of instructions make it easier to implement
the instruction pipeline technique, where multiple instructions are in different stages of execution
simultaneously.
Disadvantages of RISC:
More instructions: A single complex task may require a larger number of instructions compared
to CISC, potentially increasing program length.
Compiler dependency: The efficiency of the system heavily relies on the compiler's ability to
effectively translate high-level code into the RISC instruction set.
RISC Vs CISC
RISC (Reduced Instruction Set Computer) and CISC (Complex Instruction Set Computer) are two
processor design philosophies that differ in their instruction sets. RISC uses a small set of simple,
fixed-length instructions that execute in a single clock cycle, while CISC uses a large set of
complex, variable-length instructions that can take multiple clock cycles to execute. The primary
trade-off is between a simpler design (RISC) that requires more instructions per task and a more
complex design (CISC) that requires fewer instructions but is slower per instruction.
RISC and CISC are two different ways of designing computer processors.
RISC uses a small set of simple, fixed-size instructions designed to
execute in a single clock cycle.
CISC includes a larger set of instructions, many of which are complex and
can perform multiple operations (e.g., memory access and computation)
in a single instruction.
CISC instructions often require multiple clock cycles.
Instruction Set Small, simple, and limited number of Large, complex instructions that can
instructions. perform multiple operations.