翰·馮·諾依曼簡介
早在1949年,電腦的先驅者約翰·馮·諾依曼在他的論文《自我繁衍的自動機理論》中已把病毒的藍圖勾勒出來,當時,絕大部分的電腦專家還不太相信這種會自我繁殖的程式.然而短短十年之後,磁芯大戰在貝爾實驗室中誕生,使他的構想成為事實。他是三個年輕人在工余時的產物。他們是麥耀萊、維索斯基以及莫里斯。其中莫里斯就是後來製造了“莫里斯蠕蟲”的羅特·莫里斯的父親。當時三人年紀都只有二十多歲。用於磁芯大戰的遊戲有多種,例如有個叫爬行者的程式(Creeper),每一次執行都會自動生成一個副本,很快電腦中原有資料就會被這些爬行者侵蝕掉;“侏儒”(Dwarf)程式在記憶系統中行進,每到第五個“地址”(address)便把那裡所儲存的東西變為零,這會使原本的程式嚴重破壞;最奇特的就是一個叫“印普”(Imp)的戰爭程式了,它只有一行指令,那就是“MOV 0,1”,其中MOV是“Move”的簡寫,即移動的意思。它把身處的地址中所載的“0”寫(移)到下一個地址中,當“印普”展開行動之後,電腦中原有的每一行指令都被改為“MOV 0,1”,換句話說,螢光屏上留下一大堆“MOV 0,1”。 在那些日子裡,電腦都沒有連線,是互相獨立的,因此病毒瘟疫很難傳播。如果有某部電腦受到“感染”,失去控制,工作人員只需把它關掉便可。但是當電腦連線逐漸成為社會結構的一部分之後,一個或自我複製的病毒程式便很可能帶來無窮的禍害了。例如爬行者程式就能夠從一台機器“爬”到另一台機器中。因此長久以來,懂得玩“磁芯大戰”遊戲的電腦工作者都嚴守一項不成文的規定:不對大眾公開這些程式的內容。 1983年,這項規定被打破了。科恩·湯普遜(Ken Thompson)是當年一項傑出電腦獎得獎人?在頒獎典禮上,他作了一個演講,不但公開證實了電腦病毒的存在,而且還告訴所有聽眾怎樣去寫自己的病毒程式。他的同行全都嚇壞了,然而這個秘密已經流傳出去了。
1984年,情況愈複雜了。這一年,《科學美國人》月刊(Scientific American)的專欄作家杜特尼(A.K.Dewdney)在5月刊號寫了第一篇討論“磁芯大戰”的文章,並且只要寄上兩塊美金,任何讀者都可以收到有關寫程式的綱領,在自己家的電腦中開闢戰場。
在1985年3月份的《科學美國人》里,杜特尼再次討論“磁芯大戰”和病毒。在文章的開頭他便說:“當去年5月有關‘磁芯大戰’的文章印出來時,我並沒有想過我所談論的是那么嚴重的題目……”文中第一次提到“病毒”這個名稱。他提到說,義大利的電腦程式員利用感染磁碟的方式使其它電腦受到破壞性程式的感染。 就這樣,潘多拉之盒被打開了,許多程式設計師都了解了病毒的原理,進而開始嘗試編制這種具有隱蔽性、攻擊性和傳染性的特殊程式。病毒從隱秘走向公開,先是利用磁碟,然後是利用網路,迅速在全世界範圍內擴散開來,成為電腦用戶的頭號敵人。
磁芯大戰(Core War)的語言Redcode教程
原題
Corewar Tutorial Pt INewsgroups: rec.games.corewar(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 }
----------------------------------------------------------------------
前言
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!
----------------------------------------------------------------------
標記
"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由以下格式的彙編語言指令組成
<標籤> <操作符> , <注釋>
Redcode consists of assembly language instructions of the form
,
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 is optional.
86: 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: as above, except length is not limited and case is not
addressed. Only the first eight characters are considered
significant.
X: 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 is separated from the (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 and合起來表示A-運算元. 類似地, the
合起來表示B-運算元. A-運算元對某些操作符來說是可選的.B-運算元對某些操
作符來說也是可選的. 只有END可以不帶運算元
86: 運算元用逗號隔開
88: 運算元用空白隔開
X: 運算元可用空白或逗號隔開. 少了一個逗號可能由於歧義而導致無法預料的後果.
注釋: '88標準強迫你在寫一個運算元時不能用空格, 接收空格來分開兩個運算元. 我
喜歡在 表達式里用空格, 因此我用逗號來分開運算元,我在這裡會清楚地這樣做.
The and taken together are referred to as the
A-operand. Similarly, the 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 間接定址的區別是語義的,而非依據造句法的
(譯者:我不太明白~)
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來表示.
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: 明確允許空行
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,
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.
----------------------------------------------------------------------
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
(Mark A. Durham)
Subject: Intro to Redcode Part II
Organization: Rice University, Houston, TX
Date: Thu, 14 Nov 1991 09:45:13 GMT
地址模式
定址模式巧妙地(有時不太巧妙地) 改變指令的作用.這裡簡單說一下.細節留待介紹指令集時再講.
井號(#) 表示 運算元為即時定址模式.即時定址模式數據包含在當前指令的
欄位里. 如果 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.
----------------------------------------------------------------------
指令集
DAT A, BDAT (數據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 sourcelistings. 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.
----------------------------------------------------------------------