Sei sulla pagina 1di 15

Overview

Much of the computer’s architecture /


organization is hidden from a HLL
programmer
– In the abstract sense, the programmer should
not care what the underlying architecture really
EE 4504 is
Computer Organization The instruction set is the boundary where
the computer designer and the computer
programmer can view the same machine
Thus, an examination of the instruction set
Section 7
goes a long way to explaining the
The Instruction Set computer’s CPU itself
This section investigates the design of the
instruction set and the impact of the set on
the design of the overall computer system
Readings: Chapters 9 and 10

EE 4504 Section 7 1 EE 4504 Section 7 2

1
Instruction content Instruction types

Each instruction must contain 4 basic An instruction set should be functionally


pieces of information complete
– Operation code: specifies the operation to be – Permit the user to formulate any high-level data
performed, expressed as a binary code processing task
– Source operand references: operands required Five categories of instructions
for the instruction are specified
– Arithmetic operations
– Result reference: where should the result of the
– Logic operations
operation be placed?
– Data movement (internal to the system)
– Next instruction reference: how / where is the
next instruction to be found – I/O (data movements between the computer and
external devices)
» In most cases, this is not explicitly stated in
the instruction – Control operations
» Next instruction is the one that logically Instruction sets have been designed with
follows the current one in the program – Small numbers of instructions (1)
(sequential / linear progression through the – Hundreds of instructions
program)
– Trend today is to use “enough” to get the job
done well (more on this in the RISC/CISC
discussions to come)

EE 4504 Section 7 3 EE 4504 Section 7 4

2
Until the 1980s, the trend was to construct Wulff asserts that compiler writers might
more and more complex instruction sets make the better architects
containing hundreds of instructions and – Have had to deal with poor architecture
variations decisions
Intent was to provide mechanisms to Wulff’s attributes of a good instruction set
bridge the semantic gap, the difference in – Complete: be able to construct a machine-level
high and low level functioning of the program to evaluate any computable function
computer – Efficient: frequently performed functions
should be done quickly with few instructions
– Reconcile the views of the HLL programmer
and the assembly level programmer – Regular and complete classes of instructions:
provide “logical” set of operations
– Provide a diverse set of instructions in an
attempt to match the programming style of HLL – Orthogonal: define instructions, data types, and
addressing independently
– Permit the compiler to “bridge the gap” with a
single instruction rather than synthesizing a Additional attribute:
series of instructions – Compatible: with existing H/W and S/W in a
– Did not always have the desired impact product line

EE 4504 Section 7 5 EE 4504 Section 7 6

3
Addresses in an Instruction

In a typical arithmetic or logical 2 address instructions


instruction, 3 addresses are required -- 2 – One of the addresses is used to specify both an
operands and a result operand and the result location
These addresses can be explicitly given or – Example: X = X + Y
implied by the instruction – Very common in instruction sets

3 address instructions 1 address instructions


– Both operands and the destination for the result – Two addresses are implied in the instruction
are explicitly contained in the instruction word – Traditional accumulator-based operations
– Example: X = Y + Z – Example: Acc = Acc + X
– With memory speeds (due to caching) 0 address instructions
approaching the speed of the processor, this – All addresses are implied, as in register-based
gives a high degree of flexibility to the operations
compiler » Example: TBA (transfer register B to A)
» Avoid the hassles of keeping items in the – Stack-based operations
register set -- use memory as one large set
of registers » All operations are based on the use of a
stack in memory to store operands
– This format is rarely used due to the length of
addresses themselves and the resulting length of » Interact with the stack using push and pop
the instruction words operations

EE 4504 Section 7 7 EE 4504 Section 7 8

4
Trade off: Fewer addresses in the – 2 address
instruction results in MOV Y,A
SUB Y,B
– More primitive instructions MOV T,D
– Less complex CPU MUL T,E
– Instructions with shorter length ADD T,C
– More total instructions in a program DIV Y,T
– Longer, more complex programs
– Longer execution times – 1 address
LOAD D
Consider MUL E
ADD C
Y = (A-B) / (C+D*E) STORE Y
LOAD A
SUB B
– 3 address DIV Y
SUB Y,A,B STORE Y
MUL T,D,E
ADD T,T,C
DIV Y,Y,T

EE 4504 Section 7 9 EE 4504 Section 7 10

5
Types of Operations

– 0 address
» Convert to postfix (reverse Polish) notation
Y = AB-CDE*+/

PUSH A
PUSH B
SUB
PUSH C
PUSH D
PUSH E
MUL
ADD
DIV
POP Y

EE 4504 Section 7 11 EE 4504 Section 7 12

6
Control Operations

Common operations
– Branch
» Conditional or unconditional
» Jump to another part of the program for the
next instruction by modifying the program
counter
– Skip
» Useful in loop control
ISZ R1
BRA TOP
– Subroutine call / return
» Jump to routine with the expectation of
returning and resuming operation at the
next instruction
» Must preserve the address of the next
instruction (the return address)
Store in a register or memory location
Store as part of the subroutine itself
Store on the stack

EE 4504 Section 7 13 EE 4504 Section 7 14

7
Endian Wars

» Parameters can be passed to / from the Architects must specify how data is stored
subroutine in similar ways (its byte ordering) in memory and registers
» Use of the stack is the only reentrant – This leads to the “endian wars”
approach
» Big endian
» Each called subroutine is allocated a stack
frame on the stack » Little endian
Contains variable to be passed Consider the hex value $12345678 and
Return address how it is stored in memory starting at
Results to be returned address $100
– Big endian stores most significant byte in the
lowest address:
100 12
101 34
102 56
103 78
– Little endian stores the word in reverse:
100 78
101 56
102 34
103 12

EE 4504 Section 7 15 EE 4504 Section 7 16

8
Addressing Modes

Observations: Once we have determined the number of


– In storing several data items into a memory addresses contained in an instruction, the
segment, each item will have the same address manner in which each address field
(big or little endian does not change this) specifies memory location must be
– Endianness does not effect the ordering of items determined
in a data structure
– No general consensus as to which is “best” Want the ability to reference a large range
» Little endian: Intel X86, Pentium, VAX of address locations
» Big endian: S370, Motorola 680x0, RISCs Tradeoff between
– No real advantage in one style over the other – Addressing range and flexibility
» Decision is based on supporting previous – Complexity of the address calculation
machines in many cases Immediate Mode
– Biggest problems: – The operand is contained within the instruction
» Data transfers between machines of itself
different endianness – Data is a constant at run time
Must go though a format conversion – No additional memory references are required
process after the fetch of the instruction itself
» Manipulation of individual bytes (bits) of – Size of the operand (thus its range of values) is
multibyte word limited

EE 4504 Section 7 17 EE 4504 Section 7 18

9
Direct mode Indirect addressing
– The address field of the instruction contains the – The address field in the instruction specifies a
effective address of the operand memory location which contains the address of
– No calculations are required the data
– One additional memory access is required to – Two memory accesses are required
fetch the operand » The first to fetch the effective address
– Address range limited by the width of the field » The second to fetch the operand itself
that contains the address reference – Range of effective addresses is equal to 2n,
– Address is a constant at run time but data itself where n is the width of the memory data word
can be changed during program execution – Number of locations that can be used to hold
– Some machines use variations of direct the effective address is constrained to 2k, where
addressing: direct and extended addressing on k is the width of the instruction’s address field
the 68HC11 -- 8 and 16-bit addresses Register-based addressing modes
– Register addressing: like direct, but address
field specifies a register location
– Register indirect: like indirect, but address
field specifies a register that contains the
effective address
– Faster access to data, smaller address fields in
the instruction word
EE 4504 Section 7 19 EE 4504 Section 7 20

10
Displacement or address relative Indexing
addressing – Essentially the same impact as base addressing
– Two address fields in the instruction are used – Our book says that the A field is a memory
» One is an explicit address reference address and the referenced register contains the
» The other is a register reference displacement value that is added to A
» EA = A + (R) » This is not necessarily the case! “Indexing”
as used and defined by Motorola for the
– Relative addressing
68HC11 is exactly as our author defines
» A is added to the program counter contents base addressing
to cause a branch operation in fetching the
– Better distinction of the base and indexing
next instruction
might be who / what does the reference.
– Base-register addressing Examples:
» A is a displacement added to the contents of » Indexing is used within programs for
the referenced “base register” to form the accessing data structures
EA » Base addressing is used as a control
» Used by programmers and O/S to identify measure by the O/S to implement
the start of user areas, segments, etc. and segmentation
provide accesses within them

EE 4504 Section 7 21 EE 4504 Section 7 22

11
Instruction Formats

Pentium and PowerPC addressing The instruction format defines the layout
– Text shows 9 addressing modes for the Pentium of instruction word in terms of its
» Range for simple modes (e.g., immediate) constituent parts
to very complex modes (e.g., bases with Most basic issue is the instruction length
scaled index and displacement)
– Longer instruction lengths permit more
– The PowerPC, in contrast has fewer, simpler
opcodes, addressing modes, addressing ranges,
addressing modes
etc.
– Longer does not imply a significant increase in
functionality, however
– Instruction lengths are equal to the basic
memory transfer data size or a multiple of that
size
» If the memory system retrieves 32 bit
words, instructions should be 32 bits (or 64)
Allocation of bits
– Tradeoff between number of opcodes supported
(rich instruction set) and the power of the
addressing capability

EE 4504 Section 7 23 EE 4504 Section 7 24

12
PDP-8: 12-bit fixed format PDP-10 36-bit fixed format
– Stressed orthogonality, completeness, and
direct addressing
– Trade off ease of programming with increased
H/W expense

Figure 10.5 PDP-10 instruction format

Figure 10.4 PDP-8 instruction format


EE 4504 Section 7 25 EE 4504 Section 7 26

13
PDP-11 variable length format PowerPC format
– 16-bit word length minicomputer
– Variable length instructions to provide
flexibility -- more opcodes and memory
addressing modes
» Cost of the flexibility is a significant
increase in the CPU complexity

Figure 10.6 PDP-11 instruction formats Figure 10.8 PowerPC instruction formats
EE 4504 Section 7 27 EE 4504 Section 7 28

14
Summary

In this section, we have looked at the


instruction set of the machine
– Content
» types of information contained in them
» Functional completeness
– Addressing in instructions
» Number of addresses included and the
impact on the program
» Addressing modes -- how is the effective
address determined
– Instruction format
» Size and amount allocated to different fields
» Fixed and variable formats
» Complexity

EE 4504 Section 7 29

15

Potrebbero piacerti anche