English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 05 May 2021, 13:30   #1
KONEY
OctaMED Music Composer

KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 46
Posts: 537
Differences betweed LEA label,Ax and MOVE.L #label.Ax

Can the 68k gurus cast some light on what are the differences between these two instructions?
cycles saved? some additional action not permitted? compatibility?

Code:
LEA		LABEL,A0
MOVE.L	#LABEL,A0
thanks!
KONEY is offline  
Old 05 May 2021, 13:43   #2
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 999
LEA calculates an effective address... for example.

lea 2(a1,d4.w),a0

has a much different result than

move.l 2(a1,d4.w),a0


but in terms of operation, the 2 examples you provided do practically the same thing
DanScott is offline  
Old 05 May 2021, 13:57   #3
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 47
Posts: 8,073
In addition to what Dan said, if LABEL isn't more than $7fff bytes from the code that points to it, you can do:

Lea Label(pc),a0

Makes code smaller, and quicker still and relocatable.
Galahad/FLT is offline  
Old 05 May 2021, 14:23   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 1,137
Quote:
Originally Posted by KONEY View Post
Can the 68k gurus cast some light on what are the differences between these two instructions?

As far as the outcome goes, there is no difference, result is the same. Actually, it is "MOVEA.L #label,a0" in your example, though the assembler silently fixed this for you. The difference between "MOVEA" and "MOVE" is that the former does not set the condition codes, the latter does.



There is no "MOVE" to address register, but the assembler already spotted this, so no worries.
Thomas Richter is offline  
Old 05 May 2021, 15:25   #5
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 999
and just to add more (complexity)...

movea.w #value,a0 will sign extend to a long..

so after:

movea.w #$8000,a0 = a0.l will contain$ffff8000
DanScott is offline  
Old 05 May 2021, 15:41   #6
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 48
Posts: 4,306
As for timing, i can't tell for sure but normally there should be no difference.
Code has same size, nothing special.

Normally the assembler is able to convert
LEA label,a0
to
LEA label(pc),a0
if optimisation is allowed. It is possible some assemblers can convert MOVEA to LEA but i'd recommend using LEA wherever it is an address.
meynaf is offline  
Old 05 May 2021, 15:52   #7
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 49
Posts: 5,449
when disassembling some code, disassemblers convert LEA ADDRESS to the relevant label, but leave MOVE.L #value as is (because it could be a non-address value)

=> coders from the past please use LEA so we can reverse-engineer more easily
jotd is offline  
Old 05 May 2021, 16:51   #8
saimo
Registered User
saimo's Avatar
 
Join Date: Aug 2010
Location: Italy
Posts: 407
Quote:
Originally Posted by DanScott View Post
and just to add more (complexity)...

movea.w #value,a0 will sign extend to a long..

so after:

movea.w #$8000,a0 = a0.l will contain$ffff8000
Just to add some information...

My memory is fuzzy here, but I'm pretty sure that aeons ago while coding, I found that, at least on 68030 (and maybe also on 68020), movea.w #value,a0 takes as long as movea.l #value,a0. The same goes for lea.w and lea.l. I guess the reason is the sign extension.
This is not mentioned in the manuals (but the MC68030UM manual does mention the 2 extra cycles regarding adda.w and suba.w, though).
To me it's become a given, so I always keep it in mind.
saimo is offline  
Old 05 May 2021, 17:01   #9
roondar
Registered User

 
Join Date: Jul 2015
Location: The Netherlands
Posts: 2,888
For the 68000 I do know that it's indeed the same speed for both move.w/add.w/lea.w/etc to an address register and move.l/add.l/lea.l/etc.

On the topic of LEA, while move.l #<label>,a0 and lea.l <label>,a0 do the same thing, I'd personally prefer the use of LEA. Reason being that move.l can be used for any value, but LEA always refers to an address. In my opinion, this makes it clearer what you're doing in the source code and can help prevent some errors by 'forcing' you to keep track of why you chose to use a certain instruction. It also helps (well, it helps me at any rate) to read code easier when I come back after a longer time.
roondar is offline  
Old 05 May 2021, 17:23   #10
grond
Registered User

 
Join Date: Jun 2015
Location: Germany
Posts: 1,031
Quote:
Originally Posted by saimo View Post
My memory is fuzzy here, but I'm pretty sure that aeons ago while coding, I found that, at least on 68030 (and maybe also on 68020), movea.w #value,a0 takes as long as movea.l #value,a0. The same goes for lea.w and lea.l. I guess the reason is the sign extension.
Are you sure your assembler didn't convert them to PC-relative variants which it then shrunk to the smallest constant offset operand size it could? Then both .w and .l variants would have resulted in the same instruction.
grond is offline  
Old 05 May 2021, 17:33   #11
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,908
LEA.w does not exist. There is just LEA, which is a 32-bit operation.
phx is offline  
Old 05 May 2021, 17:35   #12
saimo
Registered User
saimo's Avatar
 
Join Date: Aug 2010
Location: Italy
Posts: 407
Quote:
Originally Posted by grond View Post
Are you sure your assembler didn't convert them to PC-relative variants which it then shrunk to the smallest constant offset operand size it could? Then both .w and .l variants would have resulted in the same instruction.
To be honest, I made the tests so long ago, that I can't remember. But I'm also sure that the same goes for movea.w Rx,Ax.
Now, I should be doing other things, but curiosity might well push me to make some new tests...
saimo is offline  
Old 05 May 2021, 17:36   #13
saimo
Registered User
saimo's Avatar
 
Join Date: Aug 2010
Location: Italy
Posts: 407
Quote:
Originally Posted by phx View Post
LEA.w does not exist. There is just LEA, which is a 32-bit operation.
True, my bad!
I actually meant lea.l (xxx).w,ay.
saimo is offline  
Old 05 May 2021, 19:37   #14
KONEY
OctaMED Music Composer

KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 46
Posts: 537
Very interesting, thanks to all!
KONEY is offline  
Old 05 May 2021, 19:53   #15
saimo
Registered User
saimo's Avatar
 
Join Date: Aug 2010
Location: Italy
Posts: 407
Well, it turns out that my past tests were broken and/or that my memory totally failed me Apologies to all.
I have made new tests on a standard A1200 and on the same A1200 with an Blizzard 1230-IV turned on - i.e., on a 14 MHz 68020 and on a 50 MHz 68030.

The test were based on this simple loop (which executes 65536 times)...

Code:
   moveq.l #-1,d0
.l <movea/lea instruction>
   dbf     d0,.l
... the instructions were hand-coded, the interrupts were off and the elapsed time was measured with a CIA.

These are the results (times expressed in CIA ticks):

Code:
 instruction                        68020   68030
----------------------------------+-------+-------
 41f8 55      lea.l   $55.w,a0    |  8ccf |  2451
 41f9 55      lea.l   $552019,a0  |  999c |  2b96
 307c 55      movea.w #$55,a0     |  8ccf |  2451
 207c 55 2019 movea.l #$552019,a0 |  999c |  2b96
 3040         movea.w d0,a0       |  6668 |  1d0d
 2040         movea.l d0,a0       |  6668 |  1d0d
In conclusion, unlike I had thought, the sign extension makes no difference for lea and movea. Sorry again.
saimo is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Disk Label Dimensions Methanoid Retrogaming General Discussion 6 20 July 2018 00:59
WB disk or label scans Arnie request.Other 6 03 August 2016 11:34
drive label to device name jotd Coders. System 4 28 December 2015 15:16
Dopus 4 disk label videofx request.Other 2 08 June 2014 02:00
Label Program for Amiga moxavius support.Apps 2 18 February 2012 13:59

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:40.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.09526 seconds with 13 queries