Search code examples
assemblyaddressing-mode68000

M68K: predecrement on the same register


In M68040 asm, given:

mov.l #0x1000, %a0
mov.l -(%a0), -(%a0)

What is the %a0 value after the second mov? Is the register decremented twice or once?

What instead of mov.l we use one of the few other instructions that support pre-decrement/post-increment on both source and destination?

The MC68040 UM states that move16 (%an)+, (%an)+ performs only a single increment, but I could not find any information regarding the general case.

I am working on an emulator and do not have an actual CPU. Also, the general consensus online seems to be that Easy68k is not trustworthy when dealing with this kind of corner case.


Solution

  • In your specific example,

      move.w -(an),-(an)
    

    the register an is indeed decremented twice (so, after the instruction, it is decremented by 4 - or, in your .l example, by 8) on a real 68000 CPU. The instruction effectively moves memory contents downwards by a word length (verified on real hardware).

    move16 is an entirely different beast and only available on the 68040 up. I suppose the specific behavior of the move16 instruction is caused by the 68040 caching mechanisms.