Transcript 4 - SAL 3
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
move G, F
#instr 1
#instr 2
fetch
update PC
decode
load operand
execute
store
instr 1
_____
_____
_____
_____
_____
_____
instr 2
_____
_____
_____
_____
_____
_____
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
move
while: blez
mul
sub
b
endwhile:
result, 1
counter, exponent
counter, endwhile
result, result, base
counter, counter, 1
while
#code A
move
move
blez
loop: mul
sub
bgtz
endwhile:
result, 1
counter, exponent
counter, endwhile
result, result, base
counter, counter, 1
counter, loop
#code B
Write a SAL code for the following C code fragment.
for (i=2;i<=z;i++){
if (0 == i%2){
sum = sum + i;
}
}