加州理工学院-计算系统导论 (18)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
UPDATE OUR ISA AND PROCESSOR
¢ Add a new instruction: BRZ A, Addr (Branch if Zero)
If value in slot A is 0, change Prog Ctr to address Addr
¢ New logic to support this instruction:
¢ Branch Logic:
If opcode is BRZ, and memory A outputs 0, then tell multiplexer to load Addr into the Program Counter.
UPDATED PROCESSOR
¢ With updated processor, can reuse instructions by creating loops in our programs
p = p + b;
1001
a = a >> 1;
1010
b = b << 1;
1011
}
1100
return p;
}
1110
¢ Coding is more complex now!
Need to plan out our loops…
Need to know the addresses to jump to!
Operation
ADD
AB
SUB
AB
NEG
A
BRZ
A Addr
AND
AB
OR
AB
XOR
AB
INV
A
SHL
A
SHR
A
WRITING OUR PROGRAM
¢ Use same general process as before ¢ Step 1: identify inputs and outputs
Perform many computations with just a few instructions
¢ Can now implement computations where number of steps is dependent on program’s inputs
BACK TO MULTIPLICATION
communicate via memory locations
¢ Implemented a computation on this processor:
Assigned memory locations for inputs, outputs, constants Decomposed the computation into steps the processor could
int mul(int a, int b) { int p = 0; while (a != 0) { if (a & 1 == 1) p = p + b; a = a >> 1; b = b << 1; } return p;
}
¢ Inputs: A, B, some constant(s) ¢ Outputs: P
int mul(int a, int b) { int res = 0; while (a != 0) { if (a & 1 == 1) p = p + b; a = a >> 1;
Control Operation
0001 ADD
AB
0011 SUBAB来自0100 NEGA
1000 AND
AB
1001 OR
¢ (Don’t know how many though…)
Need to keep track of various addresses for branching
actually handle Assigned locations to intermediate values Translated the program into machine-code instructions
MULTIPLICATION…
¢ Then, we wanted to implement multiplication:
CS 24: INTRODUCTION TO COMPUTING SYSTEMS
Spring 2013 Lecture 3
LAST TIME
¢ Basic components of processors:
Buses, multiplexers, demultiplexers Arithmetic/Logic Unit (ALU) Addressable memory
WRITING OUR PROGRAM (2)
¢ Step 2:
Decompose program into processor instructions.
¢ This step will be much more involved now:
May need quite a few temporary values
AB
b = b << 1;
1010 XOR
AB
} return p; }
1011 INV
A
1100 SHL
A
1110 SHR
A
¢ But, we couldn’t write this program:
Our processor doesn’t support branching operations!
¢ Assembled components into a simple processor
Can perform a wide range of operations, but all very simple Need to string together a sequence of instructions, which
¢ Should have enough capability now to encode our program
Control 0001
int mul(int a, int b) {
0011
int p = 0;
0100
while (a != 0) {
0111
if (a & 1 == 1)
1000