Quick List |
|
Function | Instructions |
Data Movement | WRITE WRITE-FROM-IND WRITE-TO-IND PUSH POP |
Decisions, Jumps and Stop | STOP JUMP JUMP-IF-EOF JUMP-IF-EQ JUMP-IF-NE JUMP-IF-GT JUMP-IF-GE JUMP-IF-LE JUMP-IF-LT GOSUB RETURN |
Arithmetic | INC DEC ADD SUB MUL DIV MOD |
Input / Output |
SAY READ-PROP NEXT REWIND |
Bit Operations and Output | AND OR XOR COMP RSHIFT LSHIFT SAYBIN SAYHEX |
(top)
Instruction Name | Meaning | Format | Example | Meaning of Example |
WRITE | Write value onto card: Write a literal value (number or string) onto a card or from one card (source) to an other (destination) |
WRITE number, C# or WRITE "string", C# or WRITE C#(source), C#(destination) |
WRITE 5,C1 WRITE "Fred is cool",C2 WRITE C1,C3 |
Writes the number 5 onto Card 1, and the string "Fred is cool" onto Card 2. Then copy the value on Card 1 (5) onto Card 3. |
WRITE-FROM-IND | Write from indexed:
Add the values of the first and second arguments, and use that sum as the card number to copy from. Take the value in that card and copy it to the destination card (third argument) The first argument is called the "base" and the second is called the "index". Usually, the base is kept constant, while the index is incremented or decremented in subsequent instructions in the program. |
WRITE-FROM-IND C#(base),
C#(index), C#(destination)
or WRITE-FROM-IND number, C#(index), C#(destination) |
# add up C10, C11, # C12, etc. WRITE 0,C1 WRITE 0,C2 WRITE-FROM-IND 10,C1,C5 |
The instruction WRITE-FROM-IND 10,C1,C5
will add the contents of C1 to 10, giving 11 (if C1=1), then contents of
C11 is copied to C5. Then C5 is added to C2 in the next instruction, and then we increment C1 to go on to the next card. We are using C1 as an index into an array of values starting at C10. |
WRITE-TO-IND | Write to indexed:
Add up the values of the second and third arguments, and use that as the destination card number to copy the value of the first argument into. The second argument is called the "base" and the third is called the "index". Usually the base is kept constant, while the index is incremented or decremented in subsequent instructions in the program. |
WRITE-TO-IND C#(source),
C#(base), C#(index)
or WRITE-TO-IND C#(source), number, C#(index) |
# copy the first field # in a few input lines # into an array, starting # at C10 (then C11, # C12, etc.) WRITE 10, C1 |
This will write the first
field of the first input line into C10 via C5. Then we move on the
the next input line (NEXT). Then increment C2 (becomes 1), and then
do it again, which will copy the the first field in the new input line
into C11. Then into C12, etc. Notice that the group of 4 instructions (NEXT, READ-PROP, INC, and WRITE-TO-IND) doesn't change at all, but the first input field values are being written into sequential cards (C10, C11, C12, etc.). This is a mechanism of creating an array. |
PUSH | Push onto stack: Pushes a card value onto the stack. |
PUSH C# | WRITE 5,C1 PUSH C1 POP C2 |
Pushes the value of Card 1 (5) onto the stack, and then pops it into Card 2, which now contains 5 |
POP | Pop off stack: Pops a value off the stack onto a Card. |
POP C# | WRITE "Fred", C2 PUSH C2 POP C8 |
Pushes "Fred" onto the stack (from C2) and pops it onto C8 |
(top)
Instruction Name | Meaning | Format | Example | Meaning of Example |
STOP | Stop: Stops the processor -- end of program |
STOP | next-person: NEXT JUMP_IF_EOF Finish JUMP next-person Finish: |
NEXT instruction
moves to the next record in the input file. If we were at the end of
the file, then JUMP_IF_EOF will cause the processor to jump to the label
"Finish", and after that the STOP instruction will cause the
program to end.
Otherwise the next instruction (JUMP) will be executed and the next person processed. |
JUMP | Go To: Jump directly to the instruction after the named label |
JUMP label | WRITE 0,C2
Next-person: Finish: |
This example adds
up the ages of all of the people in the input file, and stored it in Card
2. This assumes the input file is organized as name,age, as in: "Peter",78 "Mary",12 |
JUMP-IF-EOF | Jump If
End-Of-File: Jumps to a label if there's no more data in the input file, otherwise goes on to the next instruction. |
JUMP-IF-EOF label | (see example for JUMP or STOP) | (see example for JUMP or STOP) |
JUMP-IF-EQ JUMP-IF-NE JUMP-IF-GT JUMP-IF-GE JUMP-IF-LE JUMP-IF-LT |
Jump if Equal Jump if Not Equal Jump if Greater Than Jump if Greater Than or Equal To Jump if Less Than or Equal To Jump If Less Than Jump to a label if the condition is met. Otherwise, if the condition is not met, then go on to the next instruction. For instance, |
JUMP-IF-EQ label,C#,C# JUMP-IF-EQ label,C#,value JUMP-IF-NE label,C#,C# JUMP-IF-NE label,C#,value JUMP-IF-GT label,C#,C# JUMP-IF-GT label,C#,value JUMP-IF-GE label,C#,C# JUMP-IF-GE label,C#,value JUMP-IF-LE label,C#,C# JUMP-IF-LE label,C#,value JUMP-IF-LT label,C#,C# JUMP-IF-LT label,C#,value
|
; Example 1 is-5: ; Example 2 diff:
|
Exampe 1: In this example, 5 is written to C1. Then C1 is tested to see if it's equal to 5. If it is, then we jump to the label "is-5" and go on from there. Otherwise we go on. In this case, since C1 = 5, we will jump and print out "C1 is 5" Example 2: |
GOSUB | Go to subroutine: Jumps immediately to the given label and stores the address of the next instruction on the program stack for the RETURN instruction. |
GOSUB label | next-person: NEXT READ-PROP 2,C1 JUMP-IF-LT next-person,C1,75 GOSUB report-on-elders JUMP next-person report-on-elders: |
This example will
print out the names and ages of people who are 50 years old or older.
Assume that the input file has lines of names and ages, e.g.: "Peter",78 The RETURN instruction will cause the program to go back to the instruction right after the GOSUB (which is the JUMP) |
RETURN | Return after
subroutine: Jumps immediately to the instruction after the most recently executed GOSUB. |
RETURN | (see GOSUB example) | (see GOSUB example) |
(top)
Instruction Name | Meaning | Format | Example | Meaning of Example |
INC | Increment: Add one to the given card |
INC C# | WRITE 0,C1 REWIND next-person: NEXT JUMP-IF-EOF no-more INC C1 JUMP next-person no-more: |
This example will count the number of records in the input file and then print it out and stop. |
DEC | Decrement: Subtract one from the given card |
DEC C# | WRITE 3,C1
say-again: Finish: |
This will output:
Fred is smart. |
ADD | Add: Add the value of the 1st argument to the 2nd argument, and store into the 3rd argument. |
ADD C#,C#,C# or ADD C#,value,C# or ADD value,C#,C# |
WRITE 5,C5 ADD 5,C5,C6 WRITE C6,C7 ADD C7,C7,C7 |
C5 = 5 C6 = 10 C7 = 20 |
SUB | Subtract: Subtract the 2nd argument from the 1st argument and store into the 3rd. |
SUB C#,C#,C# or SUB C#,value,C# or SUB value,C#,C# |
WRITE 5,C5 SUB C5,3,C4 WRITE C4,C3 SUB C3,C3,C3 |
C5 = 5 C4 = 2 C3 = 0 |
MUL | Multiply: Multiply the values of the 1st and 2nd arguments and place into the 3rd. |
MUL C#,C#,C# or MUL C#,value,C# or MUL value,C#,C# |
WRITE 5,C5 MUL C5,3,C4 MUL C5,C5,C8 |
C5 = 5 C4 = 15 C8 = 25 |
DIV | Divide: Divide the value of 1st arg by the 2nd and store in the 3rd. Integer division is performed with no remainder. |
DIV C#,C#,C# or DIV C#,value,C# or DIV value,C#,C# |
WRITE 5,C5 DIV C5,3,C6 DIV C5,C5,C7 |
C5 = 5 C6 = 1 C7 = 1 |
MOD | Mod (remainder): Divide the value of the 1st argument by the second, and store the remainder into the 3rd |
MOD C#,C#,C# or MOD C#,value,C# or MOD value,C#,C# |
WRITE 5,C5 MOD C5,3,C6 MOD C5,C5,C7 |
C5 = 5 C6 = 2 C7 = 0 |
(top)
Instruction Name | Meaning | Format | Example | Meaning of Example |
SAY | Print to output: Print the instruction's argument. Use "\n" for indicate the end of a printed line. |
SAY value or SAY C# |
SAY "His name is " SAY C1 SAY "\n" SAY "Her name is " SAY C2 |
If Card 1 contains
"Popeye" and Card 2 contains "Olive Oil" then the
output will be:
His name is Popeye |
READ-PROP | Read Property from Input
Record:
|
READ-PROP value,C# | READ-PROP 1,C1 READ-PROP 2,C2 NEXT |
Reads the first property
(first field) into Card 1, and the second property (second field) into
Card 2. Then goes on to the next record.
Files with properties look like CSV files, where each line is a record, and the properties (fields) are separated by commas. For instance, the following 2 lines represent the datafile read by READ-PROP: "Peter",12,"Brooks" |
NEXT | Go on to the next record in the input file (the next input line). | NEXT | READ-PROP 1,C1 NEXT READ-PROP 2,C2 |
Assuming that the input file
contains 2 fields (say, name and age) as in:
"Peter",78 This reads the first property ("Peter") into Card 1, and then skips to the next input line and reads the second property (12) into Card 2. To check if there are any more lines (or records) in the input file, see JUMP-IF-EOF |
REWIND | Rewind input: Go to the beginning of the input file. |
REWIND | REWIND NEXT READ-PROP 1,C2 REWIND READ-PROP 1,C1 |
A peculiar way to get the first field in the second record onto Card 1 and the first field in the first record onto Card 2. |
(top)
This work is licensed under a Creative Commons License.