Reputation: 48121
Are there any differences between
LEA $1000,A0
and
MOVE #$1000,A0
to put an address in the address registry?
Upvotes: 10
Views: 11508
Reputation: 15924
The motivation of having LEA, instead of only MOVE, is that LEA gives access to the result of the address calculation based on the different addressing modes.
The MOVE #$1000,A0
instruction moves the immediate $1000 into the A0
register, since the immediate indication "#" is used in the mnemonic. The LEA $1000,A0
instruction points to the memory address $1000, and loads this address into the A0
register. In this simple example, the result is the same, and it looks like it is just a matter of some simple syntax with the missing immediate indication "#".
What LEA
actually does may be easier to understand when looking at the difference in:
LEA (A0),A1
and:
MOVE (A0),A1
With LEA (A0),A1
, the A1
register is loaded with the A0
value, like A1 := A0
, where the MOVE (A0),A1
loads the word (default size) value from the memory location in the A0
register, sign extend the value to long (always entire register for address registers) and saves the value in the A1
register.
So LEA
provides the address result from the address calculation before the address is used to actually make a memory access. This is also why there isn't any LEA #<data>
format (addressing mode), since the address of the #<data>
would be in the program space (PC relative), since immediate data is part of the instruction.
The real strength in LEA
is apparent when when more complex addressing modes are used, where it would require significant code to calculate the address otherwise.
So the actual difference on LEA
and MOVE
in the original question can better be illustrated with this illegal code for address register destination (possible for data register destination):
LEA ($1000),A0
and:
MOVE #$1000,A0
This more clearly shows that LEA
provides the address of the indirection, without actually doing the memory access.
Upvotes: 1
Reputation: 10026
When I was learning how to program in assembly language (68k) there was a difference pointed out in regards to this example of LEA
and MOVE.L
when it comes to dealing with Address Registers. In terms of using labels there is definitely a major difference.
Say you have a label Foo
for some DC.*
.
LEA Foo, A0 ;Loads Foo into Address Register A0
MOVE.L #Foo, A0 ;Loads Foo into Address Register A0
The lesson was that under normal conditions, the above two instructions would in fact accomplish the same thing. However, due to "relocatability" in real-life systems, the bottom one can cause problems.
It is safest to just use the LEA
approach. Whether or not there can be an issue when using $1000
- I am not sure on. However, to talk about the difference between this LEA
and MOVE.L
when dealing with Address Registers this is definitely something that has to be considered.
Upvotes: 0
Reputation: 286
Durandal is correct, operations involving an address register have generally no impact on the processor flags, in this particular case the two instructions will behave the same and take the exact same cpu time (8 cycles using short addressing mode or 12 using long mode).
MOVE xx,an is not a real instruction, it's something assemblers allow but if you look at the disassembled result you will see that that the actual instruction is MOVEA.
Upvotes: 5
Reputation: 20059
In this case, there will be no observable difference (unlike the accepted answer claims - the MOVE example will assemble as MOVEA which does not alter the CCR, see M68K Reference Manual Pg 4-116 to 4-120).
Upvotes: 11
Reputation: 30449
The lea
instruction does not affect flags, where the move
instruction does. Specifically Z
and C
will be cleared after the move #$1000,a0
.
Upvotes: 7