Download Learning ZIL
Transcript
Page 69 Learning ZIL 2/25/2002 Appendix D: ZIL Instructions ZIL instructions, also called op-codes, are the method by which you communicate with the interpreter. This is just a partial list; some op-codes are so obscure you'll never need to know them. A complete description of every instruction can be found in the ZIP Specification. In the list below, arguments to the instruction are listed after the name of the instruction. Optional arguments are italicized. Arithmetic Instructions ADD integer1 integer2 Adds the two given numbers and returns the sum. This usually appears in ZIL code as a "+"—the compiler changes it to "ADD." Example: <+ ,FRONT-SEAT-PASSENGERS ,BACK-SEAT-PASSENGERS> SUB integer1 integer2 Subtracts integer2 from integer1 and returns the difference. The compiler changes "-" to "SUB." Example: <- ,LT-BLATHER-ANGER 5> MUL integer1 integer2 Multiplies the two given numbers and returns the product. The compiler changes "*" to "MUL." Example: <* <MARTIANS-IN-ROOM> ,ANTENNA-ON-A-MARTIAN> DIV integer1 integer2 Divides integer1 by integer2 and returns the quotient, truncated to an integer if necessary. The compiler changes "/" to "DIV." Example: </ ,SCREEN-WIDTH 2> MOD integer1 integer2 Divides integer1 by integer2 and returns the remainder. Example: <MOD ,PEBBLES-IN-PILE 10> RANDOM integer Returns a random number between one and the given number, inclusive. Example: <RANDOM 17> Predicate Instructions EQUAL? arg1 arg2 arg3 arg4 Returns true if arg1 is equal? to any of the subsequent args. Example: <EQUAL? ,HERE ,OVAL-OFFICE ,ROSE-GARDEN ,PORTICO> ZERO? arg Returns true if the value of arg is zero. This often appears as <EQUAL? ,WHATEVER 0> in your game code; the compiler converts it to the ZERO? instruction. Example: <ZERO? ,FUEL-LEVEL> LESS? integer1 integer2 Returns true if integer1 is less than integer2. The compiler converts L? to LESS?. Example: <L? ,AIR-PRESSURE 4>