Thursday, August 29, 2013

Program Code – Internal Format

The internal program code of a BASIC program will consist of 16-bit instruction words.  Each instruction word will consist of two parts, the instruction code (command, operator, internal function, etc.) to perform, and the sub-code information that will only used to recreate the original program text (with the Parentheses, Colon and Let sub-codes).  The sub-code information will not be used by the run-time module, but there will be a few exceptions (the Question and Keep on the various INPUT statement codes).

Some instruction words will have a second 16-bit operand word, which could contain one of three types of information depending on the instruction code.  For instructions that are variables, arrays, constants, remarks, define functions, user functions, etc., this second word will be an index into one of the dictionaries.  For single line structure statements (an IF statement for example), the second word will contain an offset to where to jump to.  For example, in an IF statement followed by a set of commands to execute upon a true expression, the offset will tell the IF command how many words to skip when the expression is false.

The final type of information in the operand word is a block number, which will be used on multiple line structure statements.  For example, an IF/END IF structure over several lines, both the IF and END IF commands will have the same block number.  Structured block will probably also have a dictionary, so technically this operand type is also an index.  The dictionary entry for a block will contain the locations of the IF and END IF statements.  When running, if the IF expression is false, it will go to the dictionary for the block number to find out where the associated END IF is located and jump the instruction after it.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)