I went over DeMorgan's Laws, and the compilation of condition branches or loop control boolean expressions.
I also went over the compilation of
for (i = 0; i < N; i++) { sq[i] = i*i; }into MIPS assembly, and looked at the exact run-time of this code as an expression involving the inputs. Assume that i is in register $t0, N is in $a0, and the base address of the array sq is in $a1.
instructions cycles li $t0, 0 1 b test 1 bod: mul $t0,$t0 ~7 mflo $t1 1 sll $t2,$t0,2 1 add $t2,$t2,$a1 1 sw $t1,0($t2) 1 (if write buffer) + ?? test: blt $t0,$a0,bod 1 (ignoring pipeline issues for now)The runtime is 3 + (12 + ??) N . The runtimes for mul and sw depends on the particular implementation of the architecture. Some chips have faster multiply units than others (more expensive / chip real estate used); some chips have a better write queue for the sw (it could even be a single cycle).
We started next on
for (isq = i = 0; i < N; i++) { sq[i] = isq; isq = isq + 2 * i + 1; }See if you can translate this to MIPS efficiently. What is the runtime of this new code?
For your amusement:
[ieng9]~ 397 $ cat foo.java class foo { public static void main(String argv[]) { System.out.println("Hello world"); } } [ieng9]~ 398 $ /usr/local/java/jdk_1.1.3/bin/javac foo.java [ieng9]~ 399 $ /usr/local/java/jdk_1.1.3/bin/java foo Hello world [ieng9]~ 400 $ od -x foo.class | head -1 0000000 cafe babe 0003 002d 0020 0800 1307 0018 [ieng9]~ 401 $
bsy+www@cs.ucsd.edu, last updated