Академический Документы
Профессиональный Документы
Культура Документы
e.g.
ADD
Operand(s)
R0
100
The shorter the instruction, the faster the time that it can
be fetched and decoded.
A machine with 2^N instructions must require at least Nbit to encode all the op-codes.
Instruction sets
Byte ordering
- Big-endian: bytes in word ordered from left-toright eg. Motorola
- Little-endian: bytes in word ordererd right-toleft eg. Intel
Creates havoc when transferring data; need to swap
byte order in transferred words
2.10, 2.11
Op-code Encoding
1. Block-code technique
instruction 0
instruction 1
instruction 2
3-bit Op-code
3-to-8
decoder
instruction 3
instruction 4
instruction 5
instruction 6
instruction 7
Op-code Encoding
2. Expanding op-code
technique
Consider an 4+12 bit instruction with a 4-bit opcode and three 4-bit addresses.
Op-code
Address 1
Address 2
Address 3
Op-code
Address 1
Address 2
1111
Op-code
Address 1
1111
1111
1111
Op-code
Opcode Encoding
Note that the three address fields may not
necessarily be used to encode a three-address
operand; they canl be used as a single 12-bit oneaddress operand.
Can have some part of the op-code to specify the
instruction format and/or length.
- if there are few two-address instructions, we
may attempt to make them shorter instead
and to use the first two bits to indicate the
instruction length, e.g., 10 means two-address
and 11 means three address.
Op-code Encoding
Huffman encoding
1
0
1/2
0
1
1
1/4
0
1
1/8
1/8
1/2
1/4
1/16
1/16
1/16
1/16
1/8
1/8
1/4
1/4
STO LOAD
10
11
Addressing modes
ADD #250, R1
% R1 := R1 + 250;
% R1 := R1 + *(250);
% R1 := R1 + R2;
Addressing Modes
% R1 := *(R2);
MOV -(R2), R1
R2 := R2 + k;
% R2 := R2 - k; R1 := *(R2);
% R1 := R2[2];
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.
10
Instruction Types
Arithmetic
ADD, SUB, DIV, MUL
Logical
AND, OR, NOT, SHIFT, ROTATE
System-control
Test-And-Set
I/O
Separate I/O space input/output
11
Instruction Types
Unconditional branch
BRB
NEXT
Conditional branch
SOBGTR
R5, LOOP
ADBLEQ
Subroutine call
CALL
SUB
RET
% pop PC
Interrupt-handling
TRAP
12
Instruction types
Typical branch instructions test the value of some
flags called conditions. Certain instructions cause
these flags to be set automatically.
The registers used in implementing a subroutine
call are called linkage registers, which 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 except that it
may 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.
13
14
15
Example: 8051
low or high
16
17
18
[5.14]
32-bit instructions; 31 RISC instructions
first 2 bits help decode instruction format
to encode a 32 bit constant, need to do it in 2
separate instructions!
Example: 8051
[5.16]
6 simple formats; 1, 2 or 3 bytes
format 4: 11 bits when no external memory; else
format 5
19
old 5.35
5.36
20
Addressing: Pentium
new modes are more regular, general
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
21
Examples of addressing
PDP-11
5.33
22
5.34
23
Example: 8051
5 modes [fig 5-29]
some instns use accumulator implicitly (no code
telling such... means instns are more compact!)
some modes (reg indirect) require operand to be in
bottom 256 bytes of memory, because thats where
registers are residing
64 Kb of memory addressed by loading 2-bit offsets
24
Addressing: Discussion
PDP-11 is clean, simple; some waste
Pentium: specialized formats, addressing schemes
386 - 32 bit addressing is more general
RISC (Ultra): simpler instructions, fewer modes
Compilers will generate required addressing, so a simple
scheme will suffice
Specialized modes, formats makes instruction parallelism
(pipelining) more difficult
fewer modes preferrable over specialized modes
simplicity means better compilers
Compact Instructions
+ - smaller resource usage
- faster fetch, execution
- - reduce robustness
Larger instructions:
+: simpler formats
less constrained
-: performance waste
25