CSDN博客

img michaelz2001

[译]磁芯大战(Core War)的语言Redcode教程

发表于2002/5/13 9:35:00  1975人阅读

主题: Core War(磁芯大战)的Redcode简介
译者: Michael Zeng [michaelz2000@21cn.com]
日期: 02-5-9 15:23
*转载请勿删改,谢谢*

原题:
Corewar Tutorial Pt INewsgroups: rec.games.corewar
From: DURHAM@ricevm1.rice.edu (Mark A. Durham)
Subject: Intro to Redcode Part I
Organization: Rice University, Houston, TX
Date: Thu, 14 Nov 1991 09:41:37 GMT

Redcode介绍
-----------------------


  I. 前言 - 读者注意!    { 第一部分 }
 
 II. 标记                  { 第一部分 }

III. MARS的特性           { 第一部分 }

 IV. 地址模式           { 第二部分 }

  V. 指令集           { 第二部分 }


----------------------------------------------------------------------

Introduction to Redcode
-----------------------


  I. Preface - Reader Beware!    { Part I }
 
 II. Notation                    { Part I }

III. MARS Peculiarities          { Part I }

 IV. Address Modes               { Part II }

  V. Instruction Set             { Part II }


----------------------------------------------------------------------


I. 前言 - 读者注意!

   The name "Core War" arguably can be claimed as public domain. 
Thus, any program can pass itself off as an implementation of Core
War.(译者:不会翻译呀~) 理论上,大家都希望在一个系统上写Redcode,
并且知道在所有其他系统上它都会以相同的方式运行.  哎呀,这没什么关系呀.


I. Preface - Reader Beware!

   The name "Core War" arguably can be claimed as public domain.
Thus, any program can pass itself off as an implementation of Core
War.  Ideally, one would like to write a Redcode program on one system
and know that it will run in exactly the same manner on every other
system.  Alas, this is not the case.

   Core War 有四种系统:非ICWS系统, ICWS'86, ICWS'88, 和扩展系统.
非ICWS系统通常与A. K. Dewdney在《科学的美国》上的一篇文章
"Computer Recreations" 中描述的Core War不同.ICWS'86 和 ICWS'88 系统则分别
遵循"International Core War Society"在1986年和1988年制定的规则.扩展系统
一般支持ICWS'86, ICWS'88规则,并有一定的扩展.我将会谈到常用的公共扩展,如果
它们在所有扩展系统上都可用的话(大部分都不是).


   Basically, Core War systems fall under one of four catagories:
Non-ICWS, ICWS'86, ICWS'88, or Extended.  Non-ICWS systems are usually
a variant of Core War as described by A. K. Dewdney in his "Computer
Recreations" articles appearing in Scientific American.  ICWS'86 and
ICWS'88 systems conform to the standards set out by the International
Core War Society in their standards of 1986 and 1988, respectively.
Extended systems generally support ICWS'86, ICWS'88, and proprietary
extensions to those standards.  I will discuss frequently common
extensions as if they were available on all Extended systems (which
they most certainly are not).


    我将不会在这里讨论非ICWS系统. 如果你能读懂这篇文章,你就可以轻易理解
大多数非ICWS系统. 虽然ICWS'86和ICWS'88被称为"标准",但是它们都受歧义性和
额外标准问题的困扰,我将尝试指出来.
   注意.  因为几乎所有的解释想别的一样合理,我自然更喜欢"我"的解释. 
我会尝试指出其他解释有歧义的地方,并清楚表明我的或其他人的相关解释.


   I will not describe Non-ICWS systems in this article.  Most Non-
ICWS systems will be easily understood if you understand the systems
described in this article however.  Although called "standards",
ICWS'86 and ICWS'88 (to a lesser extent) both suffer from ambiguities
and extra-standard issues which I will try to address.
   This is where the reader should beware.  Because almost any
interpretation of the standard(s) is as valid as any other, I
naturally prefer MY interpretation.  I will try to point out other
common interpretations when ambiguities arise though, and I will
clearly indicate what is interpretation (mine or otherwise) as such.
You have been warned!


----------------------------------------------------------------------


 II. 标记 

   "86:" 表示ICWS'86的特性.  "88:" 则表示ICWS'88的.  "X:" 表示扩展系统. 
"Durham:"表示我偏好的解释.  "其他:" 其他人的解释.  "注释:"表示我在做什么和
为什么这样.  "评论:" 表示我跟从或反对该做法.没有冒号后缀的可视为普通.

II. Notation

   "86:" will indicate an ICWS'86 feature.  "88:" will indicate an
ICWS'88 feature.  "X:" will indicate an Extended feature.  "Durham:"
will indicate my biased interpretation.  "Other:" will indicate
interpretations adhered to by others.  "Commentary:" is me explaining
what I am doing and why.  "Editorial:" is me railing for or against
certain usages.  Items without colon-suffixed prefaces can be
considered universal.


   Redcode由以下格式的汇编语言指令组成

<标签>   <操作符> <A-模式><A-字段>, <B-模式><B-字段>   <注释>

 

   Redcode consists of assembly language instructions of the form

<label>   <opcode> <A-mode><A-field>, <B-mode><B-field>   <comment>


Recode例程:

; Imp
; by A. K. Dewdney
;
imp     MOV imp, imp+1      ; 程序把自己复制到前面一个指令
        END                 ; 并且移动穿过内存

(译者注:IMP是最短的Core War战士,只有一句)

An example Recode program:

; Imp
; by A. K. Dewdney
;
imp     MOV imp, imp+1      ; This program copies itself ahead one
        END                 ; instruction and moves through memory.


<标签>是可选的.
86: <标签> 从第一列开始,1到8个字符长,必须以字母开头且由合法字符组成.
    不分大小写("abc"等同于"ABC").
88: <标签> 同上, 但长度不限和区分大小写.  只有前8个字符有意义
X: <标签>前面可以有任意多的空白(空格, TAB键,和新行), 长度任意,必须以字母
开头且由合法字符组成. ("abc" 不同于 "ABC").
注释: 我全用小写字母写 标签,这样来和操作符和操作数区分

The <label> is optional.
86: <label> begins in the first column, is one to eight characters
    long, beginning with an alphabetic character and consisting
    entirely of alphanumerals.  Case is ignored ("abc" is equivalent
    to "ABC").
88: <label> as above, except length is not limited and case is not
    addressed.  Only the first eight characters are considered
    significant.
X: <label> can be preceded by any amount of whitespace (spaces, tabs,
    and newlines), consists of any number of significant alphanumerals
    but must start with an alphabetic, and case is significant ("abc"
    is different from "ABC").
Commentary: I will always use lowercase letters for labels to
    distinguish labels from opcodes and family operands.


操作符 和<标签>之间用空白隔开.  操作符不区分大小写.  DAT, MOV,
    ADD, SUB, JMP, JMZ, JMN, DJN, CMP, SPL, 和 END 都是可用的操作符
86: SPACE 也作为一个操作符.
88: SLT 和 EQU 是操作符.  SPACE 不是.
X: 以上的和XCH,PCT都是操作符,还有无数的扩展.
注释: END, SPACE, 和 EQU是伪指令,因为它们向汇编程序指明了操作,但不
    产生可执行的代码.  我用大写的操作符来和<标签>,文本区分开.


The <opcode> is separated from the <label> (if there is one) by
    whitespace.  Opcodes may be entered in either uppercase or
    lowercase.  The case does not alter the instruction.  DAT, MOV,
    ADD, SUB, JMP, JMZ, JMN, DJN, CMP, SPL, and END are acceptable
    opcodes.
86: SPACE is also recognized as an opcode.
88: SLT and EQU are recognized as opcodes.  SPACE is not.
X: All of the above are recognized as opcodes as well as XCH and PCT,
    plus countless other extensions.
Commentary: END, SPACE, and EQU are known as pseudo-ops because they
    really indicate instructions to the assembler and do not produce
    executable code.  I will always capitalize opcodes and pseudo-ops
    to distinguish them from labels and text.


The <A-模式> and <A-字段> 合起来表示A-操作数. 类似地, the <B-模式><B-字段>
    合起来表示B-操作数.  A-操作数对某些操作符来说是可选的.B-操作数对某些操
    作符来说也是可选的.  只有END可以不带操作数

86: 操作数用逗号隔开
88: 操作数用空白隔开
X: 操作数可用空白或逗号隔开.  少了一个逗号可能由于歧义而导致无法预料的后果.
注释: '88标准强迫你在写一个操作数时不能用空格, 接收空格来分开两个操作数. 我
    喜欢在表达式里用空格, 因此我用逗号来分开操作数,我在这里会清楚地这样做.


The <A-mode> and <A-field> taken together are referred to as the
    A-operand.  Similarly, the <B-mode><B-field> combination is known
    as the B-operand.  The A-operand is optional for some opcodes.
    The B-operand is optional for some opcodes.  Only END can go
    without at least one operand.
86: Operands are separated by a comma.
88: Operands are separated by whitespace.
X: Operands are separated by whitespace and/or a comma.  Lack of a
    comma can lead to unexpected behaviour for ambiguous constructs.
Commentary: The '88 standard forces you to write an operand without
    whitespace, reserving whitespace to separate the operands.  I like
    whitespace in my expressions, therefore I prefer to separate my
    operands with a comma and will do so here for clarity.


<模式> 有 # (即时寻址), @ (间接寻址), 或 < (86: Auto-Decrement 间接寻址
    88: Pre-Decrement 间接寻址). 缺省为直接寻址.
86: $ 表示直接寻址
88: $ 不可用
X: $ 和86一样
注释:  Auto-Decrement 间接寻址和Pre-Decrement 间接寻址的区别是语义的,而非依据造句法的
(译者:我不太明白~)


<mode> is # (Immediate Addressing), @ (Indirect Addressing), or <
    (86: Auto-Decrement Indirect, 88: Pre-Decrement Indirect).  A
    missing mode indicates Direct Addressing.
86: $ is an acceptable mode, also indicating Direct Addressing.
88: $ is not an acceptable mode.
X: $ is an acceptable mode as in 86:.
Commentary: The distinction between Auto-Decrement Indirect Addressing
    and Pre-Decrement Indirect Addressing is semantic, not syntactic.


<字段> 是标签和整数的任意组合,由 + (加号)和 - (减号)隔开.
86: 括号被明确禁止.  "*" 定义为一个特殊的标签,表示当前语句
88: 添加了 * (乘号) and / (整数除法).  "*" 不再象86一样是特殊的标签
X: 表达式中允许出现括号和空格.
注释:"*" 作为特殊的标签对某些编译程序来说可能很有用, 但对Redcode编译程
    序就完全是多余的.  在Redcode中当前语句总是能用0来表示.


<field> is any combination of labels and integers separated by the
    arithmetic operators + (addition) and - (subtraction).
86: Parentheses are explicitly forbidden.  "*" is defined as a special
    label symbol meaning the current statement.
88: Arithmetic operators * (multiplication) and / (integer division)
    are added.  "*" is NOT allowed as a special label as in 86:.
X: Parentheses and whitespace are permitted in expressions.
Commentary: The use of "*" as meaning the current statement may be
    useful in some real assemblers, but is completely superfluous in a
    Redcode assembler.  The current statement can always be referred
    to as 0 in Redcode.


<注释> 由 ; (分号)开头, 在新行结束(译者:象C++的//), 可以是任意数量
    的字符.  注释可以自己占一行,前面不需要有指令
88: 明确允许空行


<comment> begins with a ; (semicolon), ends with a newline, and can
    have any number of intervening characters.  A comment may appear
    on a line by itself with no instruction preceding it.
88: Blank lines are explicitly allowed.

 


   我常用"A" 来表示A-操作数,"B" 表示B-操作数(大写是重要的). 
用"a" 来表示A-字段, "b" 表示B-字段.  所以我从不用"a"或"b"做标签.

   我用花括号来包括一类操作数或指令. 所以 "A" 就等同于"{ a, #a, @a, <a }".
用 "???" 来表示任意操作数,"x" 或 "label"表示一个标签.  因此一句完整的
Redcode语句就写成这样

x    ??? A, B   ; 这描述了所有可能的Redcode语句.


   I will often use "A" to mean any A-operand and "B" to mean any
B-operand (capitalization is important).  I use "a" to mean any  A-
field and "b" to mean any B-field.  For this reason, I never use "a"
or "b" as an actual label.
   I enclose sets of operands or instructions in curly braces.  Thus
"A" is equivalent to "{ a, #a, @a, <a }". I use "???" to mean any
opcode and "x" or "label" as an arbitrary label.  Thus, the complete
family of acceptable Redcode statements can be represented as

x    ??? A, B   ; This represents all possible Redcode statements.


"???"很少使用,因为我们通常在讨论特定操作符的特点. 方便起见,我常用 "x-1"
(尽管它不合理) 表示标签 "x" 的前一条语句. "M" 则总是一个表示MARS内存大小
的整数.

"???" is rarely used as most often we wish to discuss the behaviour of
a specific opcode.  I will often use labels such as "x-1" (despite its
illegality) for the instruction before the instruction labelled "x",
for the logically obvious reason.  "M" always stands for the integer
with the same value as the MARS memory size.


----------------------------------------------------------------------


III. MARS的特性

   MARS有两个特点,使Redcode和其他汇编语言不同. 首先,MARS没有绝对地址.
第二,内存是循环的.
   由于没有绝对地址, 所以Redcode都是用相对寻址写的.  在相对寻址里, 所以地址
都解释为当前执行指令的位移.地址 0 就是当前执行指令.  地址 -1 是前一个当
前执行指令(假设没有跳转或分支).地址 +1 是下一个执行指令 (假设没有跳转或分支).
   因为内存是循环的, 每条指令都有无穷多个地址. 假设内存大小为M, 当前指令的地址
有 { ..., -2M, -M, 0, M, 2M, ... }.  前一个指令是{ ..., -1-2M, -1-M, -1,
M-1, 2M-1, ... }.  下一个指令是{ ..., 1-2M, 1-M, 1, M+1, 2M+1, ... }.


III. MARS Peculiarities

   There are two things about MARS which make Redcode different from
any other assembly language.  The first of these is that there are no
absolute addresses in MARS.  The second is that memory is circular.
   Because there are no absolute addresses, all Redcode is written
using relative addressing.  In relative addressing, all addresses are
interpreted as offsets from the currently executing instruction.
Address 0 is the currently executing instruction.  Address -1 was the
previously executed instruction (assuming no jumps or branches).
Address +1 is the next instruction to execute (again assuming no jumps
or branches).
   Because memory is circular, each instruction has an infinite number
of addresses.  Assuming a memory size of M, the current instruction
has the addresses { ..., -2M, -M, 0, M, 2M, ... }.  The previous
instruction is { ..., -1-2M, -1-M, -1, M-1, 2M-1, ... }.  The next
instruction is { ..., 1-2M, 1-M, 1, M+1, 2M+1, ... }.

注释: MARS因历史原因通过标准化字段为0 到 M-1 的正整数来运行这些
   利用了环状特性的目标代码. 由于内存大小在编程阶段常常是未知的,
   MARS有一个引导程序在处理代码放置和初始化任务指针之余,使字段标准化.


注释:Redcode程序常想提早知道MARS的内存大小. 有时这是不可能的.
    因为标准化字段只能用0 到 M-1 的整数来表示, 我们不能用M来表示.较好
    的东西是? M-1.  但我们怎样在不知道内存大小的时候写M-1? 回忆上面讲的,
    -1 就等于 M-1.  最后要注意的: -1/2 是等于 0 的(而不是 M/2[译者注:是
    (m-1)/2吧?]) 汇编程序对表达式求值得 -0.5,然后舍去了.


Commentary: MARS systems have historically been made to operate on
   object code which takes advantage of this circularity by insisting
   that fields be normalized to positive integers between 0 and M-1,
   inclusive.  Since memory size is often not known at the time of
   assembly, a loader in the MARS system (which does know the memory
   size) takes care of field normalization in addition to its normal
   operations of code placement and task pointer initialization.

Commentary: Redcode programmers often want to know what the memory
    size of the MARS is ahead of time.  This is not always possible.
    Since normalized fields can only represent integers between 0 and
    M-1 inclusive, we can not represent M in a normalized field.  The
    next best thing?  M-1.  But how can we write M-1 when we do not
    know the memory size?  Recall from above that -1 is equivalent to
    M-1.  Final word of caution: -1/2 is assembled as 0 (not as M/2)
    since the expression is evaluated within the assembler as -0.5 and
    then truncated.


86: 只能载入两个编译了的Redcode程序(战士)到MARS内存(磁芯).
88:  磁芯在没有载入战士时被初始化为(充满)DAT 0, 0.
     可以载入任意数量的战士.

注释: 比赛时几乎都是一对一,只载入对战的两个战士.


86: Only two assembled-Redcode programs (warriors) are loaded into
    MARS memory (core).
88: Core is initialized to (filled with) DAT 0, 0 before loading any
    warriors.  Any number of warriors may be loaded into core.

Commentary: Tournaments almost always pit warrior versus warrior with
    only two warriors in core.


   MARS是一个多任务系统.  战士以一个进程开始,但可以"分裂"出更多
的任务. 当一个战士的所有进程被杀死,它就输了.  当只剩下一个战士可
以继续运行,那它就是胜利者.
86: 每个战士最多只能有 64 个进程.
88: 不限制进程数量


----------------------------------------------------------------------


   MARS is a multi-tasking system.  Warriors start as just one task,
but can "split" off additional tasks.  When all of a warriors tasks
have been killed, the warrior is declared dead.  When there is a sole
warrior still executing in core, that warrior is declared the winner.
86: Tasks are limited to a maximum of 64 for each warrior.
88: The task limit is not set by the standard.


----------------------------------------------------------------------

第二部分:
Corewar Tutorial Pt IINewsgroups: rec.games.corewar
From: DURHAM@ricevm1.rice.edu (Mark A. Durham)
Subject: Intro to Redcode Part II
Organization: Rice University, Houston, TX
Date: Thu, 14 Nov 1991 09:45:13 GMT


 IV. 地址模式

   寻址模式巧妙地(有时不太巧妙地) 改变指令的作用.这里简单说一下.
细节留待介绍指令集时再讲.
   井号(#) 表示操作数为即时寻址模式.即时寻址模式数据包含在当前指令的
字段里.  如果 A-模式是即时的话, 数据就在A-字段.  如果 B-模式是即时的
话, 数据就在B-字段.
   如果没有指明模式 (86: 或使用 '$' ), 缺省为直接寻址模式. 直接寻址模式
指向相对于当前指令的一条指令.  地址 0 指向当前指令. 直接地址-1指向(物理上)
前一条指令. 直接地址 +1指向(物理上)下一条指令.

IV. Address Modes

   Addressing modes subtly (sometimes not-so-subtly) alter the
behaviour of instructions.  A somewhat brief description of their
general properties is given here.  Specifics will be left to the
instruction set section.
   An octothorpe (#) is used to indicate an operand with an Immediate
Address Mode.  Immediate mode data is contained in the current
instruction's field.  If the A-mode is immediate, the data is in the
A-field.  If the B-mode is immediate, the data is in the B-field.
   If no mode indicator is present (86: or the US dollar sign '$' is
present), Direct Address Mode is used.  Direct addresses refer to
instructions relative to the current instruction.  Address 0 refers to
the current instruction.  Direct address -1 refers to the (physically)
previous instruction.  Direct address +1 refers to the (physically)
next instruction.


    @ 表示间接寻址模式. 在间接寻址模式中, 间接地址和直接寻址一样也指向一条
指令, 但目标不是间接地址指向的指令,而是间接地址指向的指令的B-字段表示
的地址.

(译者注:混乱了吧,有点象C语言里"指针的指针"的意思)
例如:

x-2     DAT  #0,  #0   ; 目标指令
x-1     DAT  #0, #-1   ; 指针指令
x       MOV   0, @-1   ; 复制自己到 x-2.


   The commercial-at (@) is used to indicate Indirect Address Mode.
In indirect addressing, the indirect address points to an instruction
as in direct addressing, except the target is not the instruction to
which the indirect address points but rather the instruction pointed
to by the B-field of the instruct pointed to by the indirect address.
Example:

x-2     DAT  #0,  #0   ; Target instruction.
x-1     DAT  #0, #-1   ; Pointer instruction.
x       MOV   0, @-1   ; Copies this instruction to location x-2.


   小于号 (<) 表示 (86: 自动-, 88: 预-)消耗间接寻址模式. 它的作用和
间接寻址模式一样,但指针在使用前会被消耗.
(译者注:好像就是先减 1 再取值)
例如:

x-2     DAT  #0,  #0   ; 目标指令
x-1     DAT  #0,  #0   ; 指针指令. 和@的例子比较一下.
x       MOV   0, <-1   ; 复制自己到 x-2..


   The less-than (<) is used to indicate (86: Auto-, 88: Pre-)
Decrement Indirect Address Mode.  Its behaviour is just like that of
Indirect Address Mode, except the pointer is decremented before use.
Example:

x-2     DAT  #0,  #0   ; Target instruction
x-1     DAT  #0,  #0   ; Pointer instruction.  Compare to @ example.
x       MOV   0, <-1   ; Copies this instruction to location x-2.


注释:虽然消耗间接寻址模式看起来象间接寻址模式的简单扩展,  有时候它真的
     很巧妙 - 特别是与 DJN 一起使用.  有一点要注意,它的名字从 '86标准的
     自动消耗间接寻址模式 该为 '88 标准的预消耗间接寻址模式.它们的差异在
     下面提到,这对一般的Redcode程序员来说是不太重要的. 我建议没兴趣的人
     跳过下一段.
 
   
Commentary: Although Decrement Indirect addressing appears to be a
    simple extension of Indirect addressing, it is really very tricky
    at times - especially when combined with DJN.  There are sematic
    differences between the '86 and '88 standards, thus the change in
    name from Auto-Decrement to Pre-Decrement.  These differences are
    discussed below.  This discussion is non-essential for the average
    Redcode programmer.  I suggesting skipping to the next section for
    the weak-stomached.

(译者:我也不想翻译呀~但还是拿出专业精神~)
86: Durham: 指令从内存取出到一个指令寄存器. 再对每个操作数求值,储存
    位置(到地址寄存器)和指令(到数值寄存器).求值之后指令被执行.
    操作数求值: 如果是即时模式, 地址寄存器置为0 (当前指令地址) 数值
    寄存器置为当前指令. 如果是直接模式, 地址寄存器置为字段的值,数值
    寄存器置为地址寄存器指向的指令. 如果是间接模式,地址寄存器置为字段
    与字段指向的指令的B-字段的和,数值寄存器置为地址寄存器指向的指令.
    如果是自动消耗模式, 地址寄存器置为一个比字段与字段指向的指令的B-字段
    的和少 1 的值,数值寄存器置为地址寄存器指向的指令.
  
 操作数被求值后(但在指令执行前), 如果任一模式是自动消耗的话,相应的
    内存地址会消耗(译者:就是减1).如果两个模式都是自动消耗且两个字段
    都指向同一指针, 内存地址会消耗两次. 注意:现在指令指向与任一操作
    数以及它在寄存器中的任何一个拷贝都不同的指令.
86: 其他: 和上述相同,除了没有寄存器.所有过程都在内存中进行.
   
   
86: Durham: Instructions are fetched from memory into an instruction
    register.  Each operand is evaluated, storing a location (into an
    address register) and an instruction (into a value register) for
    each operand.  After the operands have been evaluated, the
    instruction is executed.
   Operand Evaluation: If the mode is immediate, the address register
    is loaded with 0 (the current instruction's address) and the value
    register is loaded with the current instruction.  If the mode is
    direct, the address register is loaded with the field value and
    the value register is loaded with the instruction pointed to by
    the address register.  If the mode is indirect, the address
    register is loaded with the sum of the field value and the B-field
    value of the instruction pointed to by the field value and the
    value register is loaded with the instruction pointed to by the
    address register.  If the mode is auto-decrement, the address
    register is loaded with a value one less than the sum of the field
    value and the B-field value of the instruction pointed to by the
    field value and the value register is loaded with the instruction
    pointed to by the address register.  AFTER the operands have been
    evaluated (but before instruction execution), if either mode was
    auto-decrement, the appropriate memory location is decremented.
    If both modes were auto-decrement and both fields pointed to the
    same pointer, that memory location is decremented twice.  Note
    that this instruction in memory then points to a different
    instruction than either operand and also differs from any copies
    of it in registers.
86: Other: As above, except there are no registers.  Everything is
    done in memory.
   
注释: ICWS'86清楚说明指令寄存器的使用,但其他操作数地址和数值寄存器
    都只是隐含的.  歧义性和缺乏对内存和寄存器工作原理的清晰描述让
    ICWS'86 备受责难,因而促使 ICWS'88诞生.
88: 同上,除了所有工作都在内存中完成,以及预消耗间接寻址取代了自动消
    耗间接寻址. 预消耗间接寻址在操作数求值时消耗内存(译者:注意消耗
    内存的意思是令该地址的值减1) 而不是求值之后. 它先对A操作数求值
    再对B操作数求值.
   
   
Commentary: ICWS'86 clearly states the use of an instruction register,
    but the other operand address and value registers are only
    implied.  Ambiguities and lack of strong statements delineating
    what takes place in memory and what takes place in registers
    condemned ICWS'86 to eternal confusion and gave birth to ICWS'88.
88: As above except everything is done in memory and Pre-Decrement
    Indirect replaces Auto-Decrement Indirect.  Pre-Decrement Indirect
    decrements memory as it is evaluating the operands rather than
    after.  It evaluates operand A before evaluating operand B.


----------------------------------------------------------------------


V. 指令集

DAT A, B
   DAT (数据data) 指令有两个作用.  一,它允许你储存数据作指针,位移等之用
二, 执行DAT指令的任何进程都会从进程队列移走. 当战士所有的进程都从进程队
列移走,那它就输了.
86: DAT 只能有一个操作数-- B-操作数. A-字段没有定义(例子中是 #0),
    但B-操作数相同的 DAT 指令必须相同.
88: DAT 允许有两个操作数,但只有两种模式 - 即时 和 预消耗.
X: DAT 可带一个或两个任意模式的操作数. 如果只有一个操作数,将被认为是B-操
    作数,A-操作数则默认为 #0
注释: 值得注意的是消耗将在进程移出队列之前发生, 因为指令在操作数求值后执行
   
   
V. Instruction Set

DAT A, B
   The DAT (data) instruction serves two purposes.  First, it allows
you to store data for use as pointers, offsets, etc.  Second, any task
which executes a DAT instruction is removed from the task queue.  When
all of warrior's tasks have been removed from the queue, that warrior
has lost.
86: DAT allows only one operand - the B-operand.  The A-field is left
    undefined (the example shows #0), but comparisons of DAT
    instructions with identical B-operands must yield equality.
88: DAT allows two operands but only two modes - immediate and
    pre-decrement.
X: DAT takes one or two operands and accepts all modes.  If only one
    operand is present, that operand is considered to be the B-operand
    and the A-operand defaults to #0.
Commentary: It is important to note that any decrement(s) WILL occur
    before the task is removed from the queue since the instruction
    executes only after the operand evaluation.


MOV A, B
   MOV (移动move) 指令复制一个字段值(如果均为即时模式)或整个指令 (如果均
   不是即时模式) 到磁芯的另一个位置(从 A 到 B).
86: Durham: MOV #a, #b 把自己改写为 MOV #a, #a.
注释: 在 ICWS'86 中有一个印刷上的错误,把 MOV #a, B 解释错了.
    有ICWS'86的人, 请把第四页第二栏倒数第二行的"B-field" 删去.
88: 不允许使用即时的B-模式.(译者:可能译得不对)
X: 允许使用即时的B-模式,和B-操作数为0的效果相同.  (参阅 86: Durham: 上面).
   
   
MOV A, B
   The MOV (move) instruction either copies a field value (if either
mode is immediate) or an entire instruction (if neither mode is
immediate) to another location in core (from A to B).
86: Durham: MOV #a, #b changes itself to MOV #a, #a.
Commentary: There is a clear typographical error in ICWS'86 which
    changes the interpretation of MOV #a, B to something non-sensical.
    For those with a copy of ICWS'86, delete the term "B-field" from
    the next-to-last line of the second column on page 4.
88: No immediate B-modes are allowed.
X: Immediate B-modes are allowed and have the same effect as a
    B-operand of 0.  (See 86: Durham: above).


ADD A, B
86: ADD 指令把 A-位置的值和B-位置的值相加, 取代B-位置的旧内容
88: 如果 A-模式 是即时模式, ADD的作用同上.如果A-模式不是即时模式,
    则A-操作数指向的指令的A-字段和B-字段分别于B-操作数指向的指
    令的A-字段和B-字段相加. B-模式不能为即时模式.
X: B-模式可为即时模式,作用与86:相同.
    例如: 当执行一次之后 ADD #2, #3 变成 ADD #2, #5 .
   
   
ADD A, B
86: The ADD instruction adds the value at the A-location to the value
    at the B-location, replacing the B-location's old contents.
88: If the A-mode is immediate, ADD is interpreted as above.  If the
    A-mode is not immediate, both the A-field and the B-field of the
    instruction pointed to by the A-operand are added to the A-field
    and B-field of the instruction pointed to by the B-operand,
    respectively.  The B-mode can not be immediate.
X: Immediate B-modes are allowed and have the same effect as in 86:.
    Example: ADD #2, #3 becomes ADD #2, #5 when executed once.


SUB A, B
   SUB (减subtract) 指令和上述的情况相同,不同的是 A 减去 B.


SUB A, B
   The SUB (subtract) instruction is interpreted as above for all
three cases, except A is subtracted from B.


JMP A, B
   JMP (跳转jump) 指令改变指令指针为 A-操作数.
86: JMP 只能有一个操作数 - A-操作数.  B-操作数看作 #0.
88: JMP 允许两个操作数, 但A-模式不能为即时模式
X: JMP 允许两个操作数, A-模式可以是即时模式.即时的A-模式操作数在运行是
   看成是 JMP 0, B .
   
   
JMP A, B
   The JMP (jump) instruction changes the instruction pointer to point
to the instruction pointed to by the A-operand.
86: JMP allows only one operand - the A-operand.  The B-operand is
    shown as #0.
88: JMP allows both operands, but the A-mode can not be immediate.
X: JMP allows both operands and the A-mode can be immediate.  An
    immediate A-mode operand is treated just like JMP 0, B when
    executed.


JMZ A, B
   JMZ (为零跳转jump if zero) 指令当B-操作数指向的指令的B-字段为零时,
跳转到A-操作数指向的指令.
88: 不允许即时的 A-模式.


JMZ A, B
   The JMZ (jump if zero) instruction jumps to the instruction pointed
to by the A-operand only if the B-field of the instruction pointed to
by the B-operand is zero.
88: Immediate A-modes are not allowed.


JMN A, B
   JMN (非零跳转jump if non-zero) 指令当B-操作数指向的指令的B-字段不为零
时,跳转到A-操作数指向的指令.
88: 不允许即时的 A-模式.


JMN A, B
   The JMN (jump if non-zero) instruction jumps to the instruction
pointed to by the A-operand only if the B-field of the instruction
pointed to by the B-operand is non-zero.
88: Immediate A-modes are not allowed.


DJN A, B
   DJN (消耗后非零跳转decrement and jump if non-zero) 指令消耗B-操作数指向
的指令的B-字段,消耗后不为零就跳转到A-操作数指向的指令.
88: 不允许即时的 A-模式.


DJN A, B
   The DJN (decrement and jump if non-zero) instruction causes the
B-field of the instruction pointed to by the B-operand to be
decremented.  If the decremented values is non-zero, a jump to the
instruction pointed to by the A-operand is taken.
88: Immediate A-modes are not allowed.


CMP A, B
   CMP (比较,相等时跳过compare, skip if equal)指令比较两个字段(如果都是
即时模式)或两条完整的指令(如果均不是即时模式), 当两者相等时跳过下一条指令.
注释: 在 ICWS'86 中有一个印刷上的错误,把 CMP #a, B 解释错了.
    有ICWS'86的人, 请把第5页第2栏第5行的"B-field" 删去.
    同时,第6页例子的注释写反了("相等" 应为 "不相等" 反之亦然).  虽然标签
    是写对了.
88: 不允许即时的 B-模式.


CMP A, B
   The CMP (compare, skip if equal) instruction compares two fields
(if either mode is immediate) or two entire instructions (if neither
mode is immediate) and skips the next instruction if the two are
equivalent.
Commentary: There is a clear typographical error in ICWS'86 which
    changes the interpretation of CMP #a, B to something non-sensical.
    For those with a copy of ICWS'86, delete the term "B-field" from
    the fifth line from the bottom of the second column on page 5.
    Also, the comments to the example on page 6 have been switched
    (equal is not equal and vice versa).  The labels are correct
    though.
88: Immediate B-modes are not allowed.


SPL A, B
   SPL (分裂split)指令 分裂成战士当前进程和一个新进程. 例如: 两个
战士的战斗, 1 和 2, 战士 1 有两个进程 (1 和 1') 战士 2 只有一个进程,
看起来就想这样: 1, 2, 1', 2, 1, 2, 1', 2, 等等.
86: SPL 只允许有一个操作数 - B-操作数. A-操作数看成 #0.  执行SPL后,
    下一条执行的指令是新增的进程(新进程放在进程队列的前面).  每个战士最
    多可以有64个进程.
88: SPL分裂 A-操作数,而不是B-操作数.执行SPL后,下一条执行的指令
    是原来没有新增进程时会执行到的那个进程(新进程放在进程队列的后面)
    没有明确限制进程的数量. 不允许即时模式的 A-操作数.
X: 允许即时模式的 A-操作数,和 SPL 0, B 的效果一样.
   
   
SPL A, B
   The SPL (split) instruction splits the execution between this
warrior's currently running tasks and a new task.  Example: A battle
between two warriors, 1 and 2, where warrior 1 has two tasks (1 and
1') and warrior 2 has only one task would look like this: 1, 2, 1', 2,
1, 2, 1', 2, etc.
86: SPL allows only one operand - the B-operand.  The A-operand is
    shown as #0.  After executing the SPL, the next instruction to
    execute for this warrior is that of the newly added task (the new
    task is placed at the front of the task queue).  A maximum of 64
    tasks is allowed for each warrior.
88: SPL splits the A-operand, not the B-operand.  After executing the
    SPL, the next instruction to execute for this warrior is the same
    instruction which would have executed had another task not been
    added (the new task is placed at the back of the task queue).
    There is no explicit task limit on warriors.  Immediate A-operands
    are not allowed.
X: Immediate A-operands are allowed and behave as SPL 0, B when
    executed.


88: SLT A, B: SLT (如果小于就跳过skip if less than) 指令 如果A小于B就跳过
    下一条指令.  不允许即时的 B-模式.
X: 允许即时的 B-模式.

X: XCH A, B: XCH (交换exchange)指令 交换A-操作数指向的指令的A-字段和B-字段

X: PCT A, B: PCT (保护protect) 指令 保护A-操作数指向的指令直到当有指令尝试去
    覆盖被保护的指令时去除保护.


88: SLT A, B: The SLT (skip if less than) instruction skips the next
    instruction if A is less than B.  No Immediate B-modes are
    allowed.
X: Immediate B-modes are allowed.

X: XCH A, B: The XCH (exchange) instructions exchanges the A-field and
    the B-field of the instruction pointed to by the A-operand.

X: PCT A, B: The PCT (protect) instruction protects the instruction
    pointed to by the A-operand until the protection is removed by an
    instruction attempting to copy over the protected instruction.


伪指令: 汇编程序指令
-----------------------------------------
Pseudo-Ops: Instructions to the Assembler
-----------------------------------------


END
    END 伪指令表示Redcode源程序结束
86: END 不带操作数
88: 如果END后带有标签, 则首先执行END带的标签处的指令.(译者:即程序的入口)
X: ORG A (起点origin) 取代了END初始指令的功能.
注释: 如果没有指明初始指令,程序的第一条指令就是初始指令.只需以"JMP start"开
    头就可以取得于"END start" 或 "ORG start"相同的效果.


END
    The END pseudo-op indicates the end of the Redcode source program.
86: END takes no operands.
88: If END is followed by a label, the first instruction to be
    executed is that with the label following END.
X: ORG A (origin) takes over this initial instruction function from
    END.
Commentary: If no initial instruction is identified, the first
    instruction of your program will be the initial instruction.  You
    can accomplish the same effect as "END start" or "ORG start" by
    merely starting your program with the instruction "JMP start".


86: SPACE A, B: SPACE 伪指令使Redcode源程序清单变得美观. SPACE A, B 的
    意思是跳过 A 行, 保持B行在下一页.  某些汇编程序不支持SPACE, 但将它
    看作注释.

88: label EQU A: EQU (等于equate) 伪指令类似于宏,它把后面出现的所有标
    签"label"用字符串"A"代替.
注释: 正常的标签是一个参照物.  例如:

x       DAT  #0,  #x   ; 这里x使用在B-字段中
x+1     DAT  #0,  #x   ; 每条指令的B-字段给出
x+2     DAT  #0,  #x   ;    相对x的位移.

等同于

x       DAT  #0,  #0   ; 位移为0
x+1     DAT  #0, #-1   ;    1
x+2     DAT  #0, #-2   ;    2

但是

x!      EQU   0        ; 作用就象 #define x! 0
        DAT  #0,  #x!  ; 在扩展系统中,标签里
        DAT  #0,  #x!  ;          可以使用惊叹号.
        DAT  #0,  #x!  ; 我专用它们
                       ;    来表示即时等同标签.

等同于

        DAT  #0,  #0   ; 直接写文本
        DAT  #0,  #0   ;    在每一行看来
        DAT  #0,  #0   ;    都是一样的

----------------------------------------------------------------------


【全文完】

 


86: SPACE A, B: The SPACE pseudo-op helps pretty-up Redcode source
    listings.  SPACE A, B means to skip A lines, then keep B lines on
    the next page.  Some assemblers do not support SPACE, but will
    treat it as a comment.

88: label EQU A: The EQU (equate) pseudo-op gives the programmer a
    macro-like facility by replacing every subsequent occurrence of
    the label "label" with the string "A".
Commentary: A normal label is a relative thing.  Example:

x       DAT  #0,  #x   ; Here x is used in the B-field
x+1     DAT  #0,  #x   ; Each instruction's B-field gives
x+2     DAT  #0,  #x   ;    the offset to x.

is the same as

x       DAT  #0,  #0   ; Offset of zero
x+1     DAT  #0, #-1   ;    one
x+2     DAT  #0, #-2   ;    two

but

x!      EQU   0        ; Equate label like #define x! 0
        DAT  #0,  #x!  ; Exclamation points can be used
        DAT  #0,  #x!  ;    in labels (in Extended systems)
        DAT  #0,  #x!  ; I use them exclusively to indicate
                       ;    immediate equate labels.

is the same as

        DAT  #0,  #0   ; A direct text replacement
        DAT  #0,  #0   ;    appears the same on every
        DAT  #0,  #0   ;    line it is used.

----------------------------------------------------------------------

 


 

0 0

相关博文

我的热门文章

img
取 消
img