View Single Post
Old 31st May 2019, 9:39 pm   #10
NealCrook
Tetrode
 
Join Date: May 2019
Location: Reading, Berkshire, UK.
Posts: 51
Default Re: Fun with 6502 Assembler

Hi Tony,

>> The 6809 had 'long branch' instructions which were 3 bytes long

The long branch instructions are an 0x10 prefix on the branch instructions: so branch is 1 byte op + 1 byte operand (2 bytes total) and the long branch is 2 bytes op + 2 bytes operand (4 bytes total).

There is a common idiom in the 6809 NitrOS-9 code of using $8C to achieve exactly the effect that you describe, though:

Code:
              ldb   #E$MNF       get error code (module not found)
              fcb   $8C          skip 2 bytes

L070B    ldb   #E$BNam      get error code
8c is "CMPX" so it uses the next 2 bytes as an address, and sets the flags appropriately. It saves 1 byte compared with a bra, at a cost of messing with the flags and doing a "random" memory read.

I had always regarded that as quite a nice trick but describing it now, I think about the 6809's memory-mapped I/O and how you could write code that might end up reading at an address that has read side-effects (eg, a UART) and I shudder...

I am happy to admire 6502 coding wonder, but I cannot contribute any of my own,

Neal.
NealCrook is offline