The Processor Unit (Cpu) : By: Solomon S
The Processor Unit (Cpu) : By: Solomon S
The Processor Unit (Cpu) : By: Solomon S
By: Solomon S.
1
Topic Contents
• Computer arithmetic
The ALU
Integer representation
Floating point representation and arithmetic
• Instruction sets
Types of operands
Data types
• Instruction formats
Three-address
Two-address
One-address
Zero-address
• Processor organization
Instruction pipelining 2
Computer arithmetic
o Computer arithmetic is a branch of
computer engineering that deals with
methods of representing integers and
real values (e.g., fixed- and floating-
point numbers) in digital systems and
o Efficient algorithms for manipulating
such numbers by means of hardware
circuits or software routines
Cont…
The two principal concerns for computer
arithmetic.
1) The way in which numbers are represented
(the binary format) and
2) The algorithms used for the basic arithmetic
operations (add, subtract, multiply, divide).
These two considerations apply both to
integer and floating-point arithmetic.
Cont..
?
How can a computer perform arithmetic operations?
Signed Integers
o Need to reserve one bit for the sign.
o Three ways:
Sign-Magnitude
1's Complement
2's Complement
Cont..
I. Sign-Magnitude
o Uses most significant bit of the word to represent the sign.
0 - Positive
1 - Negative.
o Rest of the number is encoded in magnitude part
37 = 00000000 00100101
-37 = 10000000 00100101
6712 = 00011010 00111000
-6712 = 10011010 00111000
o Can represent numbers from -32,767 to 32,767.
o But, two representations for zero, which is poor side of sign-
magnitude:
• 0 = 00000000 00000000
• -0 = 10000000 00000000
The general case can be expressed as follows:
12
Cont..
Floating-Point Representation
IEEE Standard for Binary Floating-Point
Representation
Floating-Point Arithmetic
IEEE Standard for Binary Floating-Point
Arithmetic
Submit on 30/03/2021
17
Instruction sets KEY POINTS
instruction sets.
These include direct (operand address is in address field), indirect
address.
Cont…
What is an Instruction Set?
o Instruction set: The complete collection of instructions
that are understood by a CPU
o Machine language: binary representation of operations
and (addresses of) arguments
o Assembly language: mnemonic representation for
humans, e.g., MOV A, C A <- C
19
Cont…
Elements of an Instruction
o Instruction in memory has two parts:
opcode and
operands.
o The opcode identifies the operation that instruction does
o The operands are subjects of the operation, such as data
values, registers, or memory addresses.
o Due to variety of opcodes and operands, instructions
may occupy different sizes of bytes in memory.
Eg. SHLD, STA
20
Instruction Types
o registers,
o main memory,
Data transfer
o stack or
o I/O
o arithmetic,
Data processing
o logical
o systems control,
Program flow control
o transfer of control
o Branch control 21
Data Transfer
• Instructions like: Store, load, exchange,
move, clear, set, push, pop
• Specifies source and destination (memory,
register, stack), amount of data
• May be different instructions for different
(size, location) movements
Arithmetic
• Add, Subtract, Multiply, Divide for signed
integer (+ floating point and packed decimal)
• May include
– Absolute (|a|)
– Increment (a++)
– Decrement (a--)
– Negate (-a)
Logical
• Bitwise operations: AND, OR, NOT, XOR,
TEST, CMP, SET
• Shifting and rotating functions, e.g.
– logical right shift for unpacking: send 8-bit
character from 16-bit word
– arithmetic right shift: division and truncation for
odd numbers
– arithmetic left shift: multiplication without
overflow
Transfer of Control
• Skip, e.g., increment and skip if zero:
ISZ Reg1, jumping out from loop if it’s true
• Branch instructions: BRZ X (branch to X if
result is zero), BRP X (positive), BRN X
(negative), BRE X,R1,R2 (equal)
• Procedure: call and return,
– Unconditional call and return
– Eg. CALL 2035H, RET 2030H
Branch Instruction
Nested Procedure Calls
Types of Operand
1. Addresses:
immediate,
direct,
indirect,…
2. Numbers: integer or fixed point (binary, twos
complement), floating point (sign, significand,
exponent),
3. Characters: ASCII (128 printable and control
characters + bit for error detection)
4. Logical Data: bits or flags, e.g., Boolean 0 and 1
29
Data types
Most programming languages support common data
types of real, integer and boolean.
x86 Data Types
8 bit Byte
16 bit word
32 bit double word
64 bit quad word
128 bit double quadword
Addressing is by 8 bit unit
Data accessed across 32 bit bus in units of double word
read at addresses divisible by 4
Little endian
30
Instruction formats
o Instruction format describes the internal
structures (layout design) of the bits of an
instruction, in terms of its constituent parts.
o An Instruction format must include an
opcode, and
address
o Note: Address is dependent on an
availability of particular operands.
31
Cont…
On the basis of number of address instruction are
classified as:
o Three-address
o Two-address
o One-address
o Zero-address
1. Zero Address Instructions
Zero-address instructions are applicable to a special
memory organization, called a stack.
A stack based computer do not use address field in
instruction.
32
Cont…
2. One Address Instructions
This use a implied ACCUMULATOR register for
data manipulation.
One operand is in accumulator and other is in
register or memory location.
Implied means that the CPU already know that
one operand is in accumulator so there is no need
to specify it.
33
Cont…
3. Two Address Instructions
This is common in commercial computers.
Here two address can be specified in the
instruction.
Unlike earlier in one address instruction the result
was stored in accumulator here result cab be
stored at different location rather than just
accumulator, but require more number of bit to
represent address.
34
Cont…
4. Three Address Instructions
This has three address field to specify a register or
a memory location.
Program created are much short in size but
number of bits per instruction increase.
35
PROCESSOR ORGANIZATION
• To understand the organization of the processor, let us consider the
requirements placed on the processor, the things that it must do:
o Fetch instruction: The processor reads an instruction from
memory (register, cache, main memory).
o Interpret instruction: The instruction is decoded to determine
what action is required.
o Fetch data: The execution of an instruction may require reading
data from memory or an I/O module.
o Process data: The execution of an instruction may require
performing some arithmetic or logical operation on data.
o Write data: The results of an execution may require writing
data to memory or an I/O module.
• To do these things, it should be clear that the processor needs to
store some data temporarily
36
• Figure below shows a simplified view of a processor, indicating its
connection to the rest of the system via the system bus.
• The major components of the processor are an arithmetic and logic
unit (ALU) and a control unit (CU).
• The ALU does the actual computation or processing of data.
38
INSTRUCTION PIPELINING
39
Cont…
• pipelining involves breaking up the instruction cycle into a
number of separate stages that occur in sequence, such as
– fetch instruction,
– decode instruction,
– calculate operand addresses,
– fetch operands,
– execute instruction, and
– write operand result
• Each stage can be working on a different instruction at the
same time.
• The occurrence of branches and dependencies between
instructions complicates the design and use of pipelines.
40
• The pipeline has two independent stages.
– The first stage fetches an instruction
and buffers it.
– When the second stage is free, the first
stage passes it the buffered
instruction.
– While the second stage is executing
the instruction, the first stage takes
advantage of any unused memory
cycles to fetch and buffer the next
instruction.
• This is called instruction pre-fetch or
fetch overlap.
• Note: this approach, which involves
instruction buffering, requires more
registers. In general, pipelining requires
Two-Stage Instruction Pipe registers to store data between stages.
41
Figure shows that a six-stage pipeline can reduce the
execution time for 9 instructions from 54 time units to 14 time
units.
42
• Several comments are in order: The diagram assumes that each
instruction goes through all six stages of the pipeline. This will not
always be the case.
• For example, a load instruction does not need the WO stage. However,
to simplify the pipeline hardware, the timing is set up assuming that
each instruction requires all six stages. Also, the diagram assumes that
all of the stages can be performed in parallel.
• In particular, it is assumed that there are no memory conflicts. For
example, the FI, FO, and WO stages involve a memory access.
• The diagram implies that all these accesses can occur simultaneously.
Most memory systems will not permit that. However, the desired value
may be in cache, or the FO or WO stage may be null.
• Thus, much of the time, memory conflicts will not slow down the
pipeline.
• Several other factors serve to limit the performance enhancement. If the
six stages are not of equal duration, there will be some waiting involved
at various pipeline stages.
43
Another difficulty is the conditional branch instruction
indicates the logic needed for pipelining to account for branches and
interrupts.
44
Basic five-stage
pipeline in a RISC • The vertical axis is
machine successive instructions,
the horizontal axis is
time.
• So in the green
column, the earliest
instruction is in WB
stage, and the latest
instruction is
undergoing instruction
fetch.
IF = Instruction Fetch,
ID = Instruction Decode,
EX = Execute,
MEM = Memory access,
WB = Register write back.
45
Example:
A machine has shared a single-memory
pipeline for data and instructions. As a
result, when an instruction contains a
data-memory reference(load), it will
conflict with the instruction reference
for a later instruction (instr 3):
46
Solution
To resolve this, we stall the pipeline for one
clock cycle when a data-memory access
occurs. The effect of the stall is actually to
occupy the resources for that instruction slot.
The following figure shows how the stalls are
actually implemented.
The End of Chapter 2
50