Computer Science 161
Professor Valente
An Example of
early FORTRAN progamming
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
An Early FORTRAN program to solve this problem:
INTEGER SUM
INTEGER X
SUM = 0
10 READ (1, 5) X
5 FORMAT (I2)
IF (X .EQ. 0) GO TO 30
SUM = SUM + X
GO TO 10
30 WRITE (2, 25) SUM
25 FORMAT (I3)
END