Predecrement or how to make one ditzy

G

Guest

Guest
Archived from groups: rec.games.corewar (More info?)

As you know, I'm working on my Corewars interpreter. ICWS88 for the
beginning. I have had the standard paper in front of me for the whole
weekend and still I'm confused.
Predecrement in particular. As far as I get it, it works like this:
I read the value of the operand, add it with the programmcounter, read
the resulting memory location, take the value of the B operand of this
memory location and store this value. Then I decrement this value and
write it back to the memory location where I took it from. Now I
calculate the memory loaction where this offset is pointing at. Do I
now add the programmcounter or the adress of the memory location where
I got it from to this offset?
Example: I want to execute L1
L1 mov 0 <1
L2 DAT 0 2
L3 DAT 0 0
L4 DAT 0 0

First I evaluate the A operand of L1, which brings me mov L1 <1. I note
this down (because of In-Register evaluation).
Second I evaluate the B operand of L1, which makes me read the B
operand of L2. I do note 2 for further use and store DAT 0 1 at L2.

Now the question. Do I add the 2 to L1 or L2?
If to L1 I'll get
L1 mov 0 <1
L2 DAT 0 1
L3 mov 0 <1
L4 DAT 0 0
or if to L2 I'll get
L1 mov 0 <1
L2 DAT 0 1
L3 DAT 0 0
L4 mov 0 <1

>From the description of predecrement in the standard paper I would
think L2.
As of the "Effective Address Calculations" in the same paper, L1 would
be right.
As of the FAQ Chapter 17, L1 should be the right thing to do.
As of the ICWS94 paper chapter 5.3.4 Predecrement Indirect, L2 is
choosen.
As of "The beginners guide to Redcode v1.21", L2 is choosen BUT here
the decrementation is done BEFORE the note down of the value and so I
would add a 0 to the L2
(http://vyznev.net/corewar/guide.html#start_modes).

As a democrat I guess L2 is right because it stands 4:2, but as a
comupter scientist I can't stand democratic decisions as a base of
logic branches.

Hope you can help me, because even the search in the Usegroup archives
didn't give me a clue.
 
G

Guest

Guest
Archived from groups: rec.games.corewar (More info?)

Marnem <corewars@marnem.de> kirjoitti 21.08.2005:
> Predecrement in particular. As far as I get it, it works like this:
> I read the value of the operand, add it with the programmcounter, read
> the resulting memory location, take the value of the B operand of this
> memory location and store this value. Then I decrement this value and
> write it back to the memory location where I took it from. Now I

No, that would be POSTdecrement, which redcode doesn't have. There
are only predecrement (subtract one before use) and postincrement (add
one after use) addressing modes.

I think that's probably what's been confusing you.


> Example: I want to execute L1
> L1 mov 0 <1
> L2 DAT 0 2
> L3 DAT 0 0
> L4 DAT 0 0
[snip]
> Now the question. Do I add the 2 to L1 or L2?

You don't add 2 to anything. You first decrement it so it becomes 1,
and then you add that 1 to the address L2 to get L3.


> As of "The beginners guide to Redcode v1.21", L2 is choosen BUT here
> the decrementation is done BEFORE the note down of the value and so I
> would add a 0 to the L2
> (http://vyznev.net/corewar/guide.html#start_modes).

I assume you meant to type "add a 1 to the L2".

Yes, that's what I wrote there, and I stand by my words. :) But you
don't have to trust me; just grab an existing MARS and try it. (Both
pMARS and CoreWin are good, but anything that implements predecrement,
even the ICWS'94-draft reference code if you like, should work.)

--
Ilmari Karonen
To reply by e-mail, please replace ".invalid" with ".net" in address.

"My father used to claim that he heard god on numerous occasions. He
would ask god questions and keep a record of the answers, and at the end
of the year he would do a chi-square analysis to find out whether god had
been right more often than chance would lead one to expect." -- Pat Bowne