
Good morning class and happy Valentines Day. Thank you for all the cards and candy.
One thing I’m wondering is who left the heart shaped anchovy pizza on my desk? I might have known – the gentleman in the rear has a smile on his face.
Today’s lesson involves finding out how large a program is that is entered into the Timex Computer. Does anyone know how this can be accomplished?
The man in the rear says that we can add up the sum total of all the characters in the program and this will correspond with the amount of bytes or memory spaces used by the program.
Although he is on the right track, this method will not give us the correct answer, the reason being that some commands require more or less bytes than the amount of characters in the spelling of that command. Also, the computer automatically injects its own code that does not appear in the listing.
Some of us have seen routines that PEEK two adjacent memory location addresses and multiply one of them by 256 and add that figure to the other. Many people are confused by this procedure and cannot comprehend how the counting of memory locations used by the program is done in that manner.
There should be a method of just counting the memory locations from where the program starts to where it ends.
Have no fear, there is a 9-line program technique that can be added to any program that has space for 9 more lines, and it will figure exactly how many memory locations or BYTES a program occupies in memory.
First of all, let me state that the first command or statement in the first line of a program has its character code residing in memory location 16513. The rest of the program takes up the memory locations immediately following each other.
All we have to do is to write a routine that will count the memory locations, starting with 16513 until it reaches the end of the program, and subtract the amount of memory locations used by that routine.
In an earlier lesson we discussed the unique properties of a program line such as:
9990 REM COPY COPY
If you try to ENTER these three commands as listed, you will notice that when the first <COPY> command is attempted to be entered, the letter <Z> appears. We have to be sneaky here to be able to enter this format.
First enter <9990> and then <COPY>. Now back-space one position by using the back-arrow key (shift <5>). Now enter <COPY> again. Back-space one more position and enter <REM>. Now press the ENTER key and the line will be intact. Neat, Huh?
This line acts as a stop-gap to end the counting procedure as the last program memory location is encountered. Again, as explained in the Syntactic Sum tutorial article, the computer is instructed to ignore anything that appears in a line that starts with a <REM> statement. The two <COPY> commands that follow provide a unique situation that is impossible to achieve in a normal programming situation.
The Sinclair character code number for the command COPY, as listed in Appendix A of the TS-1000 manual, is 255. This means that if a program line has two COPYs right next to each other, the sum total of the two character code amounts is 510. Since it is impossible to have the computer accept these two commands right next to each other for any situation except after the REM statement and since the number is the largest possible number that can be achieved by adding any two character codes together, we are safe in assuming that this format will accomplish our task.
The rest of the program routine is simple. The entire routine is as follows:
9990 REM COPY COPY
9991 LET N = 16513
9992 LET A = 0
9993 IF PEEK N + PEEK (N+1) = 510 THEN GOTO 9997
9994 LET A = A+1
9995 LET N = N+1
9996 GOTO 9993
9997 PRINT AT 10,0;"TOTAL BYTES IN PROGRAM = ";A-1
9998 PRINT ,,"TOTAL SIZE OF PROGRAM IS ";100*INT (((A-1)/1024)+.05)/100;"-K"
Line 9991 sets the variable <N> to be the first memory location where the program starts. Line 9992 sets the variable <A> to be 0. Variable <N> is going to increment itself by one for each memory location that is being counted. Variable <A> is also going to increment itself by one each time <N> does.
Variable <A> is actually counting the memory locations or bytes in the program where variable <N> is the address of these memory locations.
A continuous loop occurs between lines 9993 to 9996 which line 9993 directs a breakout to occur to line 9997 when the contents of the current memory location being observed, and the one adjacent to it, have the total sum of their character codes equal 510.
Line 9997 then takes the total bytes counted, which is the variable <A> at this point and subtracts 1 from that total. The reason it does this is because if you observe line 9990, you will see that the first thing that appears in that line is the REM statement, and this occupies 1 memory location. Since this REM begins the counting routine and is not part of the program itself, we don’t want it to be part of the final total.
Execute this routine by itself by typing in GOTO 9990. You will notice that <0> will be the result for the two displayed totals. Add a line like: 10 REM or 10 PRINT
You will notice that these short programs occupy the same amount of space even though they have a different amount of characters in each line. Try back-spacing a REM before the PRINT in the line and ENTER GOTO 9990.
Why does the total not take up as much space as when they are entered as separate program lines? PRINT following a REM statement no longer has the characteristics as if it appeared alone. It now occupies only 1 memory location.
Type this routine in at the end of one of your existing programs but before executing it, put the computer in the FAST mode. The routine will count the memory locations at a rate of 1585 BYTEs per minute in the FAST mode.
The program PAYROLL is 5995 BYTEs in size and takes 3 minutes and 47 seconds for the count.
Oh, there’s the bell – I think I’ll try this pizza now.
HEY, THESE AREN’T ANCHOVIES – THEY’RE JELLY BEANS! WHERE IS THAT GUY?
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.