Understanding IA's Input and Output

Last Up date on: 2003 November 14

All values in IA are kept as unsigned variable length binary integers. The size of any value and the number of values is limited only by the amount of available memory. IA has two first in last out stacks: the main stack and the alternate stack. All arithmetic operations are done on the main stack. Values can be copied or moved to and from the alternate stack. The alternate stack is used simply as a place to hold one or more values.

IA uses three 64K segments or 196,608 bytes of memory. The first segment holds the program itself and the main stack which follows the program. The memory available for the main stack is about 58 thousand bytes. The hardware stack and the alternate stack are at opposite ends of the second segment. The third segment is used only to hold the ASCII output string. When a value is converted to decimal for output the decimal string is put into this third segment. Thus, the largest value that can be output is limited to 65,530 digits. (Leading zero suppression has not been done when the string is generated, and 2 bytes are used for a CR-LF.) When # is used to insert separators (usually a , between each three digits) the string from the output segment is moved to the hardware/alternate stack segment as the separators are inserted; so the number of digits that can be output using # is less, but still typically over 35 thousand digits.

The only time IA changes segment registers is when data is being transferred to or from the alternate stack, or for output. Otherwise CS, DS, and ES all have the same value. This accounts, in part, for the speed of IA.

The main stack is displayed and cleared at the end of every input line. (There is a facility to continue an input line, effective allowing an input line to be any length.) The alternate stack is clear when the program is started and is only cleared by an explicit command. Both stacks have an initial value of zero when cleared, but this is rarely ever seen by the user.

With this much understanding of the stack architecture we can now look at how IA processes the user input.

IA gets one line at a time from DOS, which goes into a 128 byte input buffer. This provides the same facility for correcting input that is used for DOS commands, and is described in any DOS manual. This simple edit and re-submit facility is very useful in IA and is normally done with the following keys: Insert, Delete, Back space, Escape, the right & left arrows, and function keys 2 through 5.

IA's input routine checks to see if the line is empty (just an Enter) and if it is IA terminates. The normal way to exit IA is to just press Enter, although Ctrl-Break is always functional. It is important to note that if the input to IA is redirected from a file, a blank line in that file should be used to terminate IA.

There are two, almost identical, routines that get the data character by character from the input buffer. They both ignore spaces, and they both treat graphic characters that are not digits or letters as commands. The major difference between these two routines is that one treats the input as decimal while the other treats the input as hex. These routines are labeled GDEC and GHEX for Get DECimal and Get HEX. There is a strong bias for GDEC as will be explained shortly.

When GDEC picks up a character, if it is a space it throws it away and gets the next character; if it is a digit (0 through 9) it multiplies the value on top of the stack by ten and adds the value of the digit. It then repeats for the next character. When GDEC picks up a character that is not a digit it jumps to the appropriate routine to carry out that command. All the "service routines" except for "." (called dot or period) and sometimes "_" (Underscore, to be explained latter) return to GDEC. Thus, the strong bias for decimal input. When GDEC has processed all the data in the input buffer, it gets a Carriage Return, and displays the entire stack in Hexadecimal.

The service routine for , (comma) starts a new value, initially zero, on the main stack; thus, values are separated with comma's. The service routine for . is a new command interpreter, generally . is used to modify what follows. When the character following a . is a space the stack is displayed in decimal and the rest of the line is ignored. When the character following a . is a digit or letter the service routine is GHEX.

When GHEX picks up a character if it is a digit or a letter (Upper and Lower case are treated the same) it multiplies the value on the top of the stack by the value of the input base (default 16) and adds on the value of the digit or letter, and returns to itself. (The letters have values starting with ten for A and going up through 35 for Z.) Like GDEC, when GHEX picks up any other character it jumps to the service routing. When GHEX encounters the Carriage Return it displays the entire stack in "decimal". ("Decimal" is usually base ten but can be changed to any value 2 through 15.)

This is why you input a "hex" value by starting it with a dot. And why you generally end the input line with a dot to see the stack displayed in "decimal". This makes it very simple to use IA to convert from decimal to hex, or hex to decimal.

You cannot change the base used for decimal input or hexadecimal output. (So, you can't get trapped in a base you don't want.) But, the base for "Decimal" output can be changed to any value from 2 through 15. And, it is possible, and useful, to change the number base used in GHEX for "dot input". (I suggest you wait to do this until you have experimented a bit.) The base for "Dot" input can be any value from 2 through 255, thus you can see why the letters through Z are allowed as "digits", just as we are accustomed to doing for base 16. But Z has a digit value of 35, so there needs to be a simple way to enter "digits" whose value is greater than Z. Thus, we introduce "Decimal Coded Digits" or DCD's.

Much like was done for . the _ allows for different interpretations of the following character. When _ is followed by a space it is treated exactly like a . followed by a space, when _ is followed by a CR the entire stack is discarded without being displayed, and control goes to GDEC.

More interesting: when _ is followed by a digit, any decimal value up to 255 is treated as a single digit. Any non-digit terminates the decimal coded digit and control goes to GHEX to multiply the top value of the stack by the "dot input base" and add on the value of the "digit".

Yes, decimal coded digits or DCD's may be a new concept. Examples should help. Suppose the dot input base is 16, the default, and we want to enter the value 255. We can do it in any of the following ways:

        255     .Ordinary decimal
        .ff     .Simple hex
        .FF     .Case does not matter
        _15_15  .Two digits whose value is 15
        _15 _15 .Spaces are ignored between DCD digits
        _15f    .Any alpha character is the next digit
        _15 f   .Space after or before DCD doesn't hurt
        .f_15   .Decimal Coded digits may be used within a "Dot number"
        .F f    .Spaces OK in . values but not right after the dot
        .F.f    .So are single dots
        .e_31.  .A DCD digit can be larger than the base.
        .ev     All 26 letters can be used as dot input digits.
        .e  v   Spaces are ignored. But you knew that!
Thess last three might suprise you. Traditionally, we don't use digits greater than the base of the number system. But IA can handle it. And, with dot input; and it turns out to be surprisingly useful. Of course, within dot input IA allows: leading zeros, imbedded spaces (not within DCD's), and single imbedded dots.

Note: There may be spaces proceeding each _ but there must not be any spaces between the _ and the decimal digits that follow. For example:

        _1 5 f is equivalent to: .15f not _15f or .ff
	_1 5 0 is equivalent to: .150 not _150 or .f0

A couple final examples using input base 60. To enter an angular value of: 42 degrees, 23 minutes, and 30 seconds:
  60.:          ;To set dot input base to 60
  42_23_30      .will do the job.
(IA will convert this base 60 value to binary and put a value on the stack equivalent to the "seconds" of this number.) To enter the angle that is just 1 second less than a complete circle you could use: 359_59_59. And to enter the angle that is 1 degree less than a full circle you could use: 359.00 Don't ever think this could be: Three hundred, fifty nine dollars in IA.

To get used to this one should do some experimenting. And rember, IA will reset the "dot" input base to 16 if: you specify a value less than 2, so a simple .: at the beginning of a line will get you back to the default. as will 1.: or 16.: And of course a blank line followed by F3 and another return should exit IA and restart with the defaults.

Last but not least: A single "?" (question mark) on an input line gives a list of the special symbol functions available in IA. Hopefully the short description and a little experimenting will get you going.

There will be a separate write up on using: Looping, and the User definable function "`" (reverse tic).


If you have suggestions, comments or ideas e-mail me. I would like to hear from you.
My Home Page or Jump to TOP of this page.