






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Instruction-set Design Issues: what is the ML instruction format(s)
ML instruction
Opcode Dest. Operand Source Operand 1...
Which instructions to include: How many? Complexity - simple “ADD R1, R2, R3” complex e.g., VAX “MATCHC substrLength, substr, strLength, str ” looks for a substring within a string
Which built-in data types: integer, floating point, character, etc.
Instruction format: Length (fixed, variable) number of address (2, 3, etc) field sizes
Number of registers
Addressing modes supported - how are the memory addresses of variables/data determining
Lecture 2 - 1
Number of Operands
DIV (X bY / Z) DIV (X bX / Y) DIV M DIV
MUL (X bY * Z) MUL (X bX * Y) MUL M MUL
SUB (X bY - Z) ADD (X bX - Y) SUB M SUB
ADD (X (^) bY + Z) ADD (X (^) bX + Y) ADD M ADD
STORE M POP M
MOVE (X bY) MOVE (X bY) LOAD M PUSH M
0 Address (Stack machine)
1 Address (Accumulator machine)
3 Address 2 Address
D = A + B * C (Postorder Traversal: A B C * + )
0 Address (Stack machine)
1 Address (Accumulator machine)
3 Address 2 Address
Load/Store Architecture - operands for arithmetic operations must be from/to registers
LOAD R1, B LOAD R2, C MUL R3, R1, R LOAD R4, A ADD R3, R4, R STORE R3, D
Lecture 2 - 2
Set-Then-Jump version of the if-then-else (Used in Pentium) if: cmp x, y jge else
... j end_if else: ... end_if:
The "cmp" instruction performs x - y with the result used to set the condition codes SF - (Sign Flag, n) set if result is < 0 ZF - (Zero Flag, z) set if result = 0 CF - (Carry Flag, c) set if unsigned overflow OF - (Overflow Flag, v) set if signed overflow
For example, the "jge" instruction checks to see if ZF = 1 or SF = 1, i.e., if the result of x - y is zero or negative.
Lecture 2 - 4
Machine-Language Representation of Branch/Jump Instructions (How are labels (e.g., “end_if”) in the code located???)
a) direct/absolute addressing - the memory address of where the label resides is put into the machine language instruction (EA, effective address = direct) e.g., assume label "end_if" is at address 8000 16
AL instruction ML instruction j end_if (^) Opcode 8000
end_if:
How relocatable is the code in memory if direct addressing is used? How many bits are needed to represent a direct address?
b) Relative/PC-relative - base-register addressing where the PC is the implicitly referenced register
AL instruction ML instruction
Opcode
Opcode
while: bge R8, R9, end_while
b while end_while:
"end_while" label 40 addresses from "bge"
Unconditional pc-relative branches are possible too
Lecture 2 - 5
e) Base-register addressing / Displacement - operand is pointed at by an address in a register plus offset
AL instruction
ML instruction
Memory Load r9, 40(r2)
Opcode 9 40 2
Register File
r2 (^4000)
EA = (r2) + 40
Often the reference register is the stack pointer register to manipulate the run-time stack, or a global pointer to a block of global variables.
Lecture 2 - 7
Add R1,R2,R
Load R2, X
Load R3, Y
Store R1, SUM Program Area
(X) (Y) (SUM)
5 3 DataGlobal 0
Heap
Stack
Unused
A Program's Address Space
Stack Pointer Register, $29/$sp
Global Pointer Register, $28/$gp
Program Counter, pc
f) Indexing - ML instruction contains a memory address and a register containing an index
AL instruction ML instruction
ML instruction
addindex r9, A(r2) (^) Opcode
Opcode
EA = A + (r2)
Reg. File
r2 (^10)
Useful for array access.
Lecture 2 - 8
RISC Instruction-Set Architecture (ISA) can be effectively pipelined Instruction pipelining through the CPU speeds up program execution like an assembly-line speeds up manufacturing of a car. A car assembly line might split up building a car into four stages: Chassis Motor Interior Exterior
Assume that the whole car assembly process takes 4 hours. If you divide the process into four equal stages of an hour each, then ideally we can complete a car every hour. Problems occur if the stages are not equally balanced for all cars. The main RISC philosophy (mid-80’s and after) is to design the assembly language (AL) to optimize the instruction pipeline to speed program execution.
Table 13.1 - characteristics of some CISC and RISC processors
Lecture 2 - 10
The architectural characteristics of RISC machines include: one instruction completion per clock cycle. (This means that each pipeline stage needs fit in one clock cycle) large number of registers with register-to-register operations (e.g., “ADD R2, R3, R4,” where R2 gets the results of R3 + R4). Register operands are already in the CPU so they are fast to access. simple addressing modes because complex address calculations might take longer that one clock cycle simple, fixed-length instruction formats. Fixed-length instructions require a fixed amount of time to fetch. Simple instruction formats can be decoded in a clock cycle. MIPS instruction formats are all 32-bits, and are as follows
Arithmetic: add R1, R2, R
opcode
opcode
opcode
opcode
opcode
dest reg
operand
operand
operand
operand
1 reg
1 reg
1 reg
reg
operand
operand
operand
base
2 reg
2 reg
2 reg
reg
Conditional Branch: beq R1, R2, end_if
Arithmetic with immediate: addi R1, R2, 8
Load/Store: lw R1, 16(R2)
unused
offset to label
offset from
Unconditional Branch/"jump": j someLabel PC-relative
base reg
large offset from PC or absolute address
immediate value
hardwired control unit. The simple instructions can be performed using hardwired control unit that allows for a fast clock cycle
Lecture 2 - 11