複製鏈接
請複製以下鏈接發送給好友

磁芯大戰

鎖定
磁芯大戰(core war or core wars)就是彙編程序間的大戰,程序在虛擬機中運行,並試圖破壞其他程序,生存到最後即為勝者。程序用一種特殊的彙編語言(RedCode)完成,運行於叫做MARS(Memory Array RedCode Simulator)的虛擬機中。
中文名
磁芯大戰
外文名
core war or core wars
屬    性
彙編程序
類    型
大戰

磁芯大戰人物介紹

早在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. 前言 - 讀者注意! { 第一部分 }
Ⅱ. 標記 { 第一部分 }
Ⅲ. MARS的特性 { 第一部分 }
Ⅳ. 地址模式 { 第二部分 }
V. 指令集 { 第二部分 }----------------------------------------------------------------------
Introduction to Redcode
-----------------------
I. Preface - Reader Beware! { Part I }
Ⅱ. Notation { Part I }
Ⅲ. MARS Peculiarities { Part I }
Ⅳ. Address Modes { Part Ⅱ }
V. Instruction Set { Part Ⅱ }
----------------

磁芯大戰前言

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:"表示我偏好的解釋. "其他:" 其他人的解釋. "註釋:"表示我在做什麼和
為什麼這樣. "評論:" 表示我跟從或反對該做法.沒有冒號後綴的可視為普通.
Ⅱ. 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 itsillegality) 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,... }.
Ⅲ. 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 jumpsor 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 ⅡNewsgroups: rec.games.corewar
(Mark A. Durham)
Subject: Intro to Redcode Part Ⅱ
Organization: Rice University,Houston,TX
Date: Thu,14 Nov 1991 09:45:13 GMT

磁芯大戰地址模式

尋址模式巧妙地(有時不太巧妙地) 改變指令的作用.這裏簡單説一下.
細節留待介紹指令集時再講.
井號(#) 表示操作數為即時尋址模式.即時尋址模式數據包含在當前指令的
字段裏. 如果 A-模式是即時的話,數據就在A-字段. 如果 B-模式是即時的
話,數據就在B-字段.
如果沒有指明模式 (86: 或使用 '$'),缺省為直接尋址模式. 直接尋址模式
指向相對於當前指令的一條指令. 地址 0 指向當前指令. 直接地址-1指向(物理上)
前一條指令. 直接地址 +1指向(物理上)下一條指令.
Ⅳ. 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,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.
----------------------------------------------------------------------