Professional Documents
Culture Documents
Cosc 3P92
1
COSC 3P92
Computer Instruction Set
• An instruction has two components:
– e.g
. Op-code Operand(s)
ADD R0 100
2
COSC 3P92
3
COSC 3P92
Bits/cell (word)
4
COSC 3P92
Instruction sets
• Byte ordering
– Big-endian: bytes in word ordered from left-to-right eg.
Motorola
– Little-endian: bytes in word ordered right-to-left eg. Intel
5
COSC 3P92
Big/Little Endian
6
COSC 3P92
Op-code Encoding
• 1. Block-code technique
– To each of the 2K instructions a unique binary bit
pattern of length K is assigned.
– An K-to-2K decoder can then be used to decode all
the instructions. For example,
instruction 0
instruction 1
instruction 2
3-to-8 instruction 3
3-bit Op-code decoder instruction 4
instruction 5
instruction 6
instruction 7
7
COSC 3P92
Op-code Encoding
• 2. Expanding op-code technique
– Consider an 4+12 bit instruction with a 4-bit op-code and three 4-bit
addresses.
Op-code Address 1 Address 2 Address 3
8
COSC 3P92
Opcode Encoding
9
COSC 3P92
Op-code Encoding
• Huffman encoding
– Given the probability of occurrences of each instruction, it is
possible to encode all the instructions with minimal number of
bits, and with the following property:
1
0
1/2
0
1
1/4 1
0 1
0 1 0 1 0 1 0 1
10
COSC 3P92
Opcode encoding,
Huffman codes
• Huffman encoding algorithm:
– 1. Initialize the leaf nodes each with a probability of an instruction.
All nodes are unmarked.
– 2. Find the two unmarked nodes with the smallest values and mark
them. Add a new unmarked node with a value equal to the sum of
the chosen two.
– 3. Repeat step (2) until all nodes have been marked except the last
one, which has a value of 1.
– 4. The encoding for each instruction is found by tracing the path
from the unmarked node (the root) to that instruction.
• may mark branches arbitrarily with 0, 1
11
COSC 3P92
Opcode encoding,
Huffman codes
• Advantage:
– minimal number of bits
• Disadvantage:
– must decode instructions bit-by-bit, (can be slow).
– to decode, must have a logical representation of the encoded
tree, and follow branches as you decipher bits
– Fact is, most decoding is done in parallel
– Gives a speed advantage
12
COSC 3P92
Addressing modes
• inherent
– an op-code indicates the address of its operand
13
COSC 3P92
Addressing Modes
• register indirect
– the register address in an instruction specifies the address
of its operand
14
COSC 3P92
Addressing Modes
• indexed
– an offset is added to a register to give the address of the
operand
• relative
– same as base-register mode except that the instruction pointer
is used as the base register
15
COSC 3P92
Addressing modes
• Indirect addressing mode in general also applies
to absolute addresses, not just register
addresses; the absolute address is a pointer to
the operand.
• The offset added to an index register may be as
large as the entire address space. On the other
hand, the displacement added to a base register
is generally much smaller than the entire address
space.
• The automatic modification (i.e., auto-increment
or auto-decrement) to an index register is called
autoindexing.
• Relative addresses have the advantage that the
code is position-independent.
16
COSC 3P92
Instruction Types
• Instructions, of most modern computers, may be
classified into the following six groups:
– Data transfer (40% of user program instructions)
MOV, LOAD
– Arithmetic
ADD, SUB, DIV, MUL
– Logical
AND, OR, NOT, SHIFT, ROTATE
– System-control
Test-And-Set
– I/O
Separate I/O space input/output
17
COSC 3P92
Instruction Types
• Program-control
– may be classified into the following four groups:
– Unconditional branch
BRB NEXT % branch to the label NEXT
– Conditional branch
SOBGTR R5, LOOP % repeat until R5=0
ADBLEQ R5, R6, LOOP % repeat until R5>R6
– Subroutine call
CALL SUB % push PC; branch to SUB
RET % pop PC
– Interrupt-handling
TRAP % generate an internal interrupt
18
COSC 3P92
Instruction types
• Typical branch instructions
– test the value of some flags called conditions.
– Certain instructions cause these flags to be set automatically.
• linkage registers
– Used in implementing a subroutine.
– Typically include the instruction pointer and stack pointer..
• The parameters passed between the caller and the called
subroutine are to be established by programming conventions.
– Very few computers support parameter-passing mechanisms in the hardware.
• An external interrupt may be regarded as a hardware generated
subroutine call
– Can happen asynchronously.
– When it occurs, the current state of the computation must be saved either by
» the hardware automatically
» or by a program (interrupt-service routine) control.
19
COSC 3P92
P2
Registers
ESegment
= Extended
Pointers Registers,
to memory,
registers copying
for
designed
and for backwards
manipulating
backwards strings in
compatibility.
Points to
compatibilitybase of current
toaddress
older Intel
memory
P4 uses a flat
stack
CPUs, frame, also called
used for arithmatic.
space
Stack pointerpointer
the frame
PC
PSW or Flags
21
COSC 3P92
Ultra SPARC III
Overview of the
UltraSPARC III
ISA Level (2)
Operation of the
UltraSPARC III
register windows.
23
COSC 3P92
8051
• Runs in 1 mode,
– Single process, directly interfacing h/w,
– No OS.
– Ram & Rom are (can be) on chip
– 4 sets of 8 GP registers,
» 2 bits in PSW determine which set is active.
» Interrupts do not cause a save of registers on a stack but a
context switch.
» Registers are directly mapped to memory
• R0 = 0x0000 in memory etc.
– 127 bit addressable memory locations
» Bits correspond nicely to switches and LED outputs
– Some specialized registers
» Interupts
» Timers
» All mapped to memory 128 to 255.
24
COSC 3P92
Overview of the
8051 ISA Level
26
COSC 3P92
27
COSC 3P92
Example: PDP-11
instruction formats
• CISC machine
Example: Pentium
addressing
• 8088/286 are very non-orthogonal, and addressing
possibilities are arbitrary for different registers
31
COSC 3P92
Example: Pentium Addressing
• 386 -- if 16-bit segments used, then use previous
- if 32-bit segments, use following...
32
COSC 3P92
Addressing: Pentium
33
COSC 3P92
Addressing: Pentium
• SIB
mechanism:
[5.27] --> arrays
•scale = 1, 2,
4, 8
•multiply
scale to
Index register
•adding to
Base register
•and then 8
or 32-bit
displacement
34
COSC 3P92
Examples of addressing
PDP-11
5.33
35
COSC 3P92
Examples of addressing
PDP-11
36
COSC 3P92
Addressing
& PDP 11
• orthogonality permits many
variations with one opcode
37
COSC 3P92
38
COSC 3P92
Can be used due to
limited size of the CPU
Discussion of Addressing Modes
Addressing: Discussion
40
COSC 3P92
Addressing: Discussion
• Compact Instructions
– Advantages.
» smaller resource usage
» faster fetch, execution
– Disadvantages
» reduce robustness
• Larger instructions:
– Advantages.
» simpler formats
• less constrained
– Disadvantages
» performance
» waste
41
COSC 3P92
The end
43