Presentation is loading. Please wait.

Presentation is loading. Please wait.

Toward a general purpose computer II Example: Game of Life.

Similar presentations


Presentation on theme: "Toward a general purpose computer II Example: Game of Life."— Presentation transcript:

1 Toward a general purpose computer II Example: Game of Life

2 Problems in the previous implementation 1. Similar instructions in different parts of the algorithm require different lines Very large ROM

3 Example N = N+1 tmp = i+1 Target = A + B

4 Problems in the previous implementation 2. All the variables of the algorithm are stored in registers. 1. Change in the algorithm will require change in hardware 2. Registers are expansive. 3. There is limited space.

5 Solution to 1 (and 2) Define more general instructions The algorithm will be a set of the general instructions.

6 List of instruction in game of life $3 = $1 + $2 $3 = $1 – $2 $3 = And($1,$2) $3 = OR($1,$2) $3 = Decode($1) $3 = set on less $1,$2 $1 = VAL Register no. 2

7 The set on less instruction $3 = set on less $1,$2 $3 = 00000…01 if $1 < $2 $3 = 00000…00 otherwise.

8 ALU codes The operationALU code $3 = $1 + $2000 $3 = $1 – $2001 $3 = And($1,$2)010 $3 = OR($1,$2)011 $3 = Decode($1)100 $3 = set on less $1,$2101

9 Solution to 2 Move the variables to the RAM We will need instructions to load and store registers in the RAM

10 Load and Store instructions Load addr,$1 – load address into $1 Store addr, $1 – store $1 into addr

11 Instruction control Goto the next instruction j Addr Jump to instruction in address addr

12 Control the PC branching 1 2 3 4

13 1 2 3 4 1.PC = PC+1 2.Check xxx happened If it didn’t PC = 4 3.IR  PC

14 PC control Jne $1,$2,Addr If $1 ≠ $2  Goto Addr Je $1,$2,Addr If $1 = $2  Goto Addr

15 The instructions in the system $3 = $1 + $2 $3 = $1 – $2 $3 = And($1,$2) $3 = OR($1,$2) $3 = Decode($1) $3 = set-on- less($1,$2) $1 = VAL Arithmetic/Logic operations Load addr,$1 Store addr,$1 Memory related operations j Addr Jne $1,$2,Addr Je $1,$2,Addr Control operations Instruction

16 Assumptions: We have 16 registers $1…$26 ($0 is always zero). The RAM has 65536 entries of 16bits (16bit address) The program ROM has 65536 entries of 32bits each.

17 The structure of instructions Arithmetic logic 2 bits3 bits4 bits Type: Arithmetic, memory or control Sub Type Additions, subtraction Reg1 address Reg2 Address Target Address [0-4] First 5 bits reserved Total 16 registers [5-8][9-12] [13-16]

18 The structure of instructions $1 = VAL 2 bits1114 bits16 bits Type: Arithmetic, memory or control Set Reg1 address The value [0-4] First 5 bits reserved [5-8][9-24]

19 The structure of instructions Memory instruction 2 bits1 bit004 bits16 bits Type: Arithmetic, memory or control Sub Type Store/load EmptyReg address Address load/store addr,$1 [0-4] [5-8][9-24]

20 The structure of instructions Control instructions 2 bits 04 bits 16 bits Type: Arithmetic, memory or control Sub Type J,jne,je EmtpyReg address Address j/jne/je $1,$2,Addr [0-4] [5-8][9-12] [13-28]

21 Note about the control instructions In the j instruction we ignore the first and second fields.

22 The components of the circuit: The ALU ALU Operation Code Operand AOperand B Result Is zero (1 bit)

23 The components of the circuit: The Registers Registers Data 1 Data 2 Data 1 Address Data 2 Address WriteAddress Write Data Write

24 The components of the circuit: The RAM RAM Data 1 Read Address WriteAddress Write Data Write Read Note 1: The RAM is the one you saw in class without the MAR and MBR Note 2: The RAM is implemented with Latches!

25 The components of the circuit: The PC and the program PC – holds the next address IR - holds the current instruction PC Program ROM Write IR Write

26 A note before implementation Several time cycles were lost because not all instructions have the same number of steps. Solution: Use a counter for the micro-instructions. CAR

27 The components of the circuit: CAR, example with arithmetic instruction CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: Perform the code CAR = 0 Goto the next instruction

28 The components of the circuit: CAR, example with jne $1,$2,Addr CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: $1-$2, if not zero PC  Addr CAR = 0 Goto the next instruction

29 The components of the circuit: CAR, example with arithmetic instruction CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: Perform the code Goto the next instruction For efficiency, we will NOT use the ALU here.

30 The CAR circuit CAR Adder 1 MUX C1 000

31 ALU 16 Registers RAM PC Program ROM IR 1 4 5 1 [BITS 13-28] [BITS 5-8] [BITS 9-12] [BITS 9-24] 2 [BITS 13-16] [BITS 5-8] [BITS 9-24] [BITS 5-8] 3

32 ALU 16 Registers RAM PC Program ROM IR 1 4 5 1 3 2 Mirco-instructions [BITS 0-4] All the control in the system CAR 0 2 1 0 1 0 1 0 1 [BITS 13-28] [BITS 5-8] [BITS 9-12] [BITS 9-24] [BITS 13-16] [BITS 5-8] [BITS 9-24] [BITS 5-8]

33 ALU 16 Registers RAM PC Program ROM IR 1 4 5 1 3 2 Write Read Write ALUop IRloadPCload Mux3 Mux2 Mux1 Mux4 Mux5 CAR control

34 The micro-instruction ROM Inst.CAR ALU op PC load IR load RAM read RAM write Reg Write CAR control Mux 12345

35 The micro-instruction ROM Example: Inst.CAR ALUopPC load IR load RAM read RAM write Reg Write CAR control Mux 12345 000000000110001XX111 00000100000001021X00 CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: $3=$2+$1 CAR = 0

36 The micro-instruction ROM Example: Inst.CAR ALUop PC load IR load RAM read RAM write Reg Write CAR control Mux 12345 000000000110001XX211 00000100000001021X00 CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: $3=$2+$1 CAR = 0 The meaning is: Put in PC the result Of PC+1 We don’t care about these

37 The micro-instruction ROM Example: Inst.CAR ALUop PC load IR load RAM read RAM write Reg Write CAR control Mux 12345 000000000110001XX211 00000100000001021X00 CAR = 0: IR  PC, PC=PC+1, CAR=CAR++ CAR = 1: $3=$2+$1 CAR = 0

38 In addition In order to implement the jne instruction we need a conditional write on the PC. The essence is in here

39 Addition to the ROM: Inst.CAR Branch Equal Branch NotEqual 1-bit flags that are used in the jne,je

40 ALU PC Program ROM IR Mirco-instructions Zero status bit Branch equal Branch not equal PC write

41 The program ROM AddressInstructionMeaning 000000000000100100011$3=$2+$1 0001…… Instruction type 00 Instruction sub type Reg1 Reg2 Reg3

42 Saving more space The fetch is divided into 2 cycles Fetch instruction Goto Right instruction The ROM will depend on the CAR alone

43 CAR Arithmetic = 1 micro instruction Load = 2 micro instructions Store = 2 micro instructions

44 CAR – the instruction-CAR table InstructionCAR Arithmetic Operation 00010 Load00011 00100 Store00101 00110

45 CAR – Order of execution CAR Fetch00000 Goto the right instruction 00011 InstructionCAR Arithmetic Operation 00010 Load00011 00100 Store00101 00110 Assume we are executing the instruction Load …

46 CAR – Order of execution CAR Fetch00000 Goto the right instruction 00011 InstructionCAR Arithmetic Operation 00010 Load00011 00100 Store00101 00110 Assume we are executing the instruction Load …

47 CAR – Order of execution CAR Fetch00000 Goto the right CAR 00011 InstructionCAR Arithmetic Operation 00010 Load00011 00100 Store00101 00110 Assume we are executing the instruction Load …

48 Implementation of the Goto in the CAR circuit CAR Adder 1 MUX C1C2 000 Instruction CAR table The Instruction

49 ALU 16 Registers RAM PC Program ROM IR 1 4 5 1 3 2 Mirco-instructions [BITS 0-4] All the control in the system CAR 0 2 1 0 1 0 1 0 1 [BITS 13-28] [BITS 5-8] [BITS 9-12] [BITS 9-24] [BITS 13-16] [BITS 5-8] [BITS 9-24] [BITS 5-8]

50 The micro-instruction ROM CAR ALU op PC load IR load RAM read RAM write Reg Write CAR control Mux 12345 The micro instruction ROM depends on the CAR only now.


Download ppt "Toward a general purpose computer II Example: Game of Life."

Similar presentations


Ads by Google