Example Program

Top  Previous  Next

This program shows some relationships between the various types of integer factors.

 

        code ChOut=8, CrLf=9, IntOut=11, Text=12;

        integer Counter;

        define Tab=$09;

 

        begin

        Counter:= $41;

        repeat  ChOut(0, Counter);

                ChOut(0, Tab);

                IntOut(0, Counter);

                CrLf(0);

                Counter:= Counter + 1

        until Counter = ^G;

        Text(0, "That's all folks!");   CrLf(0)

        end

 

When run, this program displays:

 

        A       65

        B       66

        C       67

        D       68

        E       69

        F       70

        That's all folks!

 

The program begins by declaring the things that are needed to run it. The first line tells which intrinsic subroutines are needed and gives each a name. The second line declares a single variable called "Counter" that will hold integer values. The last declaration tells us that the word "Tab" can be used as a direct replacement for the hex number $09. This replacement is convenient because the ASCII value of the tab character is equal to $09. These three lines of declarations can be in any order. It is conventional that "code" declarations are first.

 

The rest of the program describes the actions it performs when it runs. Since this executable part of the program is a block, consisting of several statements, it is enclosed within a begin-end pair.

 

The first statement in our program block puts the value $41 in the variable called Counter. $41 is the value of the ASCII character A.

 

Now we are going to repeatedly execute a sub-block until Counter contains a value equal to the ASCII character G.

 

We begin the sub-block by calling the intrinsic subroutine ChOut, which we send 0 and the value in Counter (initially $41). ChOut (CHaracter OUT) sends a value to a specified output device. Here we are specifying device number 0, which is the monitor. When the monitor driver receives a value, it displays the ASCII character that corresponds to the value. So the first time we call ChOut, an "A" is displayed.

 

The next line calls ChOut again and sends the ASCII value for a tab character. This moves over to the next tab stop on the monitor.

 

Now we call IntOut. IntOut (INTeger OUT) is similar to ChOut, but rather than the value being displayed as a character, it is displayed as a decimal integer. The first time we call IntOut, "65" (= $41) is displayed.

 

The next statement, CrLf(0) (Carriage Return Line Feed), is an intrinsic that moves to the beginning of a new line on the monitor.

 

Now, 1 is added to the value in Counter, and the result is stored back into Counter. On the next line we test the value in Counter to see if it is equal to ASCII G. If it is not then we go back to the beginning of the repeat block and repeat the statements starting with ChOut. If Counter has incremented up to G then we fall through to the next line, which is the Text statement.

 

Text is an intrinsic similar to ChOut, but it sends out a whole string of characters rather than just one.

 

Note the overall logic of the program. We started at A and counted up to G. For each count we displayed the character and its decimal value. When we got to G, we broke the repeat loop and displayed the message "That's all folks!"