Docsity

Microprocessor Programming: Instruction Formats, RISC vs CISC, Control Unit and Pipelining, Study notes of Computer science

Toggle sidebar
bg1
1. Instruction Formats
An instruction in a computer is made up of groups called fields. Each field carries different
information that tells the CPU what to perform. The most common fields are:
• Operation field – specifies the operation to be performed (e.g., addition).
• Address field – contains the location of the operand (register or memory location).
• Mode field – specifies how the operand is to be found.
Instructions are of variable length depending on the number of addresses they contain. Based on
the number of address fields, CPU organization is generally of three types:
• Single Accumulator organization – operation involves a special register called the
accumulator.
• General Register organization – multiple registers are used for computation.
• Stack organization – operations work on a stack basis, so no address field is required.
A blend of these organizations is mostly what is seen in real systems, rather than only one being
applied.
1.1 Zero Address Instructions
A stack-based computer does not use the address field in the instruction. All arithmetic operations
take place using the top one or two positions of the stack.
To evaluate an expression, it is first converted to Reverse Polish Notation (Postfix Notation).
Expression: X = (A+B)*(C+D) → Postfix: AB+CD+*
(TOS = Top of Stack, M[X] = any memory location)
Instruction
Operation
PUSH A
TOP = A
PUSH B
TOP = B
ADD
TOP = A+B
PUSH C
TOP = C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Microprocessor Programming: Instruction Formats, RISC vs CISC, Control Unit and Pipelining and more Study notes Computer science in PDF only on Docsity!

1. Instruction Formats

An instruction in a computer is made up of groups called fields. Each field carries different information that tells the CPU what to perform. The most common fields are:

  • Operation field – specifies the operation to be performed (e.g., addition).
  • Address field – contains the location of the operand (register or memory location).
  • Mode field – specifies how the operand is to be found.

Instructions are of variable length depending on the number of addresses they contain. Based on the number of address fields, CPU organization is generally of three types:

  • Single Accumulator organization – operation involves a special register called the accumulator.
  • General Register organization – multiple registers are used for computation.
  • Stack organization – operations work on a stack basis, so no address field is required.

A blend of these organizations is mostly what is seen in real systems, rather than only one being applied.

1.1 Zero Address Instructions

A stack-based computer does not use the address field in the instruction. All arithmetic operations take place using the top one or two positions of the stack.

To evaluate an expression, it is first converted to Reverse Polish Notation (Postfix Notation).

Expression: X = (A+B)(C+D) → Postfix: AB+CD+**

(TOS = Top of Stack, M[X] = any memory location)

Instruction Operation

PUSH A TOP = A PUSH B TOP = B

ADD TOP = A+B PUSH C TOP = C

Instruction Operation

PUSH D TOP = D ADD TOP = C+D

MUL TOP = (C+D)*(A+B) POP X M[X] = TOP

1.2 One Address Instructions

This format uses an implied ACCUMULATOR (AC) register for data manipulation. One operand is in the accumulator and the other is in a register/memory location. 'Implied' means the CPU already knows one operand is in the accumulator, so it need not be specified.

Format:

Opcode Operand/address of operand mode

Expression: X = (A+B)*(C+D) (AC = accumulator, M[] = memory location, M[T] = temporary location)

Instruction Operation

LOAD A AC = M[A] ADD B AC = AC + M[B]

STORE T M[T] = AC

LOAD C AC = M[C] ADD D AC = AC + M[D]

MUL T AC = AC * M[T] STORE X M[X] = AC

1.3 Two Address Instructions

Common in commercial computers. Two addresses can be specified in the instruction. Unlike one- address instructions (where the result is stored in the accumulator), here the result can be stored at different locations — but this requires more bits to represent the address. The destination address can also contain an operand.

Format:

to perform tasks — some are simple read, write, and move commands directing data to different hardware elements.

2.2 Instruction Set Architecture (ISA)

  • The ISA acts as an interface between hardware and software — specifying both what the processor can do and how it is done.
  • It is the only way a user can interact with the hardware; it can be viewed as a programmer's manual, since it is the part of the machine visible to the assembly language programmer, compiler writer, and application programmer.
  • The ISA defines: supported data types, registers, how hardware manages main memory, key features (e.g., virtual memory), which instructions the processor can execute, and the I/O model.
  • The ISA can be extended by adding instructions/capabilities, or by supporting larger addresses and data values.

Instructions are made up of a specific number of bits. For example, an 8-bit instruction may have the first 4 bits as the operation code (what to do) and the next 4 bits as the operand (data to use). Instruction length can vary from as few as 4 bits to several hundred, and can differ between instructions within the same ISA.

2.3 Instruction Set Types

  • CISC (Complex Instruction Set Computer): Has an additional microcode / microprogramming layer where instructions act as small programs. Programmable instructions are stored in fast memory and can be updated. More instructions are included than in other types. A single instruction can trigger multiple actions (e.g., one ADD command launching multiple memory load/store instructions).
  • RISC (Reduced Instruction Set Computer): Uses hard-wired control; does not require microcode, but has a larger base instruction set of simple instructions with a fixed instruction format. RISC processors are designed to process faster and more efficiently.
  • Enhancement instruction sets: Introduced in 1996; used in marketing to describe enhanced multimedia performance of Intel CPUs.

2.4 CISC vs RISC (detailed comparison)

Note: A concise RISC vs CISC table also appears in Section 8.4 as given directly in the teacher's handwritten notes (M-2(1).pdf); this expanded table below is from PART_A.pdf for additional reference.

CISC RISC

Has a microprogramming unit Has a hard-wired unit of programming Instruction set has many different Instruction set is reduced; most

CISC RISC

instructions used for complex operations

instructions are very primitive

Performance optimized with emphasis on hardware

Performance optimized with emphasis on software Only single register set Multiple register sets are present

Mostly less or not pipelined Highly pipelined Execution time is very high Execution time is very less

Code expansion is not a problem Code expansion may create a problem Decoding of instructions is complex Decoding of instructions is simple

Requires external memory for calculations

Doesn't require external memory for calculations

Examples: System/360, VAX, AMD, Intel x

Examples: ARC, Alpha, ARM, AVR, PA-RISC, SPARC

Instructions can take several clock cycles

Single-cycle for each instruction

Complex and variable-length instructions

Simple, standardized instructions

A large number of instructions A small number of fixed-length instructions

Compound addressing modes Limited addressing modes Applications: Smartphones, PDAs Applications: Security systems, Home automation

3. Processor Organization & Instruction Cycle

3.1 Requirements of the CPU

To understand CPU organization, consider what the CPU must do:

  • Fetch instruction – read an instruction from memory.
  • Interpret instruction – decode it to determine what action is required.
  • Fetch data – may require reading data from memory or an I/O module.
  • Process data – may require performing arithmetic/logical operations on data.

◦ Decode the instruction – the opcode defines the instruction type (data processing, memory access, etc.). ◦ Fetch the operands – based on opcode and instruction format, the control unit determines what operands are needed and where to fetch them from.

The Execute Phase

The last phase — the actual operation specified by the instruction is performed. For data- processing instructions, operands pass through the ALU/other data manipulation units. At the end, the result is stored in data memory or a CPU register (depending on architecture/instruction).

3.3 Instruction Cycle with Interrupt Processing

An Interrupt is a signal that temporarily stops the normal execution of a program so the CPU can respond to an urgent event. After servicing the interrupt, the CPU resumes execution of the interrupted program.

Interrupt Cycle: After executing each instruction, the CPU checks whether an interrupt request is pending.

  • If no interrupt: CPU fetches the next instruction.
  • If interrupt present: CPU starts the interrupt cycle.

4. Control Unit Design

The control unit generates control signals in two organizations:

  • Hardwired Control Unit
  • Microprogrammed Control Unit

4.1 Hardwired Control Unit

  • Implemented using gates, flip-flops, and decoders in hardware.
  • Much faster than the microprogrammed control unit.
  • Preferred in RISC architecture.

Advantages

  • Fast, as control signals are generated using hardware.
  • High performance.

Disadvantages

  • Control signals required by the CPU are more complex.
  • Modification of control signals is very difficult.
  • Difficult to correct mistakes in the original design; adding new features to an existing design is difficult.

There are different methods to implement a hardwired control unit:

  • State Table method
  • Delay Element method

How the Hardwired Control Unit Works

To interpret instructions and generate control signals for them, the control unit uses fixed logic circuits. To generate signals, these circuits use the contents of the control step counter, instruction register, and condition (code) flags, along with external input signals such as interrupt signals.

  • The fixed logic circuit is a combinational circuit made from decoders and encoders; it generates output based on the state of its inputs.
  • The decoder decodes the instruction loaded in the IR and generates a signal that serves as input to the encoder.
  • External inputs and conditional codes also act as inputs to the encoder.
  • The encoder then generates the control signals based on all the inputs.
  • After execution of each instruction, an end signal is generated which resets the state of the control step counter, making it ready for the next instruction.

4.3 Microprogramming

Microprogramming is the process of writing microcode for the control memory of the control unit in the CPU.

  • Control memory stores the microprogram.
  • A microprogram is a set of microinstructions.
  • Each line (location) of control memory stores a microinstruction.
  • A microinstruction specifies one or more micro-operations.
  • In horizontal microinstruction format, each bit represents a control signal.
  • In vertical microinstruction format, each microinstruction represents control signals in encoded form.

4.4 Microinstruction Sequencing & Execution

Microinstruction sequencing is the method of determining the flow of the microprogram.

Need for Designing the Microinstruction Sequencing Technique

  • First purpose: minimize the size of control memory, since control memory is present inside the CPU.
  • Second purpose: execute microinstructions as fast as possible — i.e., the address of the next microinstruction should be calculated as fast as possible.

Techniques based on the number of addresses utilized for sequencing:

  • Two Address Field (Dual Address Field)
  • Single Address Field
  • Variable Format

4.5 Microprogrammed Control Unit

The microprogrammed control unit produces control signals using microinstructions.

  • A program is a set of instructions; an instruction requires a set of micro-operations.
  • Micro-operations are performed using control signals.
  • These control signals are generated using microinstructions.
  • Microprograms for all instructions are stored in a small memory inside the CPU called control memory.
  • The set of microinstructions is stored in the control memory.
  • The control address register contains the address of the next microinstruction to be read.
  • When a microinstruction is read from control memory, it is transferred to a control buffer register.
  • A sequencing unit loads the control address register and issues a read command.

Advantages

  • Main advantage is flexibility.
  • Any change in the control unit can be made simply by changing the microinstructions.
  • Reduction in size of control memory.

4.6 Difference between Hardwired and Microprogrammed Control Unit

Attributes Hardwired Control Unit Microprogrammed Control Unit Speed Speed is fast Speed is slow

Cost of Implementation

More costly Cheaper

Flexibility Not flexible to accommodate new system specifications

More flexible to accommodate new system specifications

Ability to handle complex instructions

Difficult to handle complex instructions

Easier to handle complex instructions Decoding Complex decoding and sequencing logic

Easier decoding and sequencing logic

Applications RISC Microprocessor CISC Microprocessor

Control memory Absent Present Chip area required Less More

Occurrence (of error) Occurrence of error is more Occurrence of error is less

  • Hardwired control unit induces control signals directly; microprogrammed control unit induces them through microinstructions.
  • Hardwired CU is hard to modify; microprogrammed CU is easy to modify.
  • Hardwired CU can use only limited instructions; microprogrammed CU can generate control signals for many instructions.

5. Micro-operations

Instruction execution is operationally divided into smaller logical tasks called micro-operations. Therefore, an instruction can be seen as a sequence of micro-operations.

A micro-operation is a fundamental action performed by a machine on data stored in a register, as a step toward instruction execution.

Example (from PART_B.pdf) — LOAD R1, [0500] is executed through the micro-instructions: Read Address → Access Memory → Read Data → Load into Register → Next Instruction.

5.1 Register Transfer Micro-operation

Transfers information from one register to another register.

Example: R2 ← R1 (R1 = source, R2 = destination) and R1 ← R2 (R2 = source, R1 = destination)

  • Operation R2 ← R1 is performed using control signals: R1out, R2in
  • Operation R1 ← R2 is performed using control signals: R2out, R1in

5.2 Arithmetic Micro-operations

Arithmetic micro-operations are performed by the ALU inside the CPU. They perform basic arithmetic operations on numeric data — addition, subtraction, complement, 2's complement, addition with 2's complement, increment, decrement.

Symbolic Designation Description R3 ← R1 + R2 Contents of R1 + R2 transferred to R3.

R3 ← R1 - R2 Contents of R1 - R2 transferred to R3.

R1 ← R1 + 1 Increment the contents of R1 by 1. R1 ← R1 - 1 Decrement the contents of R1 by 1.

Example: Addition micro-operation R3 ← R1 + R2 is broken down as (M-2(1).pdf):

6. Functional Requirements of a Control Unit

The functional requirements of the control unit are the functions it must perform. A three-step process characterizes the Control Unit:

  • Define the basic elements of the processor.
  • Describe the micro-operations that the processor performs.
  • Determine the functions the control unit must perform to cause the micro-operations to be performed.

6.1 Basic Elements of the Processor

  • ALU: the functional essence of the computer.
  • Registers: used to store data internal to the CPU.

6.2 Types of Micro-operations

  • Transfer data between registers.
  • Transfer data from register to external.
  • Transfer data from external to register.
  • Perform arithmetic or logical operations.

6.3 Functions of Control Unit

The control unit performs two tasks:

  • Sequencing: Causes the CPU to step through a series of micro-operations in the proper sequence, based on the program being executed.
  • Execution: Causes each micro-operation to be performed.

7. Examples of Microprograms

7.1 ADD (R3), R1 [M(R3) ← M(R3) + R1]

Sequence of micro-operations needed to execute this instruction:

  • μop 1: R3out, MARin CPU
  • μop 2: MARout, RAM address, RAM #RD control signal
  • μop 3: RAMout, MDRin
  • μop 4: MDRout, ALUin
  • μop 5: R1out, Yin, ALU function ADD
  • μop 6: Zout, MDRin
  • μop 7: MARout, RAM address, RAM #WR control signal
  • μop 8: MDRout, RAMin

7.2 MUL R1, R2 [R1 ← R1 * R2]

  • μo1: R1out, ALUin
  • μo2: R2out, Yin, ALU function MUL
  • μo3: Zout, R1in

7.3 ADD R1, R2 [R1 ← R1 + R2]

  • μo1: R1out, ALUin
  • μo2: R2out, Yin, ALU function ADD
  • μo3: Zout, R1in

8. Flynn's Classification & Parallel Processing

8.1 Parallel Processing Concept

Parallel processing increases the computational speed of computer systems by performing multiple data-processing operations simultaneously. For example, while one instruction is being executed in the ALU, the next instruction can be read from memory. A system may have two or more ALUs to execute multiple instructions at the same time.

Parallel processing capacity increases along with system cost, but technological development has reduced hardware costs, making parallel processing economically feasible. It derives from multiple levels of complexity. Applications include:

  • VLSI Design (Processor Design)
  • Weather Forecasting
  • Military Applications

8.3 SISD — Single Instruction stream, Single Data stream

Only one instruction stream and one data stream exist. The CPU can be visualized as made up of two parts: Data Processing Unit (DPU) and Control Unit (CU).

  • The DPU deals with data and consists of the ALU and the data path; it accesses the data stream from memory bidirectionally.
  • The control unit deals with the instruction stream, receiving instructions from memory.

8.4 SIMD — Single Instruction stream, Multiple Data stream

Multiple processing elements (DPUs) exist in the computer architecture, all controlled by a single control unit.

  • The CU receives instructions from memory over a single instruction stream and generates controls for different DPUs based on the decoded instruction.
  • Each DPU processes a different data element, accessed from memory over different data streams.
  • The shared memory unit must contain multiple modules to communicate with all processors simultaneously (PART_C.pdf).

8.5 MISD — Multiple Instruction stream, Single Data stream

Multiple data processing units and multiple control units exist. The data processing units are arranged sequentially so the output of one DPU is the input of the next DPU in order. Each DPU receives controls from its own independent CU, and each CU processes a different instruction.

8.6 MIMD — Multiple Instruction stream, Multiple Data stream

Multiple control units and multiple data processing units exist. Each DPU processes a different data element using a different data stream. Each DPU receives controls from its independent CU,