While reverse engineering something for fun, I came across the following piece of assembly:
move.b (a1)+,(a0)+
I understand that the parentheses mean 'value of', but what does the plus symbol stand for? How would I accurately translate this to C?
The operand is in memory at the address provided by the value in an address register.
The base address contained in one of the address registers is added to the content of a 16/32-bit register and an 8-bit index. This address mode requires 1 extension word that contains the 8-bit index; only the 8 least significant bits of the extension words are kept and sign-extended to 32-bits before any calculation.
68000 assembly is the assembly language used for the Motorola 68000, or commonly known as the 68K. It should not be confused with the 6800 (which predates it). The Motorola 68000 is a big-endian processor with full 32-bit capabilities (despite most systems that use it being considered 16-bit.)
The parentheses mean indirect addressing and the +
means post-increment. In this case both a1
and a0
will be increased by the size of the operation after the instruction is executed. Another common addressing mode is indirect addressing with pre-decrement, -(An)
.
The typical use for a move
instruction where indirect addressing with post-increment is used for both the source and destination register is to copy data from one memory location to another in a loop.
The Programmer's Reference Manual is invaluable for any M68000 programmer.
In C, *a0++ = *a1++;
for char *a0, *a1
variables. The loop body for a classic simplistic memcpy going only 1 byte at a time. (For larger copies, you'd prefer move.w
or move.l
, or a more optimized memcpy implementation.)
(a1)+
accesses memory at a1
and increments a1
by the size of the operation. In this case 1. What you have looks like a part of a typical loop that copies memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With