The SPOT Instruction Set

(Back to SPOT Home Page)

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)

Data Movement

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

ADD C5,C2,C2

INC C1
WRITE-FROM-IND 10,C1,C5

ADD C5,C2,C2

INC C1
WRITE-FROM-IND 10,C1,C5

ADD C5,C2,C2

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
WRITE 0, C2

READ-PROP 1,C5
WRITE-TO-IND C5,C1,C2

NEXT
READ-PROP 1,C5
INC C2
WRITE-TO-IND C5,C1,C2

NEXT
READ-PROP 1,C5
INC C2
WRITE-TO-IND C5,C1,C2

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)

Decisions, Jump and Stop

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:
STOP

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:
NEXT
JUMP-IF-EOF Finish
JUMP Add-age

Finish:
SAY "The sum is: "
SAY C2
STOP

Add-age:
READ-PROP 2, C1
ADD C1,C2,C2
JUMP Next-person

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 lb-next C1, "Fred" compares the contents of C1 to the string "Fred" (case-insensitive comparison) and jumps to the location of the label "lb-next" if they are equal.  Otherwise, there is no jump and the next l instruction is (normally) executed. 

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
WRITE 5, C1
JUMP-IF-EQ is-5, C1,5
SAY "C1 is not 5.
STOP

is-5:
SAY "C1 is 5"
STOP

; Example 2
WRITE "FRED",C1
WRITE "fred",C2
JUMP-IF-NE diff,C1,C2
SAY "They're equal."
STOP

diff:
SAY "They're not equal."
STOP

 

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:
We compare the upper-case version of "fred" to the lower-case version.  Since SPOT comparison are case-insensitive, these versions are considered equal, and so no jump takes place, and "They're equal" is printed out.

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:
READ-PROP 1, C2
SAY C2
SAY " is "
SAY C1
SAY " years old.\n"
RETURN
 

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
"Mary",12

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)

Arithmetic

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:
SAY C1
STOP

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:
SAY "Fred is smart.\n"
DEC C1
JUMP-IF-EQ Finish,C1,0
JUMP say-again

Finish:
STOP

This will output:

Fred is smart.
Fred is smart.
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)

Input / Output

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
Her name is Olive Oil

READ-PROP Read Property from Input Record:


Property numbers start at 1.

 

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"
"Abraham",42,"Lincoln"

Then READ-PROP 1,C1 results in "Peter" placed onto Card 1, and READ-PROP 2,C2 copies 12 onto Card 2.  NEXT goes to the next line. 

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
"Mary",12

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)

Bit Operations and Output
Instruction Name Meaning Format Example Meaning of Example
AND Bitwise AND:

AND the first two arguments and place the result into the third

AND C#,C#,C#
or
AND C#,value,C#
or
AND value,C#,C#
WRITE 5,C1
AND C1,3,C2
C1=5
C2=1
OR Bitwise OR:

OR the first two arguments and place the result into the third

OR C#,C#,C#
or
OR C#,value,C#
or
OR value,C#,C#
WRITE 5,C1
WRITE 3,C2
OR C1,C2,C3
C1=5
C2=3
C3=7
XOR Bitwise Exlusive-OR:

XOR the first two arguments and place the result into the third

XOR C#,C#,C#
or
XOR C#,value,C#
or
XOR value,C#,C#
WRITE 5,C1
WRITE 3,C2
XOR C1,C2,C3
C1=5
C2=3
C3=6
COMP Bitwise Ones-Complement:

In the first argument, change all 1's into 0's and vice versa, and place result into the second argument

COMP C#,C# WRITE 4,C1
COMP C1,C2
C1=4
C2=-5
RSHIFT Bitwise Right-Shift:

Shift the value of the first argument to the right by the number of bit places given in the second argument, and place the result into the third argument

Equivalent to dividing by 2**(2nd argument)

RSHIFT C#,value,C# WRITE 15,C1
RSHIFT C1,2,C2
C1=15
C2=3
LSHIFT Bitwise Left-Shift:

Shift the value of the first argument to the left by the number of bit places given in the second argument, and place the result into the third argument

Equivalent to multiplying by 2**(2nd argument)

LSHIFT C#,value,C# WRITE 15,C1
LSHIFT C1,2,C2
C1=15
C2=60
SAYBIN Print in Binary:

Prints the value in binary (the number of bits printed depends on the wordsize setting)

SAYBIN C#
or
SAYBIN value
SAYBIN 30 if wordsize set to "no limit", 
prints "1 1110"

if wordsize set to "8 bits", 
prints "0001 1110"

SAYHEX Print in Hexadecimal:

Print the value in hexadecimal (the number of digits printed depends on the wordsize setting)

SAYHEX C#
or
SAYHEX value
SAYHEX 254 if wordsize set to "no limit", 
prints "fe"

if wordsize set to "16 bits", 
prints "00fe"

Creative Commons License
This work is licensed under a Creative Commons License.