E N D
SAL – Part 3 Operations Q & A
Assume that at instruction fetch, operand load, or storage of a result takes 10 time units to complete. Instruction decode, operation execution, and program counter update each take 1 time unit to complete. How long does it take to execute the following code sequence? add D, E, F #instr 1 move G, F #instr 2
instr 1 instr 2 fetch _____ _____ update PC _____ _____ decode _____ _____ load operand _____ _____ execute _____ _____ store _____ _____
Does a compiler need to be written in assembly language? If so, why? If not, how is a machine language version of the compiler generated. A compiler need not be written in assembly language. The compiler can be written in a high-level language and then use it to compile itself to its assembly language representation. An assembler can then be used to translate it into machine language.
Explain how to implement a boolean type variable in SAL. What is the variable’s type, and how is it used? We can use integer type variables. The value 0 can represent false and the value 1 can represent true.
For the following SAL codes give a value for which code B would execute fewer instructions than code A.
move result, 1 #code A move counter, exponent while: blez counter, endwhile mul result, result, base sub counter, counter, 1 b while endwhile: move result, 1 #code B move counter, exponent blez counter, endwhile loop: mul result, result, base sub counter, counter, 1 bgtz counter, loop endwhile:
Write a SAL code for the following C code fragment. for (i=2;i<=z;i++){ if (0 == i%2){ sum = sum + i; } }