Home > Blockchain >  Motorola 68000 assembler syntax for Program Counter Indirect with Index
Motorola 68000 assembler syntax for Program Counter Indirect with Index

Time:03-02

I've been putting together my own disassembler for Sega Mega Drive ROMs, basing my initial work on the MOTOROLA M68000 FAMILY Programmer’s Reference Manual. Having disassembled a considerable chunk of the ROM, I've attempted to reassemble this disassembled output, using VASM as it can accept the Motorola assembly syntax, using its mot syntax module.

Now, for the vast majority of the reassembly, this has worked well, however there is one wrinkle with operations that have effective addresses defined by the "Program Counter Indirect with Index (8-Bit Displacement) Mode". Given that I'm only now learning Motorola 68000 assembly, I wanted to confirm my understanding and to ask: what is the proper syntax for these operations?

Interpretation

For example, if I have two words:

4ebb 0004

I've interpreted this as a JSR with the target destination being the sum of:

  • the contents of pc
  • 0x04
  • the contents of d0

(Given that I am restricting myself to the 68000, I've elided any consideration of size and scale in the extension word). Based on how this addressing mode is described in the reference manual, I've emitted this as:

jsr ($04,pc,d0)

Assembling with VASM

However, when I feed this back into VASM it will emit the following error:

error 2030 in line X of "XXXX.asm": displacement out of range
>  jsr ($04,pc,d0)

which seems a very strange error to emit, given that the displacement can't be known until runtime, due to the use of the d0 register. Playing around with this, it appears to use the first part of the operand ($04) as the absolute target destination, and calculates a different displacement based on that.

Assembling with GNU as

If I switch to GNU as, the syntax that provides identical output to the original ROM is:

jsr %pc@(0x04,           
  • Related