[Coco] 6309 Weirdness ??
Robert Gault
robert.gault at worldnet.att.net
Tue May 15 22:04:53 EDT 2007
Darren A. wrote:
> While putting together some new documentation for the 6309 CPU, I came
> across some odd behavior with the new Inter-Register instructions. I was
> wondering if anybody else may have come across this?
>
> All of the new Inter-Register instructions (ADDR, SUBR, ANDR, etc..) are
> 3 bytes in length, but when the PC register is used as either the source
> or destination, the value utilized is the address of the instruction
> plus 4.
>
> So if X contains 0, and the instruction ADDR PC,X were executed at
> address $7F00, you end up with $7F04 in X. However, on the MESS 6309
> CoCo 3 emulator, you end up with $7F03 in X, which is how I assumed the
> instruction should have worked (and I guess the MESS author(s) did too).
>
> Even stranger, if you implement an endless loop using the following
> instructions:
>
> LDX #-4
> ADDR X,PC
>
> ..the loop runs until an IRQ occurs, then when the interrupt routine
> returns, it resumes execution at the address of the ADDR instruction
> minus one, which in this case holds the value $FC (LDD extended). If you
> mask interrupts before executing the loop, it runs forever.
>
> I am wondering if these are bugs in the 6309 which were never fixed.
> When Hitachi decided, for whatever reason, not to reveal the new
> features, perhaps they also abandoned any effort to thoroughly debug them.
>
> Note: I have performed tests in both native and emulation modes and
> there is no difference.
>
> Darren
>
> _________________________________________________________________
> Make every IM count. Download Messenger and join the i’m Initiative now.
> It’s free. http://im.live.com/messenger/im/home/?source=TAGHM_MAY07
>
>
My tests indicate that you are misinterpreting your results.
When I run the program
org $7000
start ldx #$1234
$7003 addr pc,x
$7006 swi
end
the result is that regX contains $1234+$7003+3=$823A. If the program is
changed to addr x,pc there is a problem because the next instruction
after addr pc,x is not swi. To correctly run the new test a program such
as the following is needed.
org $7000
start ldx #1
$7003 addr pc,x
$7006 swi
$7007 swi
end
Now when the program is run, it terminates at $7007=$7003+3+1. That is
exactly what should happen.
Your example LDX #-4 ADDR X,PC will lead to disaster. Using -3, the
program should loop indefinitely at the addr x,pc instruction. But with
-4, the program will jump into the middle of the ldx #-4 instruction.
The result in most cases will be an illegal instruction resulting in the
6309 jumping to a special trap which in most cases will not have a
vector installed.
More information about the Coco
mailing list