Islamic University – Gaza Engineering Faculty Department of Computer Engineering ECOM 3010: Computer Architecture Discussion Chapter 5 Exercises with solutions Eng. Eman R. Habib December, 2013 2 Computer Architecture Discussion Exercise 1: (5.1 from book) Combinational logic only: a, b, c, h, i Sequential logic only: f, g, j Mixed sequential and combinational: d, e, k Exercise 2: (5.2 from book) 3 Computer Architecture Discussion a. RegWrite = 0: All R-format instructions, in addition to lw, will not work because these instructions will not be able to write their results to the register file. b. ALUop1 = 0: All R-format instructions except add will not work correctly because the ALU will perform addition instead of the required ALU operation. c. ALUop0 = 0: beq instruction will not work because the ALU will perform addition instead of subtraction, so the address of branch may be wrong. d. Branch (or PCSrc) = 0: beq will not execute correctly. The branch instruction will always be not taken even when it should be taken. e. MemRead = 0: lw will not execute correctly because it will not be able to read data from memory. f. MemWrite = 0: sw will not work correctly because it will not be able to write to the data memory. Exercise 3: (5.3 from book) a. RegWrite = 1: sw and beq should not write results to the register file. sw (beq) will overwrite a random register with either the store address (branch target) or random data from the memory data read port. b. ALUop0 = 1: All R-format instructions except subtract, in addition to lw and sw will not work correctly because they will always perform subtraction. c. ALUop1 = 1: lw and sw and beq will not work correctly. they will perform a random operation depending on the least significant bits of the address field instead of addition operation necessary for address calculation in lw and sw, or subtraction for beq. d. Branch = 1: Instructions other than branches (beq) will not work correctly if the ALU Zero signal is raised. An R-format instruction that produces zero output will branch to a random address determined by its least significant 16 bits. Computer Architecture Discussion e. MemRead = 1: All instructions will work correctly. (Data memory is always read, but )memory data is never written to the register file except in the case of lw. f. MemWrite = 1: Only sw will work correctly. The rest of instructions will store their results in the data memory, while they should not. )Exercise 4: (5.8 from book jr $rs 000000 / rrrrr / 00000 /00000 / 00000 / 001000 لما بدنا نضٌف انستركشٌن على السٌنجل ساٌكل اول شً نتزكر شو بتعمل االنستركشٌن و شو فورماتها jr rs ,بتعمل جمب على االدرٌس المخزن بالرٌجٌستٌر rsو االنستركشٌن تعتبر R-formatاول 6بتات حٌكونو اصفار و ال 5بتات الً بعدهم حٌكونو rsو الباقً كلو اصفار و مش الزمٌن و اخر 6بتات بتحدد الفنكشٌن . بعدٌن بنشوف شو الزم نعدل على الداتا باث عشان تعمل هً االنستركشٌن ,ال jrبتاخد الداتا الموجودة بال rsالً هٌا رح تطلع من الرٌجٌستر فاٌل اول رٌجٌسٌتر ( ) Read Data 1 portو تودٌها على ٌ PCعنً الزم نغٌر االنبت اللً جاي على PCبدل ما كان من الملتبلٌكسٌر اللً بحدد ناخد من PC+4او ادرٌس البرانش ,الزم نضٌف بعدو كمان ملتٌبلكسٌر و نحط االنبت االول الو هوا اوتبت الملتبلٌكسٌر القدٌم و االنبت التانً الداتا اللً جاٌة من Read Data 1 portو السٌلكشٌن الٌن للمتلٌبلكسٌر بدو ٌكون كنترول سٌجنال جدٌد نسمٌه JumpRegبس مش حنقدر نطلع هاد الكنترول سٌجنل من الكنترول ٌونت النو انبت الكنترول ٌونت بس ال) OP (6bitsو النو jrمن R-typeفحتكون زي باقً االنستركشٌنز اللً ب R-typeكلهم اصفار فمش حقدر احدد من 6 bitsانها jrو بدل ما نكبر الكنترول ٌونت و نضٌف علٌها function 6 bitsممكن ناخد هاد الكنترول سٌجنل من ALU controlالنو هً بفوت علٌها function 6 bitsاما االوبٌرشٌن مش رح تهمنً النو ما بدي استخدم ALUفحنضٌف على تٌبل ALU controlهاد الالٌن: JumpReg 1 Operation xxx Function field 001000 ALUOp0 0 ALUOp1 1 4 Computer Architecture Discussion و التعدٌل على السٌنجل ساٌكل حٌكون هٌك: )Exercise 5: (5.9 from book sll $rd, $rt, SA 000000 / 00000 / ttttt / ddddd / sssss / 000000 بدي اضٌف sllاول شً االنستركشٌن sll $rt, $rd, SAبتعمل شٌفت للرٌجسٌتر $rtبقٌمة SAو بتخزن النتٌجة ب $rdو االنستركشٌن تعتبر R-formatاول 6بتات حٌكونو اصفار و ال 5بتات الً بعدهم حٌكونو غٌر مستخدمٌن و ال 5بتات الً بعدهم بكونو $rtبعدٌن 5بتات $rdبعدٌن 5بتات Shift amountو اخر 6بتات بتحدد الفنكشٌن . بعدٌن بدنا نشوف شو الزم نعدل على الداتا باث عشان تعمل هً االنستركشٌن ,بٌلزمنا نعدل على ALUو نحط فٌها shifterو نزٌد علٌها بورت لل SAعشان تاخد المدخل التانً لل ALUو تعملو شٌفت بقٌمة SAولهٌك الزم اعدل على ALU controlانو لما ٌكون ALUOp = 10و بتات الفٌنكشٌن ٌ 000000عنً sllتطلع ٌ 0000عنً الزم نضٌف بت جدٌد الوتبت ال ALU controlلما ٌكون 0رح ٌاخد اوتبت ال .Shifterو التعدٌل على الداتا باث انو الزم اخد بتات ال Instrection[10-6] SAو اودٌهم على البورت للجدٌد لل .ALUو ما رح ٌلزم كنترول سٌجنل جدٌد. وبما انها R-typeما رح ٌكون فً زٌادة على تٌبل . Control unit 5 Computer Architecture Discussion و حنضٌف على تٌبل ALU controlهاد الالٌن: Operation 1000 Function field 000000 ALUOp0 0 ALUOp1 1 و التعدٌل على السٌنجل ساٌكل حٌكون هٌك: )Exercise 6: (5.10 from book lui $rt, immediate 001111 / 00000 / ttttt / iiiiiiiiiiiiiiii بدي اضٌف luiاول شً االنستركشٌن lui $rt, immediateبتخزن االٌمٌدٌت باخر 06بت من الرٌجٌستر $rtو االنستركشٌن تعتبر I-formatاول 6بتات بحددو االنسترٌكشٌن و ال 5بتات الً بعدهم حٌكونو غٌر مستخدمٌن و ال 5 بتات الً بعدهم بكونو $rtبعدٌن 06بت .immediate 6 Computer Architecture Discussion ممكن اخد ال 06بت اللً باالخر افوتهم على الساٌن اكستٌنشٌن بعدٌن افوتهم على ALUو اخلٌها تعمل شٌفت 06هٌك بصٌر االٌمٌدٌت بال 06بت اللً باالخر و ال 06بت اللً باالول اصفار. بعدٌن بدنا نشوف شو الزم نعدل على الداتا باث عشان تعمل هً االنستركشٌن ,بٌلزمنا نعدل على ALUو نحط فٌها shifterو نزٌد علٌها بورت لل SAنفوت علٌه رقم “10000” 06عشان تاخد المدخل التانً لل ALUو تعملو شٌفت 06بت ولهٌك الزم اعدل على ALU controlانو لما ٌكون ALUOp = 11تطلع ٌ 0000عنً الزم نضٌف بت جدٌد الوتبت ال ALU controlلما ٌكون 0رح ٌاخد اوتبت ال .Shifterو ما رح ٌلزمنً تعدٌل على الداتا باث. و حنضٌف على تٌبل ALU controlهاد الالٌن: Operation 1000 Function field xxxxxx ALUOp1 1 ALUOp0 1 وعلى تٌبل Control unitرح نضٌف هاد الالٌن: Branch ALUOp 11 0 Mem Write 0 Mem Read 0 Reg Write 1 MemtoReg ALUSrc 0 1 Instruction RegDst 0 lui RegDstالزم تكون 0النو بدي اخزن نتٌجة الشٌفت بالرٌجٌستر Instrection[20-16] rt ALUSrcالزم تكون 1النو المدخل التانً لل ALUالزم ٌكون اوتبت Sign extend MemtoRegالزم تكون 0النو ما بدي اخد من المٌموري بدي اخد اوتبت ال ALUالً رح تعمل الشٌفت و اخزنو بالرٌجٌستٌر فاٌل RegWriteالزم تكون 0النو بدي اكتب على الرٌجٌستٌر فاٌل MemRead, MemWriteبحطهم زٌرو النو مش رح استخدم المٌموري ال رح اقرأ منها و ال رح اكتب علٌها Branchالزم تكون زٌرو النو مش رح اعمل برانش و بدي الٌ PCصٌر PC+4 ALUOpرح احطها 00النو رح تعمل شً جدٌد ” “sllبدون ما تتطلع على بتات الفنكشٌن 7 Computer Architecture Discussion و التعدٌل على السٌنجل ساٌكل حٌكون هٌك: )Exercise 7: (5.11 from book هنا رح ٌلزمنً اضٌف كمان write portعلى الرٌجٌستٌر فاٌل النو الزم اكتب على رٌجٌسترٌن و بدي اضٌف كنترول سٌجنل اسمٌه ”ٌ “Regwrite2كون 0لما بدي اكتب على الرٌجٌستر التانً و رح اعتبر انو الراٌت بورت التانً رح تتخزن الداتا الً رح تفوت علٌه داٌما بنفس الرٌجٌستر instruction[25-21] rsو هٌك بضل اضٌف incrementerعند الراٌت بورت التانً و ٌكون فاٌت علٌه .Read Data 1 و ما رح ٌكون فً تعدٌل على .ALU control 8 9 Computer Architecture Discussion : رح نضٌف هاد الالٌنControl unit ورح اضٌف على تٌبل Instruction RegDst ALUSrc l_inc 0 1 Memto Reg 1 Reg Write 1 Mem Read 1 Mem Branch ALUOp Write 0 0 00 Reg Write2 1 رحRegWrite2 بس رح ٌكون زٌادة الكنترول سٌجنل الجدٌدlw كل الكنترول سٌجنلز حٌكونو نفسهم النستركشٌن .write data 2 port عشان اكتب على0 ٌكون :و التعدٌل على السٌنجل ساٌكل حٌكون هٌك 10 Computer Architecture Discussion Exercise 8: (5.12 from book) This instruction requires two writes to the register file. The only way to implement it is to modify the register file to have two write ports instead of one. Such a modification of the register file architecture may not be required for a multiple- cycle implementation, since multiple writes to the same port can occur on different cycles. Exercise 9: (5.13 from book) يعنيdon’t care نفس انقيم و انباقيlw وR-format النو باننسبة نمALUSrc بMemtoReg ممكن استبدل .0 او0 ما رح يفرق اذا don’t care نفس انقيم و انباقيlw وR-format النو باننسبة نمMemRead بMemtoReg ممكن استبدل .0 او0 يعني ما رح يفرق اذا انقيمsw نفس انقيم اماlw وR-format او انعكس النو باننسبة نمALUSrc بMemRead ما بينفع استبدل .بتختهف 11 Computer Architecture Discussion Exercise 10: (5.14 from book) swap $rs,$rt can be implemented by: addi $rd,$rs,0 addi $rs,$rt,0 addi $rt,$rd,0 if there is an available register $rd or: sw $rs,temp($r0) addi $rs,$rt,0 lw $rt,temp($r0) if not. Exercise 11: (5.31 from book) MemRead اوALUSrc اوMemtoReg اوALUOp1 بRegDst ممكن استبدل MemRead اوALUSrc اوALUOp1 اوRegDst بMemtoRegممكن استبدل Computer Architecture Discussion ممكن استبدل Branchو ALUOp0ببعض Exercise 12: Add bne to single cycle. بدي اضٌف bneرح تشتغل نفس beqانو بدي احسب االدرس بانً اعمل شٌفت لٌفت 2بعدٌن اجمعو ل PC+4و رح اخلً ال ALUتطرح الرٌجٌسترٌن بس رح تختلف بانو اذا كان الزٌرو سٌجنل بٌساوي ٌ 0عنً مش متساوٌٌن هنا بعمل ا لبرانش و هٌك رح ٌلزمنً اعدل على السٌلٌكشن الٌن للملتبلٌكسٌر اللً بحدد اذا حعمل برانش او الء بانو اضٌف and بفوت علٌها not zeroو كنترول سٌجنل جدٌد بسمٌه BranchnotEqو االند القدٌمة مع االند الجدٌدة بفوتو على ٌ orعنً اذا اجت beqو تحققت او bneو تحققت ٌعمل برانش على االدرس اللً حسبو. و ما رح ٌكون فً تغٌٌر على ALU controlالنو ALUرح تعمل نفس لو اجت .beq و تٌبل Control unitرح نضٌف هاد الالٌن: Branch notEq ALUOp Jump Branch Mem Write Mem Read Reg Write Memto Reg ALUSrc RegDst Ins 1 01 0 0 0 0 0 x 0 x bne RegDst, RegWrite, MemtoRegهدول كلهم ما بهمونً النو ما رح اخزن شً على الرٌجٌستٌر فاٌل ALUSrcالزم تكون 0النو المدخل التانً لل ALUالزم ٌكون Read Data 2من الرٌجٌستر فاٌل MemRead, MemWriteبحطهم زٌرو النو مش رح استخدم المٌموري ال رح اقرأ منها و ال رح اكتب علٌها Branch, Jumpما بدي اعمل برانش و ال جمب فحٌكونو 0 ALUOpالزم احطها 00النو بدي اعمل subtract BranchnotEqالسٌجنل الجدٌد بحطو 0عشان تعمل برانش لما ٌكون السٌجنل زٌرو = 0 12 Computer Architecture Discussion و التعدٌل على السٌنجل ساٌكل حٌكون هٌك: Exercise 13: Add jal to single cycle. jal address )000011 / 26 bit (address بدي اضٌف jalاول شً االنستركشٌن jal addressبتعمل شغلتٌن اول شً بتعمل جمب و بنحسب بنفس طرٌقة ال j انو ٌعمل شٌفت لٌفت 2بعدٌن ٌضٌف باالخر اخر 4بت من PC+4و الشغلة التانٌة انها بتحط االدرس للنٌكسٌت انستركشٌن ب ٌ $raعنً رح تحط PC+4ب.$ra والزم نعدل على الداتا باث انو اضٌف ملتٌبلٌكسر عند Write dataبالرٌجسٌتر فاٌل بعد المٌلتبلٌكسٌر اللً بحدد اذا بدي اكتب الداتا الً جاٌة من ال ALUاو من المٌموري و ٌكون السٌلٌكشٌن الٌن الو كنترول سٌجنل جدٌد اسمٌه jalو االنبت االول للمتلٌبلٌكسر ٌكون الملتٌبلكسٌر القدٌم و االنبت التانً PC+4فلما تكون jal=1رح ٌكتب بالرٌجٌستر فاٌل PC+4 كمان الزم اقلو ٌكتب الداتا بالرٌجستر $raفالزم اضٌف كمان ملتبلٌكسٌر عند Write registerبعد الملتٌبلكسٌر اللً بحدد اخد rtاو rdو ٌكون السٌلكشٌن الكنترول سٌجنل الجدٌد jalو ٌكون االنبت االول الملتٌبلكسٌر القدٌم و االنبت التانً " "00000رقم الرٌجٌستٌر $raالنو رقمو 10فلما تكون jal=1رح ٌكون الرٌجٌستٌر الدٌستٌنٌشن هوا .$ra و ما رح ٌلزم تعدٌل على ALU controlالنو ما رح استخدم .ALU 13 Computer Architecture Discussion و على تٌبل Control unitرح نضٌف هاد الالٌن: Jal ALUOp Jump Branch Mem Write Mem Read Reg Write Memto Reg ALUSrc RegDst Ins 1 xx 1 0 0 0 1 x x x jal RegDstما رح تهمنً النو مش رح اخد اوتبت الملتبلٌكسٌر هاد ALUSrcما بتهمنً النو مش رح استخدم ALU MemtoRegما رح تهمنً النو مش رح اخد اوتبت الملتبلٌكسٌر هاد RegWriteالزم تكون 0النو بدي اكتب على الرٌجٌستٌر فاٌل على $ra MemRead, MemWriteبحطهم زٌرو النو مش رح استخدم المٌموري ال رح اقرأ منها و ال رح اكتب علٌها Branchما بتهمنً النو ما رح اعمل برانش بحطها 0 Jampالزم تكون 0النو رح اعمل جمب و رح اخد ادرٌس الجمب ALUOpما بتهمنً النو مش رح استخدم ALU Jalالكنترول سٌجنل الجدٌد الزم ٌكون 0عشان ٌختار الداتا PC+4و الرٌجسٌتر $ra و التعدٌل على السٌنجل ساٌكل حٌكون هٌك: 14 15 Computer Architecture Discussion Exercise 14: (5.29 from book) a. RegWrite = 0: All R-format instructions, in addition to lw, will not work because these instructions will not be able to write their results to the register file. b. MemRead = 0: None of the instructions will run correctly because instructions will not be fetched from memory. c. MemWrite = 0: sw will not work correctly because it will not be able to write to the data memory. d. IRWrite = 0: None of the instructions will run correctly because instructions fetched from memory are not properly stored in the IR register. e. PCWrite = 0: jump instructions will not work correctly because their target address will not be stored in the PC. beq will not work correctly because the PC+4 will not written into PC so the addition with the sign extended will be wrong. And the next instruction will not execute because the PC will not incremented. f. PCWriteCond = 0: Taken branches will not execute correctly because their target address will not be written into the PC. Exercise 15: (5.30 from book) a. RegWrite = 1: Jump and branch will write their target address into the register file. sw will write the destination address or a random value into the register file. b. MemRead = 1: All instructions will work correctly. Memory will be read all the time, but IRWrite and IorD will safeguard this signal. 16 Computer Architecture Discussion c. MemWrite = 1: All instructions will not work correctly. Both instruction and data memories will be written over by the contents of register B. d. IRWrite = 1: lw will not work correctly because data memory output will be translated as instructions. e. PCWrite = 1: All instructions except jump will not work correctly. This signal should be raised only at the time the new PC address is ready (PC + 4 at cycle 1 and jump target in cycle 3). Raising this signal all the time will corrupt the PC by either ALU results of Rformat, memory address of lw / sw, or target address of conditional branch, even when they should not be taken. f. PCWriteCond = 1: Instructions other than branches (beq) will not work correctly if they raise the ALU's Zero signal. An R-format instruction that produces zero output will branch to a random address determined by their least significant 16 bits. Exercise 16: (5.32 from book) We use the same datapath, so the immediate field shift will be done inside the ALU. 1. Instruction fetch step: This is the same (IR <= Memory[PC]; PC <= PC + 4) 2. Instruction decode step: We don't really need to read any register in this stage if we know that the instruction in hand is a lui, but we will not know this before the end of this cycle. It is tempting to read the immediate field into the ALU to start shifting next cycle, but we don't yet know what the instruction is. So we have to perform the same way as the standard machine does. A <= 0 ($r0); B <= $rt; ALUOut <= PC + (sign-extend(immediate field)); 3. Execution: Only now we know that we have a lui. We have to use the ALU to shift left the low-order 16 bits of input 2 of the multiplexor. (The sign extension is useless, and sign bits will be flushed out during the shift process.) ALUOut <= sll {sign-extend(IR[15:0]),16} 4. Instruction completion: Reg[IR[20-16]] = ALUOut. 17 Computer Architecture Discussion The first two cycles are identical to the FSM of Figure 5.38. By the end of the second cycle the FSM will recognize the opcode. We add the Op='lui', a new transition condition from state 1 to a new state 10. In this state we perform the left shifting of the immediate field: ALUSrcA = x, ALUSrcB = 10, ALUOp = 11 (assume this means left shift of ALUSrcB). State 10 corresponds to cycle 3. Cycle 4 will be translated into a new state 11, in which RegDst = 0, RegWrite = 1, MemtoReg = 0. State 11 will make the transition back to state 0 after completion. As shown above the instruction execution takes 4 cycles. From state 1 Op = 'lui' 10 ALUSrcA = x ALUSrcB = 10 ALUOp = 11 11 RegDst = 0 RegWrite = 1 MemtoReg = 0 To state 0 Exercise 17: (5.33 from book) 18 Computer Architecture Discussion This solution can be done by modifying the data path to extract and shift the immediate field outside the ALU. Once we recognize the instruction as lui (in cycle 2), we will be ready to store the immediate field into the register file the next cycle. This way the instruction takes 3 cycles instead of the 4 cycles of Exercise 5.32. 1. Instruction fetch step: Unchanged. 2. Instruction decode: Also unchanged, but the immediate field extraction and shifting will be done in this cycle as well. 3. Now the final form of the immediate value is ready to be loaded into the register file. The MemtoReg control signal has to be modified in order to allow its multiplexor to select the immediate upper field as the write data source. We can assume that this signal becomes a 2-bit control signal, and that the value 2 will select the immediate upper field. 19 Computer Architecture Discussion The first two cycles are identical to the FSM of Figure 5.38. By the end of the second cycle, the FSM will recognize the opcode. We add the Op = 'lui', a new transition condition from state 1 to a new state 10. In this state we store the immediate upper field into the register file by these signals: RedDst = 0, RegWrite = 1, MemtoReg = 2. State 10 will make the transition back to state 0 after its completion. From state 1 Op = 'lui' 10 RegDst = 0 RegWrite = 1 MemtoReg = 10 To state 0 Exercise 17: (5.34 from book) We can use the same datapath. 1. Instruction fetch: Unchanged (IR <= Memory[PC]; PC<= PC + 4). 2. Instruction decode: Unchanged (A <= Reg[IR[25-21]]; B<=REG[IR[20-16]]; ALUOut<=PC+(sign-extend(IR[15-0])<<2). 3. Load immediate value from memory (MDR <= Memory[PC]; PC <= PC + 4). 4. Complete instruction (Reg[IR[20-16]] (dependent on instruction format) <= MDR). The first two cycles are identical to the FSM of Figure 5.38. We add the Op='ldi', a new transition condition from state 1 to a new state 10. In this state we fetch the immediate value from memory into the MDR: MemRead = 1, ALUSrcA = 0, IorD = 0, MDWrite = 1, ALUSrcB = 01, ALUOp = 00, PCWrite = 1, PCSource = 00. FSM then makes the transition to another new state 11. In this state we store the MDR into the register file by these signals: RedDst = 0 (actually depends on the instruction format), RegWrite = 1, MemtoReg = 1. State 11 will make the transition back to state 0 after its completion. Four cycles to complete this instruction, in which we have two instruction memory accesses. 20 Computer Architecture Discussion From state 1 Op='ldi' 10 11 MemRead = 1, ALUSrcA = 0, IorD = 0, IRWrite = 0, ALUSrcB = 01, ALUOp = 00, PCWrite = 1, PCSource = 00 RedDst = 0, RegWrite = 1, MemtoReg = 1 To state 0 Exercise 18: (5.35 from book) Many solutions are possible. In all of them, a multiplexor will be needed as well as a new control signal (e.g., RegRead) to select which register is going to be read (i.e., using IR[25-11] or IR[20-16]). One simple solution is simply to add a write signal to A and break up state 1 into two states, in which A and B are read. Alternatively, you could decide to read A first because it may be needed to calculate an address. You could then postpone reading B until state 2 and avoid adding an extra cycle for the load and store instructions. An extra cycle would be needed for the branch and R-type instructions. Step 1: Instruction Fetch: IR <= Memory[PC]; PC <= PC + 4; 21 Computer Architecture Discussion Step 2: Instruction Decode and Register Fetch: A <= Reg[IR[25:21]]; ALUOut <= PC + (sign-extend(IR[15:0]) << 2); Step 3: (instruction dependent): • Memory Reference: ALUOut <= A + sign-extend(IR[15:0]); • R-type and Branch: B <= Reg[IR[20:16]]; Step 4: (Branch or R-type or memory-access): • Loads and stores access memory MDR <= Memory[ALUOut]; or Memory[ALUOut] <= B; • R-type instructions ALUOut <= A op B; • Branch: if (A==B) PC <= ALUOut; Step 5: (Write-back step): • Load: Reg[IR[20:16]] <= MDR; • R-type instructions Reg[IR[15:11]] <= ALUOut; 22 Computer Architecture Discussion 23 Computer Architecture Discussion Exercise 19: (5.50 from book) The exception cause can be represented through the status "cause" register, which records the reason code for the exception. The instruction position at which the exception occurs is identified by saving it in the Exception Program Counter (EPC) register. Execution can be restarted for some exceptions like overflow, system call request, or external I/O device interrupt by restarting execution at the EPC after handling the exception. Other exceptions are not restartable and program has to terminate. Examples of this are invalid instructions (which can actually be restartable if defined as NOP by the hardware), power/hardware failure, and divide by zero. In such a case, an error message can be produced, and program termination takes place. Exercise 20: (5.51 from book) a. Divide by zero exception can be detected in the ALU in cycle 3, before executing the divide instruction. b. Overflow can be hardware detected after the completion of the ALU operation. This is done in cycle 4. 24 Computer Architecture Discussion c. Invalid opcode can be detected by the end of cycle 2. d. This is an asynchronous exception event that can occur at any cycle. We can design this machine to test for this condition either at a specific cycle (and then the exception can take place only in a specific stage), or check in every cycle (and then this exception can occur at any processor stage). e. Check for instruction memory address can be done at the time we update the PC. This can be done in cycle 1. f. Check for data memory address can be done after address calculation at the end of cycle 3. Best Wishes