Newbie Question - How does one make comparison tests on fi..

G

Guest

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

I'm a complete newbie to CoreWar, and I'm having difficulty figuring out how to
accomplish various things in redcode. My current dilemma is how to perform
comparison tests on values. The only way I can think of explaining what I'm
mulling over is to give an example of what I'm trying thus far...

;------------------------------------------------------------------------------

; Setting up the initial values...
v1 : nop 0
v2 : nop 0
v3 : nop 0

init: mov #2 , v1
mov v1 , v2
mov #25 , v3

; Okay, here's the area I'm having trouble with. In this test, I'm *trying* to
; loop until the B-field of v1 holds the square root of 25. I've tried to do
; this by calculating its square (B-field of v2) and then comparing it to the
; B-field of v3 (which, of course, holds my target value). Apparently, I don't
; understand how to set up a >= comparison for the field values in question.
test: mul v1 , v2
jmn stop , (v2 >= v3) ; Attempting the comparison here. It doesn't
; want to work this way.
incr: add #1 , v1
mov v1 , v2
jmp test
stop: dat 0

;------------------------------------------------------------------------------

Hopefully, I've been able to phrase my question so it's understandable. Would
someone be kind enough to lend me their expertise?

TIA,
- BootSector

(No email ATM, so the MadHatter addy is just a dummy value to keep my newsreader
from whining.)
 
G

Guest

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

BootSector wrote:
> I'm a complete newbie to CoreWar, and I'm having difficulty figuring
out how to
> accomplish various things in redcode. My current dilemma is how to
perform
> comparison tests on values. The only way I can think of explaining
what I'm
> mulling over is to give an example of what I'm trying thus far...
>
>
;------------------------------------------------------------------------------
>
> ; Setting up the initial values...
> v1 : nop 0
> v2 : nop 0
> v3 : nop 0
>
> init: mov #2 , v1
> mov v1 , v2
> mov #25 , v3
>
> ; Okay, here's the area I'm having trouble with. In this test, I'm
*trying* to
> ; loop until the B-field of v1 holds the square root of 25. I've
tried to do
> ; this by calculating its square (B-field of v2) and then comparing
it to the
> ; B-field of v3 (which, of course, holds my target value).
Apparently, I don't
> ; understand how to set up a >= comparison for the field values in
question.
> test: mul v1 , v2
> jmn stop , (v2 >= v3) ; Attempting the comparison here. It
doesn't
> ; want to work this way.
> incr: add #1 , v1
> mov v1 , v2
> jmp test
> stop: dat 0

An idea without testing:

init: ...(no change)
test: mul v1, v2
slt v3, v2 ;or slt v2, v3 ...I not so sure.
stop: dat 0
incr: ... (no change)
 
G

Guest

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

Hi BootSector,

On Fri, 15 Apr 2005, BootSector wrote:
[snip problem setting up comparisons]

Ok, looking at the code below, you're mixing the redcode
assembler syntax and actual redcode instructions that get
assembled. Here's a part of your code intermixed
with what actually gets assembled:

> ; Setting up the initial values...
[snip]
> ; Okay, here's the area I'm having trouble with. In this test, I'm *trying* to
> ; loop until the B-field of v1 holds the square root of 25. I've tried to do
> ; this by calculating its square (B-field of v2) and then comparing it to the
> ; B-field of v3 (which, of course, holds my target value). Apparently, I don't
> ; understand how to set up a >= comparison for the field values in question.
> test: mul v1 , v2
> jmn stop , (v2 >= v3) ; Attempting the comparison here. It doesn't
> ; want to work this way.
MUL.F $ -6, $ -5
JMN.B $ 4, $ 0

At the jmn line, the label v2 evaluates to -6 because it's six
cells back from the jmn line, and v3 evaluates to -5 for the same
reson, but (-6 >= -5) is not true, hence 0. So you're telling
the jmn instruction to jump if the b-field of the cell zero cells
away, itself, is not zero, which it is, so it won't. :)

What you want to do can be accomplished with the slt
instruction, which skips ahead an instruction if its a-operand
is less than its b-operand (considered in the range
0..CORESIZE-1.) Replacing the jmn instruction with:

slt v2, v3
jmp stop

> incr: add #1 , v1
[snip... as before]

Cheers,

Joonas
 
G

Guest

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

On Sat, 16 Apr 2005 17:11:36 +0300, M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
wrote:

>Hi BootSector,

Why, hello! Heheh. Please overlook my bad manners in not sending out a "howdy"
to everyone from the get-go; I was trying to get the question done on my way
into work.

>On Fri, 15 Apr 2005, BootSector wrote:
>[snip problem setting up comparisons]
>
>Ok, looking at the code below, you're mixing the redcode
>assembler syntax and actual redcode instructions that get
>assembled. Here's a part of your code intermixed
>with what actually gets assembled:
>
>> ; Setting up the initial values...
>[snip]
>> ; Okay, here's the area I'm having trouble with. In this test, I'm *trying* to
>> ; loop until the B-field of v1 holds the square root of 25. I've tried to do
>> ; this by calculating its square (B-field of v2) and then comparing it to the
>> ; B-field of v3 (which, of course, holds my target value). Apparently, I don't
>> ; understand how to set up a >= comparison for the field values in question.
>> test: mul v1 , v2
>> jmn stop , (v2 >= v3) ; Attempting the comparison here. It doesn't
>> ; want to work this way.
> MUL.F $ -6, $ -5
> JMN.B $ 4, $ 0
>
>At the jmn line, the label v2 evaluates to -6 because it's six
>cells back from the jmn line, and v3 evaluates to -5 for the same
>reson, but (-6 >= -5) is not true, hence 0. So you're telling
>the jmn instruction to jump if the b-field of the cell zero cells
>away, itself, is not zero, which it is, so it won't. :)
>
>What you want to do can be accomplished with the slt
>instruction, which skips ahead an instruction if its a-operand
>is less than its b-operand (considered in the range
>0..CORESIZE-1.) Replacing the jmn instruction with:
>
> slt v2, v3
> jmp stop
>
>> incr: add #1 , v1
>[snip... as before]
>
>Cheers,
>
>Joonas

Ahhh, I see it now. Thanks for explaining the problem with the (v2 >= v3) line.
<Shakes his head in bemusement.> Now that you've pointed it out, it just seems
so obvious an error that I'm wondering how in Hel's realm I overlooked it.

Using the SLT definitely makes sense for the situation, too.

....So then, I guess that brings up another little prickly wonderment: _Is_ there
a way to specifically look at a field's value?

<Chuckles.> Eee-yup. I might not get good enough to send a warrior to any hills
in the near future, but at least the ol' neurons are getting some exercise. :)

- BootSector