[Coco] Any reason to put a 6309 in a Coco2?
William Astle
lost at l-w.net
Fri Jan 2 06:11:03 EST 2004
On Fri, 2 Jan 2004, Roger Taylor wrote:
> At 03:27 PM 1/1/2004 -0700, you wrote:
> >LDA #$4F (machine code: 864F)
> >
> >Suppose that is at $3F00. Now if you jump to $3F01, you actually start at
> >the byte with $4F in it. $4F just happens to be CLRA. The processor has no
> >idea that it's really part of the LDA instruction, nor does it care. And
> >no illegal opcodes are executed.
>
> $4F is the operand, actually. The only "opcodes" that come to mind that
> you can really jump in the middle of, so to speak, is $10xx and $11xx. And
> you're right, some very nice tricks can be achieved to save both time and
> space.
You missed my point actually. $4F happens to also be the opcode for CLRA.
While if happens to be the operand of and LDA instruction rooted at the
previous address doesn't matter. It's still a perfectly legal instruction
should the program counter happen to be pointed to that byte. Thus, if you
have:
3F00: 86
3F01: 4F
3F02: 4D
Pointing a disassembler at 3F00 will give:
3F00: LDA #$4F
3F02: TSTA
Pointing a disassembler at 3F01 will give:
3F01: CLRA
3F02: TSTA
Obviously the above is trivial but it illustrates my point. As far as the
processor is concerned, both instruction streams are perfectly valid;
nothing illegal has been done. Maybe unclear from the perspective of a
human trying to figure it out, but not illegal.
You would normally express the above in a bit more obvious fashion in
source code:
L1 FCB $86 opcode of LDA immediate - this will set A to non-zero
L2 CLRA
TSTA
I will admit it's a nasty trick but it is 2 bytes less than:
L1 LDA #1
BRA L3
L2 CLRA
L3 TSTA
(And it's faster in the L1 case and the same speed in the L2 case.) Yes, I
know that $4F != 1 but if you only need zero/non-zero, either is fine.
--
William Astle
finger lost at l-w.net for further information
Geek Code V3.12: GCS/M/S d- s+:+ !a C++ UL++++$ P++ L+++ !E W++ !N w--- !O
!M PS PE V-- Y+ PGP t+@ 5++ X !R tv+@ b+++@ !DI D? G e++ h+ y?
More information about the Coco
mailing list