🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.corewar
Article #188

Re: ICWS'88 questions

#188
From: Jeff Raven
Date: Tue, 29 Sep 1992 13:03
50 lines
2216 bytes
[Let me introduce a little line numbering to make things easier.]

>01      alpha   equ     1+1
>02      beta    equ     label-3
>03      gamma   equ     label2-label

>04              dat     #alpha
>05              dat     #beta
>06              dat     #gamma
>07      label   spl     666
>08      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?"

Simply put - it doesn't. There's no need to. The reason for this
is more or less because a redcode EQUate is the same thing as a
#define in C - the value to the right of the equate is just
substituted for the label whereever it appears. Now, in the case
above, this means that lines would look like this :

04           DAT #1+1
05           DAT #label - 3
06           DAT #label2 - label
07 label     SPL 666
08 label2    JMP label

This would be done in a sort of "pre-processing" pass. Then,
on the next pass, the equations would be evaluated - using all
relative addresses.

04           DAT #2
05           DAT #2 - 3 ---->  DAT #-1
06           DAT #2 - 1 ---->  DAT #1
07 label     SPL 666
08 label2    JMP -1

Which gives the exact same code you were looking for.
(Without having to muck around with relative + relative
is relative, relative - relative is absolute, ....)

I hope that answers your question. Feel free to ask any more.

Jeff Raven
jar129@psuvm.psu.edu
Technical Details
Message-ID: <92273.090300JAR129@psuvm.psu.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!psuvax1!psuvm!jar129
References: <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!gatech!psuvax1!psuvm!jar129
Organization: Penn State University
Date: Tue, 29 Sep 1992 09:03:00 EDT
From: Jeff Raven <JAR129@psuvm.psu.edu>
Message-ID: <92273.090300JAR129@psuvm.psu.edu>
Newsgroups: rec.games.corewar
Subject: Re: ICWS'88 questions
References: <1a5la6INN6pq@agate.berkeley.edu>
 <92271.215156JAR129@psuvm.psu.edu>
 <1992Sep29.061348.29540@mnemosyne.cs.du.edu>
Lines: 50