210 likes | 348 Vues
This document outlines the review agenda for CS3410 Homework 1. It covers essential topics such as Karnaugh Map minimization techniques, binary number translation, and finite state machines (FSM) including spam filters. Performance analysis involving instruction cycles and CPI calculation is also discussed. Additionally, there are details on writing assembler code, basic patterns for arithmetic and control structures, and best practices for programming and debugging. Ensure proper preparation for upcoming assessments.
E N D
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 • Sum of products: • Karnaugh map minimization: • Cover all 1’s • Group adjacent blocks of 2n 1’s that yield a regular shape • Encode common features ab c 00 01 11 10 0 0 0 0 1 1 1 1 0 1
Rules for Karnaugh Map Minimization • Minterms can overlap • Minterms can span 1, 2, 4, 8 … cells • The map can wrap around ab ab c c 00 01 11 10 10 00 01 11 0 0 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0
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 (cont.) Spam filter x 2 0 1 2 0 1 0 1 ….. x2 x0 x1 Output Okay
Question 4: FSM (cont.) Spam filter x 2 0 1 2 0 1 0 1 ….. x2 x0 x1 Output Okay SPAM
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.
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 = cycle time * num of instructions • Speedup < 1 means we are actually slowing down Execution time (old) Execution time (new)
Question 8 (cont.) • 4.3.3: • Cost-performance ratio (CPR) = • The higher, the better • This question asks for a “comparison” of CPR CPR ratio= = * Performance Cost CPR (old) Cost (new) Perf (old) CPR (new) Cost (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/2014sp/MIPS_Vol2.pdf • Core instruction set • http://www.cs.cornell.edu/courses/CS3410/2014sp/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: • Assembler: a = b + c; #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: $s0, b: $s1 SLT $t0, $s0, $s1 BEQ $t0, $zero, POINTB #DO A... POINTB: #DO B...
Basic Assembler Coding Patterns • While loop • C code: • Assembler: while(a < b) //Do something... #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: • Assembler: intmyArray[10]; a = myArray[2]; #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: • You need a buffer for it int scanf ( const char * format, ... );