EASy68K
http://www.easy68k.com/EASy68Kforum/

compare signed 16-bit values in address registers
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=8&t=588
Page 1 of 1

Author:  Joerg [ Wed Nov 19, 2008 10:05 am ]
Post subject:  compare signed 16-bit values in address registers

Try this:

START ORG $0400

lea $800a,a0
lea $800a,a1
cmpa a0,a1
beq equal
nop
equal MOVE.B #9,D0
TRAP #15 Halt Simulator

END START

The CMPA sets the carry flag, not the zero flag. The BEQ is not executed. :shock:

START ORG $0400

lea $7fff,a0
lea $7fff,a1
cmpa a0,a1
beq equal
nop
equal
MOVE.B #9,D0
TRAP #15 Halt Simulator

END START

Works as expected. :D

Joerg

Author:  profkelly [ Thu Nov 20, 2008 1:02 am ]
Post subject:  Re: compare signed 16-bit values in address registers

Joerg wrote:
Try this:
START ORG $0400
lea $800a,a0
lea $800a,a1
cmpa a0,a1
beq equal
nop
equal MOVE.B #9,D0
TRAP #15 Halt Simulator

END START

The CMPA sets the carry flag, not the zero flag. The BEQ is not executed. :shock:

Joerg

Strange as it may appear this is the correct behavior. The CMPA instruction sign extends word length source operands. So in your example the actual compare performed is:

$800A - $FFFF800A

Note that only the source operand is sign extended not both.

This should and does set the Carry flag.

Author:  Joerg [ Wed Nov 26, 2008 4:08 pm ]
Post subject: 

Thank you,

it's never to late to learn something new about the 68k i'm afraid.

Joerg

Author:  fulgen [ Tue May 28, 2013 11:40 pm ]
Post subject:  Re: compare signed 16-bit values in address registers

Code:
START   ORG   $0400
 movea   #$800a,a0
 movea   #$800a,a1
 cmpa   a0,a1
 beq   equal
 nop
equal   MOVE.B   #9,D0
 TRAP   #15    Halt Simulator

 END   START


That is because lea is always long size an cmpa (without .size) is by default word size. If you use movea instead lea, it works like you expected

Author:  profkelly [ Wed May 29, 2013 12:34 pm ]
Post subject:  Re: compare signed 16-bit values in address registers

The movea instruction defaults to .w and performs a sign extend when loading the address registers. The move instructions result in $FFFF800A in the address registers. The cmpa instruction compares two negative word values.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/