Professional Documents
Culture Documents
Programmable Machines
C:
int a = 1;
int b = N;
do {
a = a * b;
b = b – 1;
} while (b != 0)
initially: a = 1, b = 5
after iter 1: a = 5, b = 4
after iter 2: a = 20, b = 3
after iter 3: a = 60, b = 2
after iter 4: a = 120, b = 1
after iter 5: a = 120, b = 0
Done!
C: High-level FSM:
int a = 1;
int b = N; b’!=0
do { b’==0
a = a * b; start loop done
b = b – 1;
} while (b != 0) a ß 1 a ß a * b a ß a
b ß N b ß b - 1 b ß b
start: a ← 1, b ← 5
loop: a ← 5, b ← 4 – Helpful to translate into hardware
loop: a ← 20, b ← 3 – D-registers (a, b)
loop: a ← 60, b ← 2 – 2-bits of state (start, loop, done)
loop: a ← 120, b ← 1
loop: a ← 120, b ← 0
– Boolean transitions (b’==0, b’!=0)
done: – Register assignments in states
(e.g., a ß a * b)
2 2
waSEL 0 1 2 wbSEL 0 1 2
32 32
a b
32 32
-1
*
+
32 32
1 N
Control waSEL (2 bits)
FSM wbSEL (2 bits)
waSEL 0 1 2 wbSEL 0 1 2
S Z waSEL wbSEL S’
z
00 0 10 00 01
a b
00 1 10 00 01
0
01 0 01 01 01
-1
01 1 01 01 10
* ==
+ 10 0 00 10 10
10 1 00 10 10
z
6.004 Computation Structures L09: Programmable Machines, Slide #5
Control FSM Hardware
ROM
8 locs x 6 bits ROM contents
A[0] D[5:4] waSEL A[2:0] D[5:0]
IN
000 10 00 01
D[3:2] wbSEL
001 10 00 01
A[2:1] D[1:0] 010 01 01 01
Current Next 011 01 01 10
state state 100 00 10 10
101 00 10 10
2 2
Internal storage
control
Control
Datapath status Unit
Main Memory
PC 1101000111011
dest R1 ←R2+R3
asel bsel
• Program Counter or PC: Address
of the instruction to be executed
fn ALU status • Logic to translate instructions into
operations control signals for datapath
Compute next PC
General Registers
Why separate registers and main memory?
r31 hardwired to 0 Tradeoff: Size vs speed and energy
rc
… 0
32 registers PC
ra rb 4 +
fn ALU
operations
OPCODE =
rc=3, ra=1, 16-bit two’s
110000, encoding
encoding R3 encoding R1 complement constant,
ADDC
as destination as first encoding -3 as second
operand operand (will be sign-
Symbolic version: ADDC(r1,-3,r3) extended to become 32-bit
two’s complement operand)
rc
… 0
32 registers PC
ra rb 4 +
sxt(const)
bsel
fn ALU
operations
b == 0
mul sub loop done
a ß a * b b ß b - 1 Conditional
branch Branch not
taken
011011 rc ra unused
JMP(Ra,Rc): Reg[Rc] ← PC + 4
PC ← Reg[Ra]
… 04
R28 = 0x1 sqrt:
[0x100] BEQ(R31,sqrt,R28)
…
…
JMP(R28,R31)
[0x678] BEQ(R31,sqrt,R28)
… 1st time: PC←0x104
2nd time: PC←0x67C
6.004 Computation Structures L09: Programmable Machines, Slide #32
Beta ISA Summary
• Storage:
– Processor: 32 registers (r31 hardwired to 0) and PC
– Main memory: 32-bit byte addresses; each memory access
involves a 32-bit word. Since there are 4 bytes/word, all
addresses will be a multiple of 4.
OPCODE rc ra rb unused
• Instruction formats:
OPCODE rc ra 16-bit signed constant
32 bits
• Instruction types:
– ALU: Two input registers, or register and constant
– Loads and stores
– Branches, Jumps
6.004 Computation Structures L09: Programmable Machines, Slide #33