home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / fun / games / corewars.spk / !CoreInfo / Info / Commands < prev    next >
Text File  |  1990-11-16  |  11KB  |  264 lines

  1.  
  2.  
  3.   COMMANDS
  4.   --------
  5.  
  6.  This file details all the valid commands in the REDCODE instruction set
  7. supported by the archimedes version of Corewars. Some vary from the official
  8. specifications, and these originate from a Macintosh computer version of
  9. corewars. PCT is included because I think it is a good extension, and the
  10. others, JMG and DJZ, are included for compatibility reasons. It is advised
  11. that you do not use these last two commands in any new programs that you
  12. write.
  13.  
  14.  See the file Intro for information about how the instructions are stored and
  15. an explanation about the operand fields etc.
  16.  
  17.  
  18.  The compiler directives are as follows:
  19.                             
  20.  
  21. Addressing modes - there are four different addressing modes possible;
  22. immediate, direct, indirect and post-decremental indirect, the symbols for
  23. which are detailed here:
  24.  
  25.  # is placed before an expression to indicate that immediate addressing
  26. should be used; ie. 'dat #0'  - puts the actual value 0 in that cell
  27.  
  28.  @ is placed before an expression to indicate that indirect addressing should
  29. be used; ie. 'mov #0,@bombpt'  - moves a zero into the cell pointed to by the
  30. cell 'bombpt' (offset relative to bombpt, not executing instruction).
  31.  
  32.  alternatively, @ is also used at the beginning of a line to indicate the
  33. offset to the start of the program; ie. '@-4'  - assemble the following inst-
  34. ructions at the cell four cells behind of the point where the program will
  35. initially be called. There must be a @ used in this way before any instruct-
  36. ions can be compiled, and an error will be generated otherwise.
  37.  
  38.  < is placed before an expression to indicate that post decremental indirect
  39. addressing should be used; ie. 'mov #33,<bombpt'  - decrements the value
  40. stored at 'bombpt' and moves the immediate value 33 into the cell pointed to
  41. by the new value of 'bombpt'
  42.  
  43.  $ is placed before an expression to indicate that direct addressing should
  44. be used, although any expression without either a #,@,< or $ will be treated
  45. as direct; ie. 'mov $rubbish,$bin'  - copies cell 'rubbish' into cell 'bin'
  46. (Could be rewritten 'mov rubbish,bin').
  47.                                                                              
  48.  
  49. There are various other symbols which serve a purpose when compiling REDCODE:
  50.  
  51.  
  52.  . is used at the beginning of a line to indicate a label. A label can be
  53. upper or lower case letters, and may contain numbers, except in the first
  54. character. When being matched, case is not considered. An instruction may
  55. follow the label, seperated by a space; ie. '.imp2 mov 0,1'  - this cell can 
  56. be referred to as 'imp2' and contains a simple one-line program. Otherwise,
  57. the label is the only thing on the line; ie. '.start'.
  58.  
  59.  , is used to seperate operands in a REDCODE instruction;ie 'djn loop,label'.
  60. It is not essential, however, and is ignored by the compiler, so the previous
  61. example could legally be rewritten 'djn   loop  label' (extra spaces in any
  62. part of the line are also ignored).
  63.  
  64.  >, * and ; are comment characters which tell the compiler to ignore the rest
  65. of the line following any of them. This is so that comments may be included
  66. in REDCODE; ie. '.dwarf1 add #5,bombpt  ; add 5 to bomb pointer'.
  67.  
  68.  ( and ), brackets, are allowed in expressions, but do not influence the
  69. order of evaluation. They are in fact ignored, but included for compatibil-
  70. ity; ie.  'mov #3-(2-1),datapt' is treated as 'mov #3-2-1,datapt' so the
  71. value stored at datapt is 0 not 2.
  72.                                                       
  73.  + and - can be included in expressions evaluating to a cell location/value,
  74. and used in conjunction with a label if desired (which will usually be the
  75. case); ie. 'mov dwarf+1,@dest' - moves the cell one in front of 'dwarf' to
  76. the cell pointed to by the cell 'dest'. Other operators such as *, / etc. are
  77. not allowed. Also, expressions such as '@ beginning-7' are disallowed (the
  78. variable 'beginning' being assigned a value relative to the current offset
  79. set by @).
  80.     
  81.  
  82.                                            
  83. REDCODE instructions:-
  84.                       
  85. Syntax = [.label] [,] <MNEMONIC> [,] <operand A> [[,] [<operand B>]]
  86.  
  87.  The actual REDCODE instructions (case insensitive) are:-
  88.  
  89.  DAT A       A can be an immediate value (#) or a direct value (treated as an
  90. immediate value)
  91.  
  92.  (data)
  93.  
  94.  This instruction reserves a cell of MARS memory for data. The data value is
  95. initialised to the A-value. An attempt to execute it causes the executing
  96. side to lose a line of execution, or split, or in other words, die.
  97.  DAT has two uses: to provide data for your program, and to provide
  98. impediments to your opponent's program. DAT instructions can be MOV'ed wildlyinto core with the hope that the opposing program will try to execute them.
  99.                                       
  100.  
  101.                           
  102.  
  103.  MOV A,B     A can be any addressing mode, and B can be any mode except
  104.              immediate (#)
  105.                                         
  106.  (move)
  107.  
  108.  The cell at the A-location is copied to the B-location, replacing the
  109. B-location's old contents, or, if the B-location is protected, just removing
  110. the protection of that cell, so that the next attempt to write will succeed.
  111.  If the MOV instruction has an immediate A-location, then the immediate value
  112. is copied to the A field of the B-location, and every other field set to
  113. zero, so in effect the B-location becomes a DAT <A-value>. ** NB This is at
  114. variance with the official specifications, which alter different fields. **
  115.  If the A-location is not immediate, then all fields (opcode and both
  116. operands) are copied across.
  117.  
  118.  
  119.  
  120.  
  121.  ADD A,B     A can be any addressing mode, and B can be any mode except
  122.              immediate.
  123.  
  124.  (add)
  125.  
  126.  The value at the A-location is added to the B-location, replacing the B-
  127. location's old contents.
  128.  
  129.                         
  130.  
  131.  
  132.  SUB A,B      A can be any addressing mode, and B can be any mode except
  133.               immediate.
  134.  
  135.  (subtract)
  136.  
  137.  The value at the A-location is subtracted from the B-location, replacing the
  138. B-location's old contents.
  139.  
  140.  
  141.  
  142.  
  143.  JMP A         A can be any addressing mode except immediate.
  144.  
  145.  (jump)
  146.  
  147.  The A-location address replaces the program counter for the current split
  148. (line of execution), causing the instruction at that location to be executed
  149. next when that particular split is next executed (if you follow that...)
  150.  
  151.  
  152.  
  153.  
  154.  JMZ A,B       A and B can be any addressing mode except immediate.
  155.   
  156.  (jump if zero)
  157.  
  158.  If the A-field value of the B-location is zero, a jump will be done to the
  159. A-location, as described in the JMP instruction, above. Otherwise, execution
  160. continues with the next sequential instruction.
  161.  
  162.  
  163.  
  164.  
  165.  JMN A,B       A and B can be any addressing mode except immediate.
  166.  
  167.  (jump if not zero)
  168.  
  169.  If the A-field value of the B-location is not zero, a jump will be done to
  170. the A-location, as described in the JMP instruction, above. Otherwise, exec-
  171. ution continues with the next sequential instruction.
  172.  
  173.  
  174.  
  175.  
  176.  JMG A,B       A and B can be any addressing mode except immediate.
  177.  
  178.  (jump if greater than zero)
  179.  
  180.  This instruction is synonymous with JMN (because there is no negative data
  181. ...see section 'intro' for information).  ** NB This is not an official
  182. instruction, and you should use JMN instead **
  183.  
  184.  
  185.  
  186.  
  187.  DJN A,B       A and B can be any addressing mode except immediate.
  188.  
  189.  (decrement and jump if not zero)
  190.  
  191.  The A-field value of the B-location is reduced by one, and then tested. If
  192. it is not zero, a jump will be done to the A-location, as described in the
  193. JMP instruction, above. Otherwise, if it becomes zero, execution continues
  194. with the next sequential instruction. The A-field value of the B-location is
  195. reduced by one whether or not the jump is taken. The value is tested after it
  196. is decremented, so if it was zero before the instruction is executed, it will
  197. be decremented to memory size minus one, and the jump will be taken.
  198.  
  199.  
  200.  
  201.  
  202.  DJZ A,B       A and B can be any addressing mode except immediate.
  203.  
  204.  (decrement and jump if zero)
  205.  
  206.  The A-field value of the B-location is reduced by one, and then tested. If
  207. it is equal to zero, a jump will be done to the A-location, as described in
  208. the JMP instruction, above. Otherwise, if it is unequal to zero, execution
  209. continues with the next sequential instruction. The A-field value of the
  210. B-location is reduced by one whether or not the jump is taken. The value is
  211. tested after it is decremented, so if it was zero before the instruction is
  212. executed, it will be decremented to memory size minus one, and the jump will not be taken. ** NB This is not an official instruction **
  213.  
  214.  
  215.  
  216.  
  217.  CMP A,B       A and B can be any addressing mode.
  218.  
  219.  (compare)
  220.  
  221.  The value or values at the A-location are compared to the value(s) at the B-location. If they are unequal, the next instruction is skipped. If they are
  222. equal, the execution continues with the next sequential instruction. If the
  223. CMP instruction has an immediate operand, then only the A-field value at the
  224. cell referenced by the other operand is compared to the immediate value.
  225.  Otherwise all fields (opcode, operands) are compared to the corresponding
  226. fields of the B-location, and all three fields must be equal for the A-
  227. location value and the B-location value to be considered equal.
  228.  
  229.  
  230.  
  231.  
  232.  SPL A         A can be any addressing mode except immediate.
  233.  
  234.  (split)
  235.  
  236.  This instruction splits the execution of the program between the currently
  237. running program and the program beginning at the B location (the 'sibling'
  238. program). From that point on, a program's execution cycles are divided
  239. among all of its siblings. A program which has split twice with the SPL
  240. instruction will run as three seperate sibling programs, each of which will
  241. execute every sixth machine cycle.
  242.  For the purposes of this explanation, the set of sibling programs will be
  243. known as a 'side'.
  244.  After an SPL, the next split to be executed by this side will be the split
  245. after the new split at the A-location, not the next instruction in the
  246. program that performed the split command, or the new split. For example, if
  247. there is only one split active when an SPL command is issued, the new split
  248. would be created, but ignored until the original split was called once again.
  249.  A maximum of 64 siblings per side, 128 siblings in all, are allowed in MARS.
  250. There is no error indication given if the SPL is unsuccessful, for whatever
  251. reason (eg. 64 tasks already running; A location was not executable etc.).
  252.  
  253.  
  254.  
  255.  
  256.  PCT A         A can be any addressing mode except immediate.
  257.  
  258.  (protect)
  259.  
  260.  This instruction 'protects' the cell at the A-location. Any instruction
  261. which subsequently attempts to write to a protected cell will not alter the
  262. cell, but will remove the protection. The next attempt to write will then
  263. succeed. ** NB This is not an official instruction **
  264.