⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appendix b the salvm instruction set.htm

📁 英文版编译器设计:里面详细介绍啦C编译器的设计
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0063)http://topaz.cs.byu.edu/text/html/Textbook/AppendixB/index.html -->
<HTML><HEAD><TITLE>Appendix B: The SALVM Instruction Set</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD>
<BODY>
<CENTER>
<H1>Appendix B<BR>The SALVM Instruction Set</H1></CENTER>
<HR>
<!-------------------------------------------------------------------------------->The 
SALVM is mostly related to a CISC architecture in hardware. Instruction 
formatting is much simpler, however. Instructions in the SALVM are always one 
byte in length, followed by one or two immediate parameters of varying length. 
The instructions in memory are laid out one right after the other, and do not 
necessarily need to be aligned at the word or dword level.
<P>Not all of the 256 possible instructions are used. The VM instructin space is 
very dense; there are 236 instructions in total. One of the byte-codes, zero is 
reserved as undefined. This was done in order to facilitate error detection, 
since zero occurrs fairly commonly as data. One of the universal problems with 
CISC is that the PC has to be only off by one byte in order for a valid 
instruction stream to look like garbage. It may even look like meaningful code; 
the instructions could be all legitimate, yet they would be completely random. 
In order to at least detect this problem, the zeroth instruction was reserved as 
undefined, since it occurrs so frequently in the instruction stream as an 
immediate parameter, anyway. If the VM attempts to execute instruction 0, it 
will halt, and throw a native exception (i.e., one at the C++ level). All other 
unused instructions within the VM will do the same, as well.
<P>The instructions within the VM are divided up into ten categories, as 
follows. There are instructions for loading and storing, integer arithmetic, 
floating point arithmetic, logical/bitwise arithmetic, comparison, flow-control, 
increment and decrement, data conversion, procedural control, and other 
miscellaneous instructions.
<P>
<H2>B.1 Loading and Storing Instructions</H2><!-------------------------------------------------------------------------------->The 
load and store instructions are used to move data between one of the segments of 
memory and the EES. Referr to {the diagrams in appendix A on the VM memory 
layout}. These are the Local Data area on the stack, the Global Data Area in the 
current module, and the Global data area of an external module. Additionally, 
the EES may contain a pointer to literally anywhere in memory, which can be used 
to load and store data to and from the EES, itself.
<P>In all architectures, a load and a store involve the use of a pointer. In the 
SALVM all pointers are derived as offsets from ome of the segment registers. 
Data may be loaded or stored at some offset from one of the registers like G or 
L, or an address may be computed from them and used at a later time as a direct 
pointer. Most of these instructions are three letters long. All load 
instructions start with an L, and all store instructions start with an S. The 
next letter or two referrs to where the data is comming from or going to 
(depending on a load or a store, respectively). The last letter usually referrs 
to how much data is to be moved, or whether the instruction computes an address, 
instead. Knowing this, anyone could be generally familiar with the instruction 
set, and recognize one of these instructions at a glance, and know exactly what 
it does. For instance, here are some examples: <PRE>      LSW 00000024        Load Stack Word 
      SGD 00000018        Store Global Dword
      LEB 0004 00000032   Load External Byte
      LSB 0000004A        Load eeS Byte

      <B>Figure {LSEX}</B>  Examples of load/store instructions.
</PRE>All of these instructions have either one or two immediate parameters. 
Notice that the middle letter designates a register, or the location of a 
pointer (on the EES). They all involve the computation of a pointer, in tandem 
with the movement of data. Most often, the immediate parameter(s) are used to 
compute the offset from this pointer, and this is where the data is 
sent/retrieved. 
<H3>B.1.1 Immediate values</H3><!-------------------------------------------------------------------------------->It 
is common for mathematical expressions to contain constants. At the assembly 
level, these take on the form of immediate values. In order to load an immediate 
value onto the EES, there are four instructions. <PRE>        Num  Instruction 
      =========================================
         04   LIB  <I>&lt;byte&gt;</I>
         05   LIW  <I>&lt;word&gt;</I>
         06   LID  <I>&lt;dword&gt;</I>
         07   LIQ  <I>&lt;qword&gt;</I>

      <B>Table {LIMM}</B>  The instructions to load immediate values onto the EES.
</PRE>The instructions merely load quantities of bytes, and there is no type 
associated. The data loaded might be signed or unsigned integer, or 
floating-point. Immediate values are stored in little-endian order. An example 
of the <TT>LID</TT> instruction is shown in figure {LIDEX} <PRE>             [PC]             __________________________.
              |    __________/______                    |
              V   /                 \                   V 
      -------------------------------------        | 00000001 |
       ... | LID | 01 | 00 | 00 | 00 | ...         |   ...    |
      -------------------------------------        |__________|
                  { dword offset    }                  EES
  
      <B>Figure {LIDEX}</B>  A representation of the LID instruction within the
      instruction stream.  In this example, the value 1 will be loaded onto the 
      EES.
</PRE>
<H3>B.1.2 Local Data Area</H3><!-------------------------------------------------------------------------------->The 
instructions to load and store within the local data area are listed in table 
{LSLOCT}. <PRE>        Num  Instruction 
      =========================================
         10   LLB <I>&lt;u32 offset&gt;</I>
         11   LLW <I>&lt;u32 offset&gt;</I>
         12   LLD <I>&lt;u32 offset&gt;</I>
         13   LLQ <I>&lt;u32 offset&gt;</I>
         20   SLB <I>&lt;u32 offset&gt;</I>
         21   SLW <I>&lt;u32 offset&gt;</I>
         22   SLD <I>&lt;u32 offset&gt;</I>
         23   SLQ <I>&lt;u32 offset&gt;</I>

      <B>Table {LSLOCT}</B>  The instructions to load and store data from the local
      data area.
</PRE>These instructions all work with the L register. They are always followed 
by an unsigned 32-bit (dword) offset, which is added to L in order to get the 
final address for loading and storing. For instance, the instruction <PRE>      LLB   0000001A
</PRE>will add the immediate value of 1Ah to the L register, and fetch a 
<I>byte</I> at the address in memory. Similarly, <PRE>      SLW   00000020
</PRE>will remove a word (2 bytes) from the top of the EES, add the immediate 
value 20h to L, and store the word at that address in memory. Notice that the 
offsets are in hex. Numbers in SALVM assembly are always in hex. For a graphical 
representation of the functionality of these instructions, referr to figure 
{LSLOCF} <PRE>                                             |   ...    |
                                             |==========| \
                                      [L]--&gt; | Reserved |  | Previous call frame
                                          |  |          | /
                                          |  |==========|
                                       +  |  |          | \
                                          |  |          |  | Local Data area
                                          V  |----------|  |
                         ,------- Offset --&gt; |  [Data] &lt;-------------.
                         |                   |----------|  |         |
                         |                   |          |  |         |
                         |                   |          |  |    |    V     |
                         |                   |          | /     |  [Data]  |
                         |                   |==========|       |          |
          [PC]           |            [S]--&gt; |   ...    |       |__________|
           |    _________|________    
           V   /                  \             Stack               EES           
   -----+-----+----+----+----+----+-----
    ... | LLx |    dword offset   | ...
   -----+-----+----+----+----+----+-----
      (LLx or SLx)

      <B>Figure {LSLOCF}</B>  A representation of the way the LLx and SLx 
      instructions operate.
</PRE>
<H3>B.1.3 Global Data Within the Same Module</H3><!-------------------------------------------------------------------------------->The 
instructions for manipulating global data operate in much the same way as those 
for local data. The global data instructions work with the G register, and can 
access global data within the current module, only. They are listed in table 
{LSGLBT} <PRE>        Num  Instruction 
      =========================================
         14   LGB <I>&lt;u32 offset&gt;</I>
         15   LGW <I>&lt;u32 offset&gt;</I>
         16   LGD <I>&lt;u32 offset&gt;</I>
         17   LGQ <I>&lt;u32 offset&gt;</I>
         24   SGB <I>&lt;u32 offset&gt;</I>
         25   SGW <I>&lt;u32 offset&gt;</I>
         26   SGD <I>&lt;u32 offset&gt;</I>
         27   SGQ <I>&lt;u32 offset&gt;</I>

      <B>Table {LSGLBT}</B>  The instructions to load and store data from the global
      data area.
</PRE>Like the local instructions, the global instructions all take a 32-bit 
unsigned offset to the location of the data to be fetched/stored. The 
instruction <PRE>      LGD   00000008
</PRE>will add the immediate value of 8h to the G register, and fetch a dword at 
the address in memory. Similarly, <PRE>      SGB   0000000E
</PRE>will remove a byte from the top of the EES, add the immediate value 0Eh to 
G, and store the byte at that address in memory. For a graphical representation 
of the functionality of these instructions, referr to figure {LSGLO} <PRE>                                              __________
                                      [G]--&gt; |          |
                                          |  |          |
                                          |  |          |
                                       +  |  |          |
                                          |  |          |
                                          V  |----------|
                         ,------- Offset --&gt; |  [Data] &lt;-------------.
                         |                   |----------|            |
                         |                   |          |            |
                         |                   |          |       |    V     |
                         |                   |          |       |  [Data]  |
                         |                   |          |       |          |
          [PC]           |                   |__________|       |__________|
           |    _________|________    
           V   /                  \             Global              EES           
   -----+-----+----+----+----+----+-----        Memory
    ... | SGx |    dword offset   | ...
   -----+-----+----+----+----+----+-----
      (LGx or SGx)

      <B>Figure {LSGLO}</B>  A representation of the way the LGx and SGx instructions
      operate.
</PRE>
<H3>B.1.4 Global Data Within an External Module</H3><!-------------------------------------------------------------------------------->Since 
there is no complete linking between modules in SAL, there exist several global 
data areas, one per module. One of these always remains current, and that is the 
one that G points to. It is often necessary, however to retrieve the value of a 
variable stored in the global data area of another module, and the SALVM has 
instructions just for that task. This task involves looking up the value of G 
for the other module in the MAT. These instructions all have a slightly 
different form, and are listed in table {LSEXTT}. <PRE>        Num  Instruction 
      =========================================
         18   LEB <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         19   LEW <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         1A   LED <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         1B   LEQ <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         28   SEB <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         29   SEW <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         2A   SED <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>
         2B   SEQ <I>&lt;u16 modnum&gt;</I> <I>&lt;u32 offset&gt;</I>

      <B>Table {LSEXTT}</B>  The load and store instructions for data in external 
      modules.
</PRE>In this form, <TT><I>&lt;modnum&gt;</I></TT> is a 16-bit unsigned value 
that referrs to the module's entry in the MAT (see appendix A). These 
instructions will compute their addresses by using the module number to get a 
temporary value for G, then add the successive 32-bit offset to that value. For 
example, this instruction <PRE>      LED   0002 00000010
</PRE>will look up the value of G for module 2, add the offset of 10h, and then 
load a dword at that address onto the EES. The instruction <PRE>      SEQ   0004 0000002A
</PRE>Will pull a qword from the EES, look up the value of G for module 4, add 
the offset 2Ah to that, and finally store the qword at that address in memory. <PRE>                #  Mod id   G
               ----------------              __________
               |0| MainApp |G0|  .--[Gk]--&gt; |          |
               |1| FooLib  |G1|  |       |  |          |
               |2| BarLib  |G2|  |       |  |          |
               | |   ...   |  |  |       |  |          |
          ,--&gt; |k| kLib    |Gk|--'       |  |          |
          |    | |   ...   |  |          |  |          |
          |    |n| nLib    |Gn|          |  |          |
          |    ----------------          V  |----------|
          |     Module Address  .-Offset--&gt; |  [Data] &lt;----------.
          |         Table       |           |----------|         |
          |                     |           |          |         |
          `--------.            |           |          |    |    V     |

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -