English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 12 March 2010, 14:33   #1
Nut
Registered User
 
Join Date: Feb 2010
Location: Helsinki, Finland
Posts: 36
32bit PC-relative LEA ??

I'd like to see beyond 16bit indexing limit, so how to do it?
This is the normal way... it only sees 32k forwards and backwards.

lea data(pc),a0

data: dc.l $0



I think I did it yesterday, or I just thought I did dit it but it was something else, but now I can't remember what it was. Suppose you have 64k of data between those two lines, you ain't seeing "data" anymore. I can think of a hundred bad ways to do it, but in case you know the best way, you could enlighten me. I think I just put .l somewhere...
Nut is offline  
AdSense AdSense  
Old 12 March 2010, 14:39   #2
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by Nut View Post
I'd like to see beyond 16bit indexing limit, so how to do it?
This is the normal way... it only sees 32k forwards and backwards.

lea data(pc),a0

data: dc.l $0

START moveq #0,d0 ; start of your program code, can be any instruction of course

....

lea START(pc),a0
add.l #data-START,a0 ; -> "emulate" lea data(pc),a0

et voilį.
StingRay is offline  
Old 12 March 2010, 15:20   #3
Cosmos
Banned
 
Join Date: Jan 2007
Location: France
Posts: 655
It's "et voilą."
Cosmos is offline  
Old 12 March 2010, 15:32   #4
Nut
Registered User
 
Join Date: Feb 2010
Location: Helsinki, Finland
Posts: 36
Thanks. Modified it a little bit...

here: lea (pc),a0
add.l #data-here,a0

data: dc.l $0

Now it can see also backwards

Fantastique!
Nut is offline  
Old 12 March 2010, 15:38   #5
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by Cosmos View Post
It's "et voilą."
Damn, I'll never learn french.


Quote:
Originally Posted by Nut View Post
Thanks. Modified it a little bit...

here: lea (pc),a0
add.l #data-here,a0

data: dc.l $0

Now it can see also backwards

Fantastique!
Yeah, that works too of course, using START was just an example to give you an idea. If you're lazy you can create a MACRO like this:

Code:
MLEA    MACRO
        lea *+2(pc),\2
        add.l #\1-*+2,\2
        ENDM
which will do it automagically. =)
StingRay is offline  
Old 12 March 2010, 16:56   #6
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,029
Just want to point out that on 68020 and above you have 32-bit PC relative addressing modes available.
Leffmann is offline  
Old 13 March 2010, 01:56   #7
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Leffmann View Post
Just want to point out that on 68020 and above you have 32-bit PC relative addressing modes available.
Yes, but don't use them on the Amiga. They are not needed and slow. It would be faster to use absolute addresses and let the Amiga loader relocate. If there is a free address register and very many accesses then something like the examples above is the best.
matthey is offline  
Old 13 March 2010, 18:03   #8
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,452
Quote:
Originally Posted by StingRay View Post
Code:
MLEA    MACRO
        lea *+2(pc),\2
        add.l #\1-*+2,\2
        ENDM
Good tip That actually works, although I was a bit skeptical about the *+2 references on different instruction addresses

Here's an alternate take that does the same.
Code:
MLEA:     MACRO
.mlea\@:  lea .mlea\@(pc),\2
          add.l #\1-.mlea\@,\2
          ENDM
(Uses the AsmOne counter \@ to create a (numbered) fixed label to use as a base.)
Photon is offline  
Old 15 March 2010, 17:02   #9
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Quote:
Originally Posted by StingRay View Post
Code:
MLEA    MACRO
        lea *+2(pc),\2
        add.l #\1-*+2,\2
        ENDM
An interesting test case, indeed. I'm surprised that most assemblers generate correct code (even my own ones)!
I would not recommend it though.

Quote:
Originally Posted by Photon View Post
(Uses the AsmOne counter \@ to create a (numbered) fixed label to use as a base.)
Isn't \@ more likely taken from Devpac? Or did the original SEKA also support it?
phx is offline  
Old 15 March 2010, 20:17   #10
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by phx View Post
An interesting test case, indeed. I'm surprised that most assemblers generate correct code (even my own ones)!
What's surprising there? * = current PC, *+2 = current PC+2 = lea instruction +2. It works fine and there are no problems with it.

"Cleaner" version would be:

Code:
MLEA    MACRO
        lea *(pc),\2
        add.l #(\1-*)+4,\2
        ENDM
which does the same but might make it more clear what's going on. I avoided labels on purpose because ASM-One has a lot of problems with that when you are using a lot of macros.


Quote:
Originally Posted by phx View Post
I would not recommend it though.
You say you wouldn't recommend it but do not explain why. I am interested as to WHY you would not recommend it because I can't see any reason. The MACRO makes perfect sense and works as intended!

Last edited by StingRay; 15 March 2010 at 20:51. Reason: typo
StingRay is offline  
Old 15 March 2010, 21:20   #11
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Quote:
Originally Posted by StingRay View Post
What's surprising there? * = current PC, *+2 = current PC+2 = lea instruction +2. It works fine and there are no problems with it.

"Cleaner" version would be:

Code:
MLEA    MACRO
        lea *(pc),\2
        add.l #(\1-*)+4,\2
        ENDM
Yes, I had to look closer. On first sight it seemed to me that both *+2 were trying to refer to the same location. And I nearly wanted to believe that inside a macro you have the same address in * all the time.

Quote:
You say you wouldn't recommend it but do not explain why. I am interested as to WHY you would not recommend it because I can't see any reason.
Ok, ok. No reason to get loud.
I personally would avoid the * symbol whenever possible, because it is not implemented the same in all assemblers. As an example, critical cases are short-branches
Code:
    bra.b   *-2
and directives which can be arbitrarily split over several lines
Code:
    dc.l *,*,*,*
different to
Code:
    dc.l *,*
    dc.l *,*
It also makes your source hard to read and hard to maintain. It is a relict from the first assemblers in the 1960s where labels were limited in length and in number. As Photon wrote \@ also works with AsmOne, so there is no reason to use *.
The only case where I have to use * is with assembler-inline code in C sources.
phx is offline  
Old 15 March 2010, 21:32   #12
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by phx View Post
Ok, ok. No reason to get loud.
Using uppercase wasn't meant as shouting, I just wanted to emphasize that I'm really interested in the reason why you wouldn't recommend it.

Quote:
Originally Posted by phx View Post
I personally would avoid the * symbol whenever possible, because it is not implemented the same in all assemblers.
If I want portable code I do not use Assembler so that argument is void, for me at least.


Quote:
Originally Posted by phx View Post
As an example, critical cases are short-branches
Code:
    bra.b   *-2
and directives which can be arbitrarily split over several lines
Code:
    dc.l *,*,*,*
different to
Code:
    dc.l *,*
    dc.l *,*
All true but nothing of that applies to the Macro because there are no branches at all!


Quote:
Originally Posted by phx View Post
It also makes your source hard to read and hard to maintain. It is a relict from the first assemblers in the 1960s where labels were limited in length and in number. As Photon wrote \@ also works with AsmOne, so there is no reason to use *.
How often do you use Asm-One? And for what? I'm sorry but I have to ask this question because it seems I'm using AsmOne a LOT more than you and Asm-One has a lot of problems when you are using lots of macros (as I do in my demosystem) which is why I avoid these generated labels (yes, I of course do know about them, actually my whole demosystem is driven by macros) when they are not really required and in this case they aren't. And I don't see how it makes my sources hard to read because usually you do not care about how a macro works, you're just interested that it works.


Quote:
Originally Posted by phx View Post
The only case where I have to use * is with assembler-inline code in C sources.
How about pc relative jump tables? dc.l *-TAB. There are certainly more reasons to use * than just inline asm in C!
StingRay is offline  
Old 15 March 2010, 22:01   #13
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Don't misunderstand me. My replies were general and not directed to you personally. I didn't want to advise you or even make you change your coding habbits. You just asked why I wouldn't use '*'. And I answered. Just have fun everybody!

You're right about AsmOne. I never used it in my whole life (because of those "problems" ).
phx is offline  
Old 15 March 2010, 22:12   #14
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by phx View Post
Don't misunderstand me. My replies were general and not directed to you personally. I didn't want to advise you or even make you change your coding habbits. You just asked why I wouldn't use '*'. And I answered. Just have fun everybody!
Now I think you misunderstood my reply. I'm always open to a discussion like that because no one knows everything (which is why I asked why you wouldn't recommend it and I told you my reasons why I used it ;D). Discussions like that can be very useful. And no, I didn't understand your reply as "he wants me to change my coding habits" (that's impossible after 20 years anyway :P).

To make it a bit more clear, I'd f.e. never use bra.b *+2 in a macro for the reasons you mentioned, branch distance can change and then all hell breakes loose. However, in the case of the "PC relative lea" macro there are no problems like that because it consists of just 2 instructions of fixed length that can never(!) change. Which is why I don't see it as a problem to use the "*" symbol there.


Quote:
Originally Posted by phx View Post
You're right about AsmOne. I never used it in my whole life (because of those "problems" ).
I never found a better alternative so despite the lot of problems Asm1 definitely has, it's still the best choice for me. =)
StingRay is offline  
Old 15 March 2010, 23:42   #15
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Quote:
Originally Posted by StingRay View Post
no, I didn't understand your reply as "he wants me to change my coding habits" (that's impossible after 20 years anyway :P).
Then we have probably both seen a lot in our lifes. It's 27 years assembler coding here.

Quote:
However, in the case of the "PC relative lea" macro there are no problems like that because it consists of just 2 instructions of fixed length that can never(!) change. Which is why I don't see it as a problem to use the "*" symbol there.
When using AsmOne with the mentioned problems in mind you are certainly right in this case. But that doesn't mean I would recommend it with Devpac, for example. I was trying to make a general statement for all assemblers and all code situations.
And there might be also some special cases where * is just easier. You mentioned one form of jump table. But there are several kinds of jump tables.


Quote:
I never found a better alternative so despite the lot of problems Asm1 definitely has, it's still the best choice for me. =)
You cannot get me to any statement about which assembler to prefer. It makes no sense as I'm probably biased as being the author of two Amiga assemblers.
It heavily depends on personal taste, how you are used to work and in which environment you want to do it.
phx is offline  
Old 16 March 2010, 00:14   #16
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,452
Ah, but then you won't have us believe that your first choices aren't phxAss and... (help me out here?)



Welcome to EAB and Coder's Heaven anyway, good to see another umm oldtimer (/me ducks)
Photon is offline  
Old 16 March 2010, 05:09   #17
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Photon View Post
Ah, but then you won't have us believe that your first choices aren't phxAss and...
vasm

Everyone remembers PhxAss though. Maybe the name wasn't so bad after all . Vasm is getting very good. It's worth while to switch from PhxAss as it's more forgiving and has less bugs. No one should be using Devpac as vasm has a Devpac compatibility mode, more options and more optimizations. Vasm can optimize branches both forward and backward for example. AsmOne still makes sense as it has some features vasm never will. You have to live with the bugs and lack of support though. Ced with ARexx, and BDebug make a pretty potent programming combo. I think many 68k assembly programmers are set in their ways and don't try new things so they miss gems like vasm. It took me a long time to switch but I'm glad I did.
matthey is offline  
Old 16 March 2010, 12:35   #18
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Quote:
Originally Posted by Photon View Post
Welcome to EAB and Coder's Heaven anyway, good to see another umm oldtimer (/me ducks)
Thanks! Seems I'm even an older oldtimer than you are (by 2 years).
phx is offline  
Old 16 March 2010, 13:39   #19
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
Quote:
Originally Posted by phx View Post
But that doesn't mean I would recommend it with Devpac, for example.
Most of the assemblers I know support "*" as symbol for current PC so I don't really see a problem. And coming back to the portability, one assembler might expect \@ while another one uses a different syntax for these generated labels. So you will have to adapt the macro anyway if you want to use it with a different assembler.

Quote:
Originally Posted by phx View Post
And there might be also some special cases where * is just easier. You mentioned one form of jump table. But there are several kinds of jump tables.
I was merely pointing out the fact that using "*" does have its uses, even nowadays. Of course there are lots of different approaches to do jump tables but that was not the point.



Quote:
Originally Posted by phx View Post
You cannot get me to any statement about which assembler to prefer. It makes no sense as I'm probably biased as being the author of two Amiga assemblers.
It heavily depends on personal taste, how you are used to work and in which environment you want to do it.
You could f.e. tell me to use vasm and I'd still use Asm1 because as you say it depends on personal taste. So far I didn't find any other package with shorter turnaround times than Asm1 so despite its bugs it allows me to do the things I want to do in the shortest time.
StingRay is offline  
Old 18 March 2010, 02:37   #20
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,452
Quote:
Originally Posted by phx View Post
Thanks! Seems I'm even an older oldtimer than you are (by 2 years).
Argh, it was meant as a hidden insult. Argh, fail

Yeah, I've certainly never coded a 68K assembler, that's for sure. I've made my own bugfixed version of AsmOne 1.02, with Promax's help, and I've made a C-64 crossassembler (with parallel cable transfer) monstrosity using macros in AsmOne, but certainly not a real assembler for Amiga. Props.

I did code a Z80 assembler on PC though, with the sole purpose of coding a little MSX-cartridge Pong game The cartridge EPROM did work and I was very proud... for about a day or two and then, you know, lose interest and onto the next project This was way after MSX was popular, as nothing but nostalgia would have made me do all that work

My first steps in coding assembler was when I was 11, on the Acorn Atom and Apple-II. But it was not until I was 13 or so that it was anything more than 'modified typed-in sources from magazines'. If you know what I mean. All those home computer brands, one more exciting than the other! Good times
Photon is offline  
AdSense AdSense  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
question on resourcing relative addressing ara Coders. Asm / Hardware 5 05 February 2012 00:42
Trying to have portable configuration, relative paths relative to C:\Public\... ? Turrican support.WinUAE 3 24 June 2011 17:33
Relative paths (WAS: Has anybody ever gotten Shiftrix to work?) rsn8887 support.WinUAE 9 27 August 2010 07:56
adda / suba Vs. lea pmc Coders. General 19 04 June 2010 18:28
Relative paths Toni Wilen request.UAE Wishlist 0 16 August 2009 17:06

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 21:35.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.56722 seconds with 12 queries