Beruflich Dokumente
Kultur Dokumente
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Chapter 2: Machines, Machine
Languages, & Digital Logic
Reduced Instruction
Set Computer
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
What Must an Instruction Specify?
Which operation to perform: add r0, r1, r3
Ans: Op code: add, load, branch, etc.
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Accessing Memory—Reading from Memory
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Examples: Data Movement Instructions
Inst ruct . Meaning Machine
IN, AL, KBD Load a byt e from in port KBD to accum. Intel Pentium
LEA.L (A0), A2 Load address pointed to by A0 into A2 M68000
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Examples: ALU
(Arithmetic, Logic) Instructions
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Branch Instruction Examples
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
CPU Registers Associated with Flow of
Control—Branch Instructions
C N V Z
Program Counter Condition Codes
•
•
•
Branch Targets
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
HLL Conditional Implementation
Conditions are computed by arithmetic instructions
PC modified to execute only instructions associated
with true conditions
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Most General Instruction
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
CPU Registers may have a “personality”
Architecture classes are often based on where the operands & results
are located & how they are specified by the instruction.
They can be in CPU registers or main memory
Push Pop
Top
Second
• • •
• • •
• • •
•
•
•
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
MOST GENERAL INSTRUCTION
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
4, 3, 2, 1, & 0 Address Instructions
Classification basis: ALU instructions having two operands & one
result.
Key issue: how many operands are specified by memory/register
addresses, as opposed to being specified implicitly ?
The 4-address instruction: Specifies memory addresses for both
operands, the result, and the next instruction.
R ← [Op1 op Op2][next inst. addr.]
A 3 address instruction: As above, however, next instruction address
is implicitly the next address in sequence (except for conditional
instructions.
R ← Op1 op Op2
A 2 address instruction: Overwrites one operand in memory with the
result:
Op2 ← Op1 op Op2
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
The 4 Address Instruction
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
The 2 Address Instruction
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Single Address Instructions
We now need
instructions to load
and store
operands:
LDA OpAddr
STA OpAddr
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
The 0 Address Instruction
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Expression evaluation
Evaluate a = (b+c)*d-e for 3- 2- 1- and 0-address machines.
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
General Register Machines
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Addressing Modes
An addressing mode is hardware support for a useful way
of determining a memory address
Different addressing modes solve different HLL problems
Some addresses may be known at compile time, e.g. global vars.
Others may not be known until run time, e.g. pointers
Addresses may have to be computed: Examples include:
Record (struct) components:
variable base(full address) + const.(small)
Array components:
const. base(full address) + index var.(small)
Possible to store constant values w/o using another memory cell
by storing them with or adjacent to the instruction itself.
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Processor Organization
OFF-Chip
Data Instruction
ON-Chip
Memory Memory
Control Logic
PC Å PC+1
Processor
Registers:
PC Å Br.Addr
PC: Program Counter
IR: Instruction Reg.
Other Stuff
Other Registers
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Addressing Modes
237 1024
R1 237
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Common Addressing Modes
R1 R1
Load R1, #3
R1
R1
Load R1, Addr.A
R1
(Memory)
R1
R3 +
Add R1, R2, R3
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Common Addressing Modes
R1
R1
Load R1, (R2)
R1
R1
R1
R1
LoadRel R1, 4[PC]
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
SRC: Simple RISC Computer
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
SRC Characteristics
(=) Similar to commercial RISC machines
(–) Less powerful than commercial RISC machines.
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
SRC Basic Instruction Formats
Three basic instruction format types
Number of reg specifier fields & length of the constant field vary
Other formats result from unused fields or parts
31 2726 2221 0
op ra c1 Type 1
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Load & Store Inst: Memory Addressing
Address: constant, constant+register, or constant+PC
Memory contents or address itself can be loaded
If Rb=0 Æ c1 is 2’s complemented # extended,
If Rb NOT=0 Æ c1 is used as offset; see below (*)
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Binary Encoding of Instructions
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Assembly Language for Arithmetic & Logic Instr
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Branch Instruction Format
There are actually only two branch op codes:
br rb, rc, c3<2..0> ;branch to R[rb] if R[rc] meets
; the condition defined by c3<2..0>
brl ra, rb, rc, c3<2..0> ; Branch as above & R[ra] ← PC
• It is c3<2..0>, the 3 lsbs of c3, that governs what the branch condition is:
C: goto Label3
SRC:
lar r0, Label3 ; branch target addr Æ target reg.
br r0 ; branch
• • •
Label3: •••
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07
Example of conditional branch
Computer Systems Design and Architecture 2nd Edition © 2004 Prentice Hall, Mark Franklin F07