Computer Organization and Architecture - Instruction Sets
Machine Instruction Characteristics
- The processor's operation is dictated by the instructions it executes, known as machine or computer instructions.
- The instruction set is the collection of different instructions a processor can execute.
- Each instruction provides the processor with necessary execution information.
Elements of a Machine Instruction
- Operation Code (Opcode):
- Specifies the operation. Specified by a binary code.
- Source Operand Reference:
- Input operands for the operation.
- Result Operand Reference:
- The operation's output.
- Next Instruction Reference:
- Tells the processor where to fetch the next instruction after completing the current one.
Instruction Cycle State Diagram
- The instruction cycle includes stages like instruction address calculation, instruction fetch, operand address calculation, operand fetch, data operation, operand store, and instruction complete.
Source and Result Operands
- Location of Operands:
- Main or virtual memory: The instruction supplies the memory address.
- I/O device: The instruction specifies the I/O module and device (or memory-mapped address).
- Processor register: Instruction contains the register number or name.
- Immediate: The operand value is within the instruction itself.
Instruction Representation
Instructions are represented by bit sequences, divided into fields.
Fields correspond to the instruction's constituent elements (opcode, operands).
Example: A simple instruction format:
- Opcode (e.g., 4 bits)
- Operand Reference 1 (e.g., 6 bits)
- Operand Reference 2 (e.g., 6 bits)
- Other data/address information (e.g., 16 bits)
Mnemonics
- Opcodes are represented by abbreviations called mnemonics (e.g., ADD, SUB, MUL, DIV, LOAD, STOR).
- Operands are also represented symbolically.
- Programmers specify the location of each symbolic operand.
Instruction Types
- Data Processing: Arithmetic and Logic instructions.
- Arithmetic instructions: Computational capabilities for processing numeric data.
- Logic (Boolean) instructions: Operate on bits of a word, processing any data type.
- Data Storage: Movement of data into/out of registers/memory.
- Data Movement: I/O instructions for transferring programs/data into memory and results to the user.
- Control: Test and Branch instructions.
- Test instructions: Test value of data or computation status.
- Branch instructions: Branch to different instruction sets based on decisions.
Instruction Address Examples
Different address instructions impact how operations are performed.
Examples:
- Three-address: (Each instruction specifies two source operands and a destination)
- Two-address: Requires overwriting one operand. MOVE instruction copies values.
- One-address: Accumulator (AC) is implied. Requires LOAD and STOR instructions.
Utilization of Instruction Addresses (Nonbranching Instructions)
- Table summarizing instruction address utilization:
- OP A, B, C implies
- OP A, B implies
- OP A implies
- OP implies
Instruction Set Design
- Fundamental design issues:
- Operation repertoire: Types and complexity of operations.
- Data types: Types of data operations are performed on.
- Instruction format: Length, number of addresses, field sizes.
- Registers: Number of processor registers and their use.
- Addressing: Modes for specifying operand addresses.
Types of Operands
- Addresses
- Numbers
- Characters
- Logical Data
Numbers
- Machine languages include numeric data types with magnitude and precision limits.
- Numeric data types:
- Binary integer or binary fixed point
- Binary floating point
- Decimal (Packed decimal): Each decimal digit is represented by a 4-bit code, with two digits per byte.
Characters
- Character strings are a common data form.
- Character codes:
- International Reference Alphabet (IRA) / ASCII
- Extended Binary Coded Decimal Interchange Code (EBCDIC) (used on IBM mainframes)
Logical Data
- An n-bit unit consisting of n 1-bit items of data, each item having the value 0 or 1
- Advantages of bit-oriented view:
- Efficient memory use for Boolean/binary data arrays.
- Ability to manipulate data item bits.
Single-Instruction-Multiple-Data (SIMD) Data Types
- Introduced in x86 architecture for multimedia application performance.
- Extensions include MMX (multimedia extensions) and SSE (streaming SIMD extensions).
- Data types:
- Packed byte/word/doubleword/quadword integers
- Packed single/double-precision floating-point
Processor Actions for Various Types of Operations
- Data Transfer: Transfer data from one location to another.
- Arithmetic: Perform function in ALU, set condition codes/flags.
- Logical: Similar to arithmetic.
- Conversion: Convert data formats.
- Transfer of Control: Update program counter, manage parameter passing for subroutines.
- I/O: Issue command to I/O module.
Data Transfer
- Instruction must specify source/destination locations, data length, and addressing modes.
Arithmetic
- Basic operations (add, subtract, multiply, divide) for signed integers.
- Often provided for floating-point and packed decimal numbers.
- Single-operand instructions:
- Absolute: Absolute value of operand.
- Negate: Negate operand.
- Increment: Add 1 to operand.
- Decrement: Subtract 1 from operand.
Basic Logical Operations
Basic logical operations are NOT, AND, OR, XOR, and Equality.
Truth Table:
- P Q | NOT P | P AND Q | P OR Q | P XOR Q | P = Q
- 0 0 | 1 | 0 | 0 | 0 | 1
- 0 1 | 1 | 0 | 1 | 1 | 0
- 1 0 | 0 | 0 | 1 | 1 | 0
- 1 1 | 0 | 1 | 1 | 0 | 1
Shift and Rotate Operations
Shift and rotate operations manipulate bits within data.
Types:
- Logical shift (left/right): Fill with zeros.
- Arithmetic shift (left/right): Sign extension for right shift.
- Rotate (left/right): Wrap bits around.
Examples of Shift and Rotate Operations
- Examples illustrating logical/arithmetic shifts and rotates.
Conversion
- Instructions change data format.
- Example: Decimal to binary conversion.
- Complex Example: EAS/390 Translate (TR) instruction.
Input/Output
- Approaches:
- Isolated programmed I/O
- Memory-mapped programmed I/O
- DMA
- Use of an I/O processor
- Implementations provide a few I/O instructions with specific actions defined by parameters/codes.
System Control
- Instructions executed in privileged states/memory areas.
- Reserved for operating system use.
- Examples:
- Read/alter control register
- Modify storage protection key
- Access process control blocks
Transfer of Control
- Reasons for transfer-of-control operations:
- Execute instructions multiple times
- Decision making in programs
- Breaking tasks into smaller pieces
- Common operations:
- Branch
- Skip
- Procedure call
Branch Instructions
- Branch instructions can be conditional or unconditional, altering the flow of execution based on conditions or addresses.
Skip Instructions
- Skip instructions increment the program counter to skip the next instruction.
- Example: Increment-and-skip-if-zero (ISZ).
Procedure Call Instructions
- Self-contained programs invoked by a larger program.
- Economy: Reuse code.
- Modularity: Break down tasks.
- Involves:
- Call instruction: Branches to procedure.
- Return instruction: Returns from procedure.
Nested Procedures
- Nested procedures involve calls to procedures within procedures.
Use of Stack to Implement Nested Procedures
- Stack is used to manage return addresses and parameters during nested procedure calls.
Stack Frame Growth
- Stack frames are used to store return points, old frame pointers, and local variables for procedures.
x86 Single-Instruction, Multiple-Data (SIMD) Instructions
- Intel introduced MMX technology in 1996 for multimedia tasks.
- MMX is a set of optimized instructions for multimedia.
- Video/audio data are composed of arrays of small data types.
- New data types:
- Packed byte
- Packed word
- Packed doubleword
- Each data type is 64 bits long and consists of multiple smaller data fields, each of which holds a fixed-point integer.
Image Compositing on Color Plane Representation
Example of MMX code sequence for image compositing involves:
*Unpacking byte R pixel components from images A and B.
*Subtracting image B from image A.
*Multiplying result by fade value.
*Adding image B pixels.
Packing new composite pixels back to bytes.