Computer Science 161

Professor Valente

 

An Example of early BASIC 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 BASIC program to solve this problem:

                       

            10        SUM = 0

            20        INPUT X

            30        IF X = 0 THEN 60

            40        SUM = SUM + X

            50        GOTO 20

            60        PRINT “SUM = ”, SUM

            70        END