Computer Science 161
Professor Valente
An Example of
Pascal programming
The Algorithm:
Set the value of Sum to 0
Get a value for X
While X is not 0
Set the value of Sum to Sum + X
Get a value for X
End While
Print the value of Sum
Stop
Our VSC-32 assembly language program to solve this
problem:
LOAD Zero
STORE Sum
READ X
While: LOAD X
JUMP Print
LOAD Sum
ADD X
STORE Sum
READ X
LOAD Zero
JUMP While
Print: WRITE Sum
STOP
Zero: DATA 0
Sum: DATA 0
X: DATA 0
A Pascal program to solve this problem:
Program SumTheNumbers(Input, Output)
Var Sum, X: INTEGER;
Begin
Read X;
While X <> 0 do
Begin
Sum := Sum + X;
Read X;
End;
Write Sum;
End.