# Homework 1

### Due 1 Oct, 1998

• Textbook problem 1.8. There are several correct answers, depending on your assumptions, so you must tell me what you're assuming, and justify your answer.
• Textbook problem 1.11. This is a discussion question; I'm looking for intelligent reasoning, not a yes/no answer.
• Textbook problem 1.14. Each of the choices in the book has its merits; I want you to discuss advantages and disadvantages of each measure, and explain why one (or two) of them is better than the rest.
• Translate the following Pascal program to SAL:
• ```  program mystery;
begin
var x, y, sum : integer;
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?

• Textbook problem 2.12.
• Textbook problem 2.15. For our purposes, a "punctuation mark" is any of the characters
• period .
• comma ,
• exclamation point !
• question mark ?

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.