Article View: rec.games.corewar
Article #185Re: ICWS'88 questions
From: Scott W. Adkins
Date: Tue, 29 Sep 1992 12:28
Date: Tue, 29 Sep 1992 12:28
74 lines
4898 bytes
4898 bytes
In article <1992Sep29.061348.29540@mnemosyne.cs.du.edu> brudiakg@nyx.cs.du.edu (Ben Rudiak-Gould) writes:
>
>alpha equ 1+1
>beta equ label-3
>gamma equ label2-label
>
> dat #alpha ; #alpha = #2
> dat #beta ; #beta = #-1
> dat #gamma ; #gamma = #1
>label spl 666
>label2 jmp label
>
>Now, the first data statement should obviously evaluate to dat #2
>(that's absolute). The second would make more sense if it evaluated
>as dat #-1 (that's relative). The third should probably evaluate to
>dat #1 (the number of core locations from label to label2), since the
>relative addressing would "drop out" when subtracting two labels
>(that's absolute). My question should have been, "How does the
>assembler make this determination?"
Hmmm... Actually, the question seems to still be a little ambigious...
Ok, when dealing with equates, you must have some kind of mechanism that
will take the equate label and completely substitute it with what is
defined on the right hand side of the definition. So, dat #alpha would
become dat #1+1. Dat #beta would become dat #label-3. Dat #gamma would
become dat #label2-label. Once the substitution has occurred, then that
instruction is ran back through the evaluator a second time to evaluate
what expressions were substituted in. This might have been obvious...
I am just trying to cover all bases of the question.
To evaluate the expression, you must know the relative address of each
label defined based from the beginning of the program. This does not
include equate labels... just the regular labels. The first line in the
program starts at address 0. This would make the address of Label to be
3 and the address of Label2 to be 4. Usually, the assembler scans the
code first to determine the addresses of regular lables and substitute
equate labels with their expressions, and then scan the code again to
actually do the evaluation of the expressions.
Ok, now comes the fun part... if all of the above was fairly obvious, then
the following part might be a little on the subtle side. A little though
will give a little understanding... The evaluation of expressions are for
the most part straight forward. #1+1 becomes #2, and so on. But what about
labels? Everytime a label is encountered, it must first go through an
address calcuation before being used in the calculation. The calculation
is LabelAbsolute - CurrentLineAbsolute. Keep in mind that the absolute
addresses start from address 0, with 0 being the first line of the program.
I will show the calculations below... all label address calculations will
be shown in square brackets for emphasis... the absolute line numbers will
be shows at the beginning of each line...
0 dat #1+1 ; 1+1 = 2 dat #2
1 dat #label-3 ; [3-1]-3 = 2-3 = -1 dat #-1
2 dat #label2-label ; [4-2]-[3-2] = 2-1 = 1 dat #1
3 label spl 666 ; 666 = 666 spl 666
4 label2 jmp label ; [3-4] = -1 jmp -1
I hope all of this was clear enough to understand. This would be a good
thing to include in the standards under "How to write and assembler" section.
If you have any questions... please feel free to ask. When I wrote my
little (actually, kinda got big after awhile) assembler, I had a lot of fun
with it. When ever I get around to releasing my next version of the Deluxe
package, it will be able to run programs from '86 standard, '88 standard,
and the "Experimental standard". I have the assembler doing all of this
now... but now if I would just write the mars executor and finish it all
off...
Scott Adkins
sadkins@ohiou.edu
--
Don't forget to have a good day! Some people never remember this. ------------------------------------------------------------------------------- Scott W. Adkins Internet: sadkins@ohiou.edu
~~~~~~~~~~~~~~~ ak323@cleveland.freenet.edu (Flame me, not the net!) Bitnet: adkins@ouaccvma.bitnet -------------------------------------------------------------------------------
Ohio University of Athens Home of the Great Hocking River
Technical Details
Message-ID:
<1992Sep29.122845.8320@oucsace.cs.ohiou.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!uwm.edu!linac!att!cbnewsc!cbfsb!att-out!oucsboss!oucsace!sadkinsReferences:
<1a5la6INN6pq@agate.berkeley.edu> <92271.215156JAR129@psuvm.psu.edu> <1992Sep29.061348.29540@mnemosyne.cs.du.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!uwm.edu!linac!att!cbnewsc!cbfsb!att-out!oucsboss!oucsace!sadkins From: sadkins@bigbird.cs.ohiou.edu (Scott W. Adkins) Newsgroups: rec.games.corewar Subject: Re: ICWS'88 questions Message-ID: <1992Sep29.122845.8320@oucsace.cs.ohiou.edu> Date: 29 Sep 92 12:28:45 GMT References: <1a5la6INN6pq@agate.berkeley.edu> <92271.215156JAR129@psuvm.psu.edu> <1992Sep29.061348.29540@mnemosyne.cs.du.edu> Sender: usenet@oucsace.cs.ohiou.edu (Network News Poster) Organization: Ohio University CS Dept., Athens Lines: 74