cpu_tour.html
来自「有趣的模拟进化的程序 由国外一生物学家开发 十分有趣」· HTML 代码 · 共 359 行 · 第 1/2 页
HTML
359 行
<html><title>A guided tour of the an ancestor and its hardware</title><body bgcolor="#FFFFFF" text="#000000" link="#0000AA" alink="#0000FF" vlink="#000044"><h2 align=center>A guided tour of an ancestor and its hardware</h2><p>This document describes the structure of the virtual CPU and anexample organism running on it.<h3>The Virtual CPU Structure</h3><p>The virtual CPU, which is the default "body" or "hardware" of the organisms,contains the following set of components, (as further illustrated in thefigure below).<menu><li>A <font color="#006666"><b><i>memory</i></b></font> that consists of a sequence of instructions, each associated with a set of flags to denote if the instruction has been executed, copied, mutated, etc.<li>An <font color="#880088"><b><i>instruction pointer</i></b></font> (IP) that indicates the next site in the memory to be executed.<li>Three <font color="#FF8888"><b><i>registers</i></b></a></font> that can be used by the organism to hold data currently being manipulated. These are often operated upon by the various instructions, and can contain arbitrary 32-bit integers.<li>Two <font color="#008800"><b><i>stacks</i></b></font> that are used for storage. The organism can theoretical store an arbitrary amount of data in the stacks, but for practical purposes we currently limit the maximum stack depth to ten.<li>An <font color="#CCCC00"><b><i>input buffer</i></b></font> and an <font color="#CCCC00"><b><i>output buffer</i></b> </font>that the organism uses to receive information, and return the processed results.<li>A <font color="#8888FF"><b><i>Read-Head</i></b></font>, a <font color="#8888FF"><b><i>Write-Head</i></b></font>, and a <font color="#8888FF"><b><i>Flow-Head</i></b></font> which are used to specify positions in the CPU's memory. A copy command reads from the Read-Head and writes to the Write-Head. Jump-type statements move the IP to the Flow-Head.</menu><p><center><img align=center src="cpu2.gif"></center><br><br><br><br><br><h3>Instruction set design</h3><p>The instruction set in Avida is loaded on startup from a configuration filespecified in the <tt>genesis</tt> file. This allows selection of differentinstruction sets without recompiling the source code, as well as allowing different sizedinstruction sets to be specified. It is not possible to alter the behaviorof individual instructions or add new instructions without recompiling Avida;such activities have to be done directly in the source code.<p>The available instructions are listed in the <tt>inst_set.*</tt> files witha <tt>1</tt> or a <tt>0</tt> next to an instruction to indicate if itshould or should not be included. Changing the instruction set to be usedsimply involves adjusting these flags.<p>The instructions were created with three things in mind:<menu><li>To be as complete as possible (both in a "Turing complete" sense -- that is, it can compute any computable function -- and, more practically, to ensure that simple operations only require a few instructions).<li>For each instruction to be as robust and versatile as possible; all instructions should take an "appropriate" action in any situation where they can be executed.<li>To have as little redundancy as possible between instructions. (Several instructions have been implemented that are redundant, but such combinations will typically not be turned on simultaneously for a run.)</menu><p>One major concept that differentiates this virtual assembly language from itsreal-world counterparts is in the additional uses of <tt>nop</tt> instructions(no-operation commands).These have no direct effect on the virtual CPU when executed, but oftenmodify the effect of any instruction that precedes them. In a sense, youcan think of them as purely regulatory genes. The default instruction sethas three such <tt>nop</tt> instructions: <tt>nop-A</tt>, <tt>nop-B</tt>,and <tt>nop-C</tt>.<p>The remaining instructions can be seperated into three classes. The firstclass is those few instructions that are unaffected by nops. Most of theseare the "biological" instructions involved directly in the replicationprocess. The second class of instructions is those for which a <tt>nop</tt>changes the head or register affected by the previous command. For example,an <tt>inc</tt> command followed by the instruction <tt>nop-A</tt> wouldcause the contents of the <tt>AX</tt> register to be incremented, while an<tt>inc</tt> command followed by a <tt>nop-B</tt> would increment <tt>BX</tt>.<p>The notation we use in instruction definitions to describe that a defaultcomponent (that is, a register or head) can be replaced due to a nop commandis by surrounding name with <tt>?</tt>'s. The component list is thedefault one to be used, but if a <tt>nop</tt> follows the command, thecomponent it represents in this context will replace this default.If the component between the questionmarks is a register than a subsequent <tt>nop-A</tt>represents the <tt>AX</tt> register, <tt>nop-B</tt> is <tt>BX</tt>, and<tt>nop-C</tt> is <tt>CX</tt>. If the component listed is a head(including the instruction pointer) then a <tt>nop-A</tt> represents theInstruction Pointer, <tt>nop-B</tt> represents the Read-Head, and<tt>nop-C</tt> is the Write-Head. Currentlythe Flow-Head has no <tt>nop</tt> associated with it.<p>The third class of instructions are those that use a series of <tt>nop</tt>instructions as a template (label) for a command that needs to referenceanother position in the code, such as<tt>h-search</tt>. If <tt>nop-A</tt> follows a search command, it scans forthe first complementary template (<tt>nop-B</tt>) and moves the Flow-Headthere. Templates may be composed of more than a single <tt>nop</tt>instruction. A series of nops is typically abbreviated to the associatedletter and separated by colons. This the sequence "<tt>nop-A nop-A nop-C</tt>"would be displayed as "<tt>A:A:C</tt>".<p>The label system used in Avida allows for an arbitrary number of nops. Bydefault, we have three: <tt>nop-A</tt>'s complement is <tt>nop-B</tt>,<tt>nop-B</tt>'s is <tt>nop-C</tt>, and <tt>nop-C</tt>'s is <tt>nop-A</tt>.Likewise, some instructions talk about the complement of a register or head-- the same pattern is used in those cases. So if an instruction tests if<tt>?BX?</tt> is equal to its complement, it will test if<tt>BX == CX</tt> by default, but if it is followed by a<tt>nop-C</tt> it will test if <tt>CX == AX</tt>.<p>I've often considered to moving to four <tt>nop</tt> instructions by default;A, C, G, and T with the expected complements.<h3>Instruction Set Reference</h3><p>The full instruction set description is included<a href="inst_set.html">here</a>. An abbreviated description of the 26 default instructions is below.<p><table><tr><th valign=top>(a-c) <td><tt>nop-A</tt>, <tt>nop-B</tt>, <br> and <tt>nop-C</tt> <td valign=top>No-operation instructions; these modify other instructions.</tr><tr><th>(d) <td><tt>if-n-equ</tt> <td>Execute next instruction only-if ?BX? does not equal its complement</tr><tr><th>(e) <td><tt>if-less</tt> <td>Execute next instruction only if ?BX? is less than its complement</tr><tr><th>(f) <td><tt>pop</tt> <td>Remove a number from the current stack and place it in ?BX?</tr><tr><th>(g) <td><tt>push</tt> <td>Copy the value of ?BX? onto the top of the current stack</tr><tr><th>(h) <td><tt>swap-stk</tt> <td>Toggle the active stack</tr><tr><th>(i) <td><tt>swap</tt> <td>Swap the contents of ?BX? with its complement.</tr><tr><th>(j) <td><tt>shift-r</tt> <td>Shift all the bits in ?BX? one to the right</tr><tr><th>(k) <td><tt>shift-l</tt> <td>Shift all the bits in ?BX? one to the left</tr><tr><th>(l) <td><tt>inc</tt> <td>Increment ?BX?</tr><tr><th>(m) <td><tt>dec</tt> <td>Decrement ?BX?</tr><tr><th>(n) <td><tt>add</tt> <td>Calculate the sum of BX and CX; put the result in ?BX?</tr><tr><th>(o) <td><tt>sub</tt>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?