Authors
Publication
Pub Details
Date
Pages
BASIC Terms
Most computers use variations of the Dartmouth BASIC Language as their operating systems. The assembly language routines in ROM are designed to facilitate the Basic language as used by the operator and the Basic Editors of the computers are designed to process the particular variation of syntax used. Generally, the differences in syntax are easily learned by a user who has some experience operating any computer. So, once one learns the syntax one can begin to program the computer. This is quite an advancement over the way programming was done in the 60’s, when a computer was programmed by punching holes in a card to be fed through a card reader.
So, things are now neatly arranged. We have the BASIC language to use and the computer is programmed to accept Key Words that the operator Inputs from a keyboard and then Branch to a fixed ROM routine to execute the operator’s desires. The operating system Is FIXED in ROM. The BASIC language is just “semi-fixed” and has some flexibility. One of the flexible features has to do with mathematics expressions. The Central Processing Unit (CPU) of the computer has an Annex called “The Arithmetic Logic Unit” (ALU) whi ch processes mathematics expressions and provides a Resultant. When a math expression is included in Basic Programming, the ALU solves the expression and the CPU stores the resultant.
If, within a program line, the expression “LET a=20*40” is used, the ALU solves “20*40” to allow the varlable a to be assigned as 800. Almost all commonly used math expressions can be sent “IN BASIC” to the CPU. “LET c=2*Pi*r”” is acceptable as syntax to the basic intrepeter, and the CPU calls upon it’s ALU to solve the math before it assigns a value to var c. Then if we use other math equations most will be acceptable. How about Boolean Logic expressions? Why not? Boolean Logic is the basis for the logic of most of the IC chips in the computer (AND Gates, OR Gates, NOT Gates, etc.). The CPU itself is largely a Boolean Logic device.
What is BOOLEAN anyway? Well, most of our younger set believe that computers sprang up as a new invention during the 70’s. Actually most of the principles of computing extends back more than a hundred years. What sprang up was new manufacturing techniques of packaging electronics components. George Boole (1815-1867) gave us the logic used in computers. Mr. Boole spent a lifetime integrating two separate sciences, LOGIC and Mathematics. Then Mr. Einstein made great use of Mr. Boole’s works and added to It. Before, Logic was considered to be literal, and mathematics was limited to the factoring of numbers. Boolean logic uses such expressions as AND, OR, NOT, In both a math and relational Logic sense.
Boolean logic can greatly shorten the way we express ourselves In Basic programming. Boolean logic can also speed up the execution of Basic programming. When Boolean expressions shorten the literal expressions in Basic, the programming does not require as much memory for storage. Most College courses In Computer Programming ignore Boolean because It Is really an advanced Math discipline, and to Introduce It in a programming class would require more semester time. Yet, It does not require extensive study to use simple Boolean expressions to great advantage.
Dense Pack Basic employs Memory and time saving techniques Integrated with Basic Programming, Dense Pack Is not a new language, but Is a “method of programming”, using math as logic, and existing memory saving techniques. It Is reasonable to conclude that If a line of Basic programming can be reduced In Byte length by as much as 70%, the programming In the line will execute faster. Supporting this thesis Is the fact that arithmetic functions executed by the ALU are the fastest operations performed by the computer.
The October Issue of UP-DATE discussed “Pseudo Hex”, a table of variables that substitutes for numbers. Most programmers use the principle, but In a un-organlzed manner. The pseudo hex table was designed to assist In remembering the variables used to represent numbers 1 through 20, These are the most used numbers in computer programs. To review, Pseudo Hex uses a double character variable “o”, where “oa=1, ob=2, oc=3, to ou=20”, A person tends to quickly learn that “oe=5”. In the learning phase, one can count on fingers, using the alphabet to Intrepet the variables. The use of such a variable system quickly becomes habit to programmers.
The Pseudo Hex table Is constructed In program lines. Then GO TO the first line initializes the variables to memory, A good technique to use with disk drive systems Is to then SAVE the variables to disk where the vars table can be re-loaded to a CLEARED Basic program. When that Is done, the program lines may be deleted. The memory cost of initializing the pseudo hex variables Is usually recouped within the first 20 lines of a basic program, A basic program of 20K in length is typically reduced to about 16K in length by using the variables table.
Now we will get into the meat of Dense Pack as it employs Boolean Logic and math operators in Basic Programming. The best way to start is with an example. I’ll give a typical conventional program line after a MENU which has 9 optional electives. Normally the menu electives will be listed 1 through 9 and the operator touches a number key to make a selection. Ordinarily, a INKEY$ prompt would be used to assign the key touched to a numbered variable such as “z”, The typical program lines after would be: 100 IF z=1 THEN GO TO 500 – 102 IF z=2 THEN GO TO 600 – 104 IF z=3 THEN GO TO 700 – etc, etc, until “9 IF THEN LOGIC lines are programmed”. Then there would be a “Key Lock” line as: 118 IF z<1 OR z>9 THEN GO TO 90 (the menu).
The dense pack presentation would be only ONE line of programming Instead of 10 lines. Vars would be used for each of the small numbers. The result would be a reduction of 9 lines of programming and 75% of memory required to store the programming. The equllivant programming in Dense Pack would be: 102 GO TO (z=oa)* 500 +(z=ob)* 600 +(z=oc)* 700 +(z=od)* 800) +(z=oe)* 900 +(z=of )* 1000 + (z=og)* 1100 +(z=oh)* 1200) +(z=01)* 1300 + (zol)* 90.
The example dense pack (single) line requires only 25% of the memory needed to store the conventional 10 lines of the first example, and 9 fewer program lines. I will break down one of the IF THEN conditionals. “GO TO (z=oa)* 500”. The operator is “GO TO” and is used only once for the 10 evaluations. “IF and THEN” are implied for each of the 10 conditions that are inclosed in (brackets). The term means: IF z=1 THEN GO TO 100. When the program line is processed ALL 10 of the conditions are evaluated as a single expression, where with conventional IF THEN conditions each program line is evaluated and a false condition would be ignored. The dense pack line operates faster and conserves 75% of program memory.
Now we will explore some more Dense Pack examples. I’|| set up a program line with a pair of prompts. One will opt to solve the Circumference of a circle, and 2 will opt to solve the Area of a circle. 10 LET r=9: INPUT “<1> Circumference or <2> Area”;a: LET y= (2*Pi*r AND a=1) + (2*Pi*r 2 AND a=2). That little routine lacks a trap for wrong key hit. Conventional IF THEN statements may be mixed with Dense Pack logic expressions, as: 100 IF a<10 THEN PRINT (“yes” AND a<6) + (“no” AND a>5): IF a<3 THEN GO TO (a<1)*50 + (a=1)*100 + (a=2)*200). In that example IF a is smaller than 10 the print statement will execute and print “yes” if a is smaller than 6 or “no” if a is greater than 5. Then the last GO TO will execute only if a is smaller than 3.
Here is an actual dense pack line used in one of my programs. vars 1x=maximum printer line, qq=center of page, tb=tab, ps=print style elected, xo=existing max printer line, lo=existing line length, and I|=line length elected. A matching line “ma” is computed: 8022 LET Ix=(80 AND ps <3) + (96 AND ps=3) + (136 AND ps>3): LET qq= INT (lx/2+ 05): LET ma= INT (5+ix*lo/o): GO SUB 8088: LET +b= INT ((Ix-ll)/2+=5 – 8088 PRINT AT 10,2;”Key in line length”! TAB 2; Ix;”=Max “; ma=”Match”: INPUT ll: CLS RETURN. I left out the pseudo hex vars for easier follow through. These two lines are not intended to dazzle, but to Illustrate how many IF THEN conditionals, plus computations, GO SUBS, and LET statements can be integrated into one dense pack line. Dense pack lines are “program packages”.
As one gets into Dense Pack, the program Iines become easier because they are independnt “whole functions”. Fewer GO TOs and GO SUBS are used to pick up other sub-routines, and “fall throughs” to next program lines are greatly reduced. Sometimes one tends to get too engrossed and does a blunder like my printing a listing of the “J-vars utility package” in the October 87 issue, Looking back, it is a most difficult listing for one to key in. To give you a better feel for the usefulness of Dense Pack, one of my programs was reduced from 28K of program length to about 12K. Then more functions could be added. All of the Key Words of any computer can be used as operators for Dense Pack programming.
RULES
- A Key Word can only operate on one variable within a set of brackets. <GO TO (a=1)*100+(b=1)*200> would not work, because two evaluators are used “a and b”.
- ALL conditions should be accounted for. LET a= (10 AND b=2) + (30 AND b=4). In this example, the conditions of b<2, b=3, and b>4 are not accounted for. As a line is evaluated, and an un-accounted for condition is present, the CPU takes off hunting. Often this will result in the execution of an un-intended line near the end of the program. Use limiters such as “<” and “>” to account for all possible conditions.
- Some mixes of AND and OR within the same brackets will not be intrepeted in the BOOLEAN sense, but in the literal.
Only experimenting will proof the programming. Have fun with Dense Pack!