program mystery; begin var x, y, sum : integer; readln (x); readln (y); sum := 0; while (x > 0) do begin if x mod 2 <> 0 then begin writeln (y); sum := sum + y; end; x := x div 2; y := y * 2 end; writeln (sum); end.
Note that the SAL put instruction does not produce a newline, so if you want to mimic the effect of a writeln statement, you'll need to print the newline yourself somehow.
Once you've written this SAL program, save it in a text file and try it using spim (or xspim). Does it produce the results you expected? What useful task does it perform?
and a paragraph is a sequence of characters and newlines, ending in a blank line (i.e. two newline characters in a row). Use procedures where appropriate, e.g. to decide whether or not a given character is punctuation (see problem 2.13 for ideas on how to do this). You may want to write the program first in a high-level language, then translate it into SAL. Try to design your program so that if the requirements were to change slightly, you could modify your program quickly and easily to meet them.