banner
cos

cos

愿热情永存,愿热爱不灭,愿生活无憾
github
tg_channel
bilibili

Computer Organization Principles Review Summary (4) Instruction System

Chapter 4 Instruction System#

4.1 Development and Performance Requirements of Instruction Systems#

Basic Concepts of Instruction Systems

  • Instruction: A command for the computer to perform a certain operation. From the perspective of the hierarchical structure of computer organization, instructions can be classified into microinstructions, machine instructions, and macroinstructions.
    • Microinstruction is a command at the microprogram level, belonging to hardware;
    • Macroinstruction: A software instruction composed of several machine instructions, belonging to software;
    • Machine instruction: An instruction that lies between microinstructions and macroinstructions, usually referred to simply as an instruction.
  • Each instruction can complete an independent arithmetic or logical operation. The instructions discussed in this chapter are machine instructions.
  • The collection of all machine instructions in a computer is called the instruction system of that computer.
    • The instruction system is an important factor characterizing the performance of a computer. Its format and functionality not only directly affect the hardware structure of the machine but also directly impact the system software and the applicability of the machine.

4.1.1 Development of Instruction Systems#

Development Status#

  • In the 1950s, instruction systems had only a few to dozens of instructions for fixed-point addition and subtraction, logical operations, data transfer, and branching.

  • In the late 1960s, instructions for multiplication, division, floating-point, decimal, and string processing were added, increasing the number of instructions to one or two hundred, and addressing modes became more diverse, leading to the emergence of series computers.

  • By the late 1970s, most computers had instruction systems with hundreds of instructions, referred to as Complex Instruction Set Computers (CISC).

    • However, such a large instruction system not only lengthened the development cycle of computers, making it difficult to ensure correctness and easy debugging and maintenance, but also wasted hardware resources due to the use of many complex instructions with very low frequency, resulting in the so-called 80:20 rule of instruction sets.
    • That is, the most commonly used simple instructions account for only 20% of the total number of instructions, but they appear in programs 80% of the time.
  • Thus, the Reduced Instruction Set Computer (RISC) was proposed, which is easier to implement with VLSI technology.

4.1.2 Performance Requirements for Instruction Systems#

  • Completeness: Completeness means that the instruction system provides enough instructions directly for writing various programs in assembly language without needing software to implement them. Completeness requires that the instruction system is rich, fully functional, and easy to use. The most basic and essential instructions in a computer are few. Many instructions can be implemented using the most basic instructions.
  • Effectiveness: Effectiveness means that programs written using the instruction system can run efficiently. High efficiency is mainly reflected in the small storage space occupied by the program and fast execution speed.
  • Regularity: Regularity includes the symmetry, uniformity, consistency of instruction formats, and data formats in the instruction system.
    • Symmetry: All registers and memory units in the instruction system can be treated equally, and all instructions can use various addressing modes;
    • Uniformity: An instruction of a certain operation type can support various data types, such as arithmetic operation instructions that can support byte, word, double-word integer operations, decimal number operations, and single and double precision floating-point operations;
    • Consistency of instruction formats and data formats: The length of instructions and data has a certain relationship to facilitate processing and access. For example, the length of instructions and data is usually an integer multiple of byte length.
  • Compatibility: Different models of series machines have the same basic structure and a common basic instruction set, so the instruction system is compatible, meaning that basic software can be used across different models. However, due to the different release times of different models, there are structural and performance differences, making it impossible for all software to be fully compatible; it can only achieve "upward compatibility," meaning that software running on lower-end machines can run on higher-end machines.

4.2 Instruction Formats#

  • Instruction format: The structural form of the instruction word represented by binary code.
  • An instruction can reflect the following information:
    • What operation to perform
    • If operands are needed, where to fetch them from
    • Where to send the result, and where to fetch the next instruction from
  • Instruction format includes two aspects:
Opcode Field OPAddress Code Field A
Indicates the operational characteristics and functionality of the instructionSpecifies the address of the operands involved in the operation

4.2.1 Opcode#

  • When designing a computer, an opcode must be specified for each instruction in the instruction system.
  • The opcode OP of an instruction indicates what type of operation the instruction should perform, such as addition, subtraction, multiplication, division, fetching data, storing data, etc. Different instructions are represented by different encodings in the opcode field, with each encoding representing a specific instruction. For example, opcode 001 can be designated for addition; opcode 010 can be designated for subtraction.
  • The number of bits that make up the opcode field generally depends on the scale of the computer's instruction system. A larger instruction system requires more bits to represent each specific instruction. For example, if an instruction system has 32 instructions, then 5 bits are needed for the opcode. In general, an opcode containing n bits can represent a maximum of 2^n instructions.

4.2.2 Address Code (Key Point)#

  • Based on how many operand addresses are in an instruction, the instruction can be referred to as a certain number of operand instructions or address instructions.

Zero-address Instruction#

Opcode OP
Function: Instructions that do not require operands, such as "halt," "no operation," "clear," and other control instructions.

One-address Instruction#

Opcode OPOperand A1
Function Description: OP (A1) →A1
(AC) OP (A1) →AC
Implicitly assumes that the operand is in the accumulator AC.

Two-address Instruction#

Opcode OPOperand A1Operand A2
A1: Source/Destination operand address
A2: Destination/Source operand address
Function Description:
(A1) OP (A2)→A1
(A1) OP (A2)→A2

Two-address instructions are classified based on the physical location of the operands into:

  • SS Memory-to-Memory type
  • RS Register-to-Memory type
  • RR Register-to-Register type

Three-address Instruction#

OpcodeA1A2A3
A1: Address of the operand being operated on, also called the source operand address
A2: Operand address, also called the destination operand address
A3: Address for storing the operation result
Function Description: (A1) OP (A2)→A3

4.2.3 Instruction Word Length (Key Point)#

Concept#

  • Instruction Word Length: The number of bits in a binary code that makes up an instruction word.
  • Machine Word Length: The number of bits of binary data that a computer can process directly.
  • Single Word Length Instruction: An instruction whose word length is equal to the machine word length.
  • Half Word Length Instruction: An instruction whose word length is equal to half the machine word length.
  • Double Word Length Instruction: An instruction whose word length is equal to two machine word lengths.

Advantages and Disadvantages of Multi-word Length Instructions#

  • Advantages: Provide enough address bits to solve the addressing problem of accessing any memory unit;
  • Disadvantages: Must access memory twice or more to fetch a complete instruction, reducing the CPU's computation speed and occupying more storage space.
  • The advantages of using fixed-length instructions in the instruction system: All instruction word lengths are equal, the instruction word structure is simple, and the instruction word length is constant;
  • The advantages of using variable-length instructions: The lengths of various instruction words vary with the functionality of the instructions, the structure is flexible, and it can make full use of instruction length, but the control of instructions is more complex.
  • The problem generally assumes the machine word length is 16 bits, as shown below.
    Insert image description here

4.3 Operand Types#

4.3.1 General Data Types#

  • Address Data: Addresses are actually a form of data.
  • Numeric Data: The three commonly used types of numeric data in computers.
    • Fixed-point integers or fixed-point decimals, floating-point numbers, compressed decimal numbers.
  • Character Data: Text data or strings, currently widely using ASCII code.
  • Logical Data: A unit composed of several binary bits, where each bit can be 1 or 0. When data is viewed in this way, it is referred to as logical data.

4.4 Addressing Methods for Instructions and Data (Key Point!)#

  • In memory, the way operands or instruction words are written or read includes address specification, associative storage, and stack access methods. Almost all computers use address specification in memory.
  • Addressing method: The way to form the address of operands or instructions.
    • Instruction Addressing Method: Used to form the address of instructions in memory.
    • Data Addressing Method: Used to form the address of operands in memory.

4.4.1 Instruction Addressing Methods#

  • Sequential Addressing Method
  • Jump Addressing Method
    Insert image description here

4.4.2 Operand Addressing Methods#

The method of finding the actual operand based on the address code field given in the instruction, that is, the method of forming the effective address of the operand, is called the operand addressing method. For example, the structure of a single-address instruction is as follows:

Opcode OPIndex X   Indirect IFormal Address A
Addressing Method Feature BitOffset

The addressing process is the process of converting the formal address of the operand into the effective address of the operand.
Insert image description here

1. Implicit Addressing#

  • Feature: The address of the operand is not explicitly given in the instruction, but is implicitly indicated.
  • In the single-address instruction format, the address of the second operand is not specified in the instruction address field, but the accumulator AC is designated as the address of the second operand, making AC an implicit address.

2. Immediate Addressing#

  • Feature: Immediate addressing is a special addressing method where the address field of the instruction points to not the address of the operand, but the operand itself.
  • The data is contained within the instruction, so as soon as the instruction is fetched, the operand that can be used immediately is also fetched, thus such an operand is called an immediate value.
  • The operand contained in the instruction is immediately available, saving access time to memory.
  • Instruction format: Opcode OP Operand A
  • Example: Instruction mov ax, 100

3. Direct Addressing#

  • Feature: The address A given in the address code field of the instruction is the effective address EA of the operand, also known as the direct address, that is, EA = A.Insert image description here

4. Indirect Addressing#

  • Feature: The formal address A in the instruction address field is not the actual address of the operand, but an indicator of the operand's address, that is: the content of A is the effective address of the operand: EA = (A)【just nesting again(】
    Insert image description here

5. Register Addressing#

  • Feature: The operand is not in memory but is placed in a general-purpose register.
  • The operand address given in the instruction is not the memory address unit number, but the number of the general-purpose register, where the instruction's operand is stored in the corresponding register, that is, EA=R~i~Insert image description here

Advantages

  • Since registers are internal to the CPU, fetching operands from registers during instruction execution is much faster than accessing main memory;
  • Because the number of registers is limited, the number of bits used for register numbering is also small, thus effectively reducing the length of the address code field of the instruction.

6. Register Indirect Addressing#

  • Feature: The content of the register in the instruction is not the operand but the address of the operand, with the actual operand located in memory. That is, the operand is placed in main memory, while the address of the operand is stored in a general-purpose register, and the number of that general-purpose register is given in the address code part of the instruction, resulting in EA=(Ri)【nesting again(】
    Insert image description here

  • Advantages: Instructions using this addressing method are shorter, and after fetching the instruction, only one memory access is needed to obtain the operand, making the instruction execution speed faster than the aforementioned indirect addressing method. This is also a widely used addressing method in computers today.

7. Offset Addressing#

  • A combination of direct addressing and register indirect addressing.
  • Effective Address: EA = A + (R), where A is the formal address.
    • Requires that the instruction has two address fields, with at least one being explicit.
    • The formal address A is used directly.
  • The three commonly used types of offset addressing are:
    • Relative addressing, base addressing, and indexed addressing.
  • Relative Addressing: The base address is provided by the program counter PC, and the relative displacement D is given in the instruction's address code part. The effective address of the operand is obtained by adding the two, that is: EA = (PC) + D. The content of the program counter is the address of the current instruction.Insert image description here
  • Base Addressing: The bit length of the base address register can be set long enough to address a larger memory space.Insert image description here
  • Indexed Addressing: Indexed addressing adds the base address A given in the instruction's address code part to the content of a specific index register Rx in the CPU to form the effective address of the operandInsert image description here

8. Segment Addressing Method#

  • Microcomputers use segment addressing, which is essentially base addressing.
  • The 1MB main memory space is divided into several segments of a maximum length of 64KB. When addressing a specific memory unit, the actual 20-bit physical address is formed by adding a base address register (segment register) to the 16-bit offset provided in the instruction.
    Insert image description here

9. Stack Addressing#

  • A temporary storage unit that can store data.
  • Two Forms: Register Stack and Memory Stack
  • Storage Principle: First In, Last Out
  • Data access is done through the stack top, requiring an implicit or explicit stack pointer (top of the stack pointer).
  • Stack Instructions: PUSH, POP

[Example 4] The structure of a two-address RS-type instruction is as follows:
6 bits   4 bits         1 bit  2 bits   16 bits
OP   General Register     I   X   Offset D
 Where I is the indirect addressing flag, X is the addressing mode field, and D is the offset field. Through the combination of I, X, and D, the following addressing methods can be formed:
Insert image description here
Please list the names of the six addressing methods.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.