Green Script - Scripting Kit V1 ------------------------------- ********************************************* TECHNICAL SPECIFICATION: Green Script Opcodes ********************************************* WARNING: This is preliminary documentation. It may not be 100% accurate, and could contain errors. Value Name Parameters ----------------------------------------------------------------------- 0 NOP None 1 HALT None 2 LABEL 1 byte:label id 3 GOTO 1 byte:label id 4 GOSUB 1 byte:label id 5 RETURN None 6 BREAK None 7 MARK None 8 ZERO 1 byte:variable id 9 INV 1 byte:variable id a LET_VALUE 1 byte:variable id 4 bytes:value b LET_VARIABLE 1 byte:variable id 1 byte:variable id c ADD_VALUE 1 byte:variable id 4 bytes:value d ADD_VARIABLE 1 byte:variable id 1 byte:variable id e SUB_VALUE 1 byte:variable id 4 bytes:value f SUB_VARIABLE 1 byte:variable id 1 byte:variable id 10 MULT_VALUE 1 byte:variable id 4 bytes:value 11 MULT_VARIABLE 1 byte:variable id 1 byte:variable id 12 DIV_VALUE 1 byte:variable id 4 bytes:value 13 DIV_VARIABLE 1 byte:variable id 1 byte:variable id 14 IF 1 byte:variable id 1 byte:ifcode *.... ....1 byte:data type (x bytes: data) 15 RETURN_VARIABLE 1 byte:variable id 16 RETURN_VALUE 4 bytes:value 17 PUSH_VALUE 4 bytes:value 18 PUSH_VARIABLE 1 byte:variable id 19 POP_VARIABLE 1 byte:variable id 1a SIZE 1 byte:variable id 1b CLEAR None 1c SUM 1 byte:variable id 1d PROD 1 byte:variable id 1e CLEAR_VALUE 4 bytes:value 1f CLEAR_VARIABLE 1 byte:variable id 20 INT 1 byte:variable id 21 ABS 1 byte:variable id * See ifcodes.txt ****************************************************************** NOP ****************************************************************** OPCODE VALUE: 0 DATA SIZE: 0 TOTAL SIZE: 1 The "NOP" (NO Operation) command does nothing. Example: 00 ****************************************************************** HALT ****************************************************************** OPCODE VALUE: 1 DATA SIZE: 0 TOTAL SIZE: 1 The "HALT" command halts execution (not an error exit). Example: 01 ****************************************************************** LABEL ****************************************************************** OPCODE VALUE: 2 DATA SIZE: 1 TOTAL SIZE: 2 The "LABEL" command is used at compile / assembly / loading time to use as a "saved offset" - the location of the LABEL opcode is stored in a table, it's index in that table defined by the byte following the opcode. Example: 02 01 When this is discovered, the file offset is stored in entry "01". ****************************************************************** GOTO ****************************************************************** OPCODE VALUE: 3 DATA SIZE: 1 TOTAL SIZE: 2 The "GOTO" command is used at run time to look up an offset that is stored in a table, it's index in that table defined by the byte following the opcode. Example: 03 01 When this is discovered, the file offset stored in entry "01" is read and the current read offset is changed to match. ****************************************************************** GOSUB ****************************************************************** OPCODE VALUE: 4 DATA SIZE: 1 TOTAL SIZE: 2 The "GOSUB" command is exactly the same as the "GOTO" command, apart from the fact that before jumping to the offset in the table, the current read offset is added to the top of the "call stack". Example: 04 01 When this is discovered, the current read location is "pushed" onto the top of the call stack, then the file offset stored in entry "01" is read and the current read offset is changed to match. ****************************************************************** RETURN ****************************************************************** OPCODE VALUE: 5 DATA SIZE: 0 TOTAL SIZE: 1 The "RETURN" command is used in conjunction with the "GOSUB" command. When encountered, the topmost offset is "popped" from the top of the call stack, and the current read offset is changed to match. Example: 05 ****************************************************************** BREAK ****************************************************************** OPCODE VALUE: 6 DATA SIZE: 0 TOTAL SIZE: 1 The "BREAK" command triggers a debug break (works in both debug and non-debug mode). Example: 06 ****************************************************************** MARK ****************************************************************** OPCODE VALUE: 7 DATA SIZE: 0 TOTAL SIZE: 1 The "MARK" command triggers a debug mark (works in debug mode only), which makes the debugger (if present) wait for user input before continuing. Example: 07 ****************************************************************** ZERO ****************************************************************** OPCODE VALUE: 8 DATA SIZE: 1 TOTAL SIZE: 2 The "ZERO" command sets the contents of the variable specified by the byte following the opcode to zero. Example: 08 01 ****************************************************************** INV ****************************************************************** OPCODE VALUE: 9 DATA SIZE: 1 TOTAL SIZE: 2 The "INV" command reverses the sign of the contents of the variable specified by the byte following the opcode (i.e. positive values become negative, and negative values become positive). Example: 09 01 ****************************************************************** LET_VALUE ****************************************************************** OPCODE VALUE: a DATA SIZE: 5 TOTAL SIZE: 6 The "LET_VALUE" command sets the contents of the variable specified by the byte following the opcode to the floating-point value specified by the four bytes following the variable id. Example: 0a 01 ?? ?? ?? ?? ****************************************************************** LET_VARIABLE ****************************************************************** OPCODE VALUE: b DATA SIZE: 2 TOTAL SIZE: 3 The "LET_VARIABLE" command copies the contents of the variable specified two bytes after the opcode into the variable specified immediately following the opcode. Example: 0a 02 01 ****************************************************************** ADD_VALUE ****************************************************************** OPCODE VALUE: c DATA SIZE: 5 TOTAL SIZE: 6 The "ADD_VALUE" command sets the contents of the variable specified by adding to it the floating-point value specified by the four bytes following the variable id. Example: 0c 01 ?? ?? ?? ?? ****************************************************************** ADD_VARIABLE ****************************************************************** OPCODE VALUE: d DATA SIZE: 2 TOTAL SIZE: 3 The "ADD_VARIABLE" command adds the contents of the variable specified two bytes after the opcode to the variable specified immediately following the opcode. Example: 0d 02 01 ****************************************************************** SUB_VALUE ****************************************************************** OPCODE VALUE: e DATA SIZE: 5 TOTAL SIZE: 6 The "SUB_VALUE" command sets the contents of the variable specified by taking from it the floating-point value specified by the four bytes following the variable id. Example: 0e 01 ?? ?? ?? ?? ****************************************************************** SUB_VARIABLE ****************************************************************** OPCODE VALUE: f DATA SIZE: 2 TOTAL SIZE: 3 The "SUB_VARIABLE" command takes the contents of the variable specified two bytes after the opcode from the variable specified immediately following the opcode. Example: 0f 02 01 ****************************************************************** MULT_VALUE ****************************************************************** OPCODE VALUE: 10 DATA SIZE: 5 TOTAL SIZE: 6 The "MULT_VALUE" command sets the contents of the variable specified by multiplying it with the floating-point value specified by the four bytes following the variable id. Example: 10 01 ?? ?? ?? ?? ****************************************************************** MULT_VARIABLE ****************************************************************** OPCODE VALUE: 11 DATA SIZE: 2 TOTAL SIZE: 3 The "MULT_VARIABLE" command multiplies the contents of the variable specified two bytes after the opcode with the variable specified immediately following the opcode, and stores it in the variable specified immediately after the opcode. Example: 11 02 01 ****************************************************************** DIV_VALUE ****************************************************************** OPCODE VALUE: 12 DATA SIZE: 5 TOTAL SIZE: 6 The "DIV_VALUE" command divides the contents of the variable specified immediately after the opcode by the 4-byte floating- point value specified two bytes after the opcode. Example: 12 01 ?? ?? ?? ?? ****************************************************************** DIV_VARIABLE ****************************************************************** OPCODE VALUE: 13 DATA SIZE: 2 TOTAL SIZE: 3 The "DIV_VARIABLE" command divides the contents of the variable specified immediately after the opcode by the contents of the variable specified two bytes after the opcode. Example: 13 02 01 ****************************************************************** IF ****************************************************************** OPCODE VALUE: 14 DATA SIZE: 5 or 8 TOTAL SIZE: 6 or 9 The "IF" command is complex, by the fact that the size of the data following the command can vary, depending on the type of value that is being compared against (a 4-byte floating-point value, or a single-byte variable identifier). Here is the structure: O V I T D ___4-byte float (T=0) "IF"___Variable___Ifcode___Data Type__/ **OR** (14) ID Byte Byte ID Byte \___1-byte variable ID (T=1) The purpose of the "IF" command is to provide a conditional operator. It compares the contents of the variable specified by "V" to the data specified by "D" using the algebra-based operator (or "Ifcode") "I". The size of data "D" varies, depending on the value of "T", which specifies the data type for "D". Generally, "T" is only "0" (meaning a 4-byte float), or "1" (meaning a single byte variable id, whos contents are to be used in the comparison). If the result of the expression is "true", then the command that follows the "IF" command is executed. However, if the outcome is "false", the next command is skipped and execution continues two commands along. Examples: 14 01 02 01 02 14 01 03 00 ?? ?? ?? ?/ For more information about data type specifiers and ifcodes, see the "ifcodes.txt" reference file. ****************************************************************** RETURN_VARIABLE ****************************************************************** OPCODE VALUE: 15 DATA SIZE: 1 TOTAL SIZE: 2 The "RETURN_VARIABLE" command stops execution of the program, and tells the run-program or debugger the result or "return value" of the program. It is extracted from the variable specified by the byte immediately following the opcode. Example: 15 01 ****************************************************************** RETURN_VALUE ****************************************************************** OPCODE VALUE: 16 DATA SIZE: 4 TOTAL SIZE: 5 The "RETURN_VALUE" command stops execution of the program, and tells the run-program or debugger the result or "return value" of the program. The result to be given is in 4-byte floating point value form, and follows the opcode. Example: 16 ?? ?? ?? ?? ****************************************************************** PUSH_VALUE ****************************************************************** OPCODE VALUE: 17 DATA SIZE: 4 TOTAL SIZE: 5 The "PUSH_VALUE" command adds the 4-byte floating-point value which follows the opcode to the top of the "user stack". Example: 17 ?? ?? ?? ?? ****************************************************************** PUSH_VARIABLE ****************************************************************** OPCODE VALUE: 18 DATA SIZE: 1 TOTAL SIZE: 2 The "PUSH_VARIABLE" command adds the contents of the variable specified by the byte immediately following the opcode to the top of the "user stack". Example: 18 01 ****************************************************************** POP_VARIABLE ****************************************************************** OPCODE VALUE: 19 DATA SIZE: 1 TOTAL SIZE: 2 The "POP_VARIABLE" command looks up the value on the top of the "user stack" (the most recently "PUSH"-ed item), and changes the value of the variable specified by the byte following the opcode, to match. The top item is then removed. Example: 19 01 ****************************************************************** SIZE ****************************************************************** OPCODE VALUE: 1a DATA SIZE: 1 TOTAL SIZE: 2 The "SIZE" command looks up the number of items on the "user stack" (i.e. the SIZE of the stack), and changes the value of the variable specified by the byte following the opcode to match. Example: 1a 01 ****************************************************************** CLEAR ****************************************************************** OPCODE VALUE: 1b DATA SIZE: 0 TOTAL SIZE: 1 The "CLEAR" command is used to remove all items from the "user stack" (i.e. to CLEAR the stack). Example: 1b ****************************************************************** SUM ****************************************************************** OPCODE VALUE: 1c DATA SIZE: 1 TOTAL SIZE: 2 The "SUM" command performs a "summation" operation. It adds togther and finds the total value of all of the items on the "user stack", and places them in the variable specified by the byte following the opcode. Example: 1c 01 ****************************************************************** PROD ****************************************************************** OPCODE VALUE: 1d DATA SIZE: 1 TOTAL SIZE: 2 The "PROD" command performs a "product" operation. It multiplies togther and finds the total product of all of the items on the "user stack", and places them in the variable specified by the byte following the opcode. Example: 1d 01 ****************************************************************** CLEAR_VALUE ****************************************************************** OPCODE VALUE: 1e DATA SIZE: 4 TOTAL SIZE: 5 The "CLEAR_VALUE" command removes a certain number of items from the top of the "user stack". This "certain number" is equal to the 4-byte floating-point value specified immediately after the opcode. Example: 1e ?? ?? ?? ?? ****************************************************************** CLEAR_VARIABLE ****************************************************************** OPCODE VALUE: 1f DATA SIZE: 1 TOTAL SIZE: 2 The "CLEAR_VARIABLE" command removes a certain number of items from the top of the "user stack". This "certain number" is equal to the value of the variable specified by the byte following the opcode. Example: 1f 01 ****************************************************************** INT ****************************************************************** OPCODE VALUE: 20 DATA SIZE: 1 TOTAL SIZE: 2 The "INT" commands performs an "integer" operation on the variable specified by the byte following the opcode. It changes the value to show only the "whole" part of the number (i.e. removes all digits from after the decimal point.). The INT command DOES NOT round the number up or down. Example: 20 01 ****************************************************************** ABS ****************************************************************** OPCODE VALUE: 21 DATA SIZE: 1 TOTAL SIZE: 2 The "ABS" commands performs an "absolute" operation on the variable specified by the byte following the opcode. It inverts the sign of the value, changing negative numbers into positive ones, and positive numbers into negative ones. A zero remains equal. Example: 21 01