CS3410 HW1 Review 2014, 2, 21 Agenda • We will go through the HW1 questions together • TAs will then walk around to help Question 1: Karnaugh Map c a b c out 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 ab • Sum of products: out abc abc abc abc • Karnaugh map minimization: 00 01 11 10 0 00 00 0 0 11 1 11 11 0 0 11 • Cover all 1’s • Group adjacent blocks of 2n 1’s that yield a regular shape • Encode common features out ab ac Rules for Karnaugh Map Minimization • Minterms can overlap • Minterms can span 1, 2, 4, 8 … cells • The map can wrap around c ab 00 01 11 10 0 01 00 0 0 11 1 10 10 0 0 10 c ab 10 00 01 11 0 01 01 0 0 10 1 10 10 0 0 10 Question 2: Numbers & Arithmetic • Binary translation: – Base conversion via repetitive division • From binary to Hex and Oct • Negating a number (2’s complement) • Overflow – Overflow happened iff carry into msb != carry out of msb Question 4: FSM Question 4: FSM (cont.) Spam filter 1 0 1 x1 x0 x x2 Output Okay 2 0 1 2 0 ….. Question 4: FSM (cont.) Spam filter 1 0 1 2 x1 x0 x x2 Output Okay SPAM 0 1 2 0 ….. Question 4: FSM (cont.) State (x1=0, x2=0) and (x1=0, x2=1) have exactly the same transitions AND output. So they are NOT distinct states. Current state Input Next state Output x1 x2 x0 x1’=x0 x2’=x1 0 0 0 0 0 okay 0 0 1 1 0 okay 0 0 2 2 0 okay 0 1 0 0 0 okay 0 1 1 1 0 okay 0 1 2 2 0 okay 0 2 0 0 0 spam … … … … … … Question 7: Performance • Instruction mix for some program P, assume: – 25% load/store ( 3 cycles / instruction) – 60% arithmetic ( 2 cycles / instruction) – 15% branches ( 1 cycle / instruction) • CPI: – 3 * .25 + 2 * .60 + 1 * .15 = 2.1 • CPU Time = # Instructions x CPI x Clock Cycle Time – Assuming 400k instructions, 30 MHz : • 400k * 2.1 / 30 = 28000 µs (1 µs = 1 microsecond = 1/1M S) Question 8 Registers and Control are in parallel Question 8 (cont.) • Refer to section 1.6 in the text book • 4.3.1: The clock cycle time is determined by the critical path (the load instruction) • 4.3.2: – Speedup = Execution time (old) Execution time (new) – Execution time = cycle time * num of instructions – Speedup < 1 means we are actually slowing down Question 8 (cont.) • 4.3.3: Performance – Cost-performance ratio (CPR) = Cost – The higher, the better – This question asks for a “comparison” of CPR CPR ratio= CPR (old) CPR (new) = Cost (new) Cost (old) * Perf (old) Perf (new) 1 speedup Question 9/10/11: Assembler Code • Writing the instructions in a human-readable format – http://www.cs.cornell.edu/courses/CS3410/2014s p/MIPS_Vol2.pdf • Core instruction set – http://www.cs.cornell.edu/courses/CS3410/2014s p/project/pa1/pa1.html Assembler Code • When writing the assembler code: – Decide which register stores which variable • Typically you should use $t0~$t9 and $s0~$s7 (You don’t need to understand their difference now) – Decide which instruction you want to use • Get familiar with the core instruction set • Get familiar with some basic patterns Basic Assembler Coding Patterns • Arithmetic – C code: a = b + c; – Assembler: #a: $s0, b: $s1, c:$s2 ADD $s0, $s1, $s2 Basic Assembler Coding Patterns • Brunch – C code: – Assembler: if(a < b) //DO A... else //DO B... #a: SLT BEQ #DO $s0, b: $s1 $t0, $s0, $s1 $t0, $zero, POINTB A... POINTB: #DO B... Basic Assembler Coding Patterns • While loop – C code: while(a < b) //Do something... – Assembler: #a: $s0, b: $s1 LOOP: SLT $t0, $s0, $s1 BEQ $t0, $zero, EXIT #Do something... J LOOP EXIT: #Out of the loop... Basic Assembler Coding Patterns • Array access – C code: int myArray[10]; a = myArray[2]; – Assembler: #a: $s0, myArray: $s1 LW $s0, 8($s1) C Programming • Have you tried the hello-world? • Use csuglab machines. It is easier. • How to read input from the terminal? – scanf: int scanf ( const char * format, ... ); – You need a buffer for it Good Luck! Questions?
© Copyright 2026 Paperzz