English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 07 January 2009, 03:18   #1
bpazolli
 
Posts: n/a
Simple Question

Can you use absolute addressing in assembly on an Amiga 500? I assume with an operating system this would be difficult, so do you just do everthing relative to the starting address of the program? Such as placing labels throughout your program and referring to them with offsets. Or can you just go ahead and use org command? If so at what addresses would be acceptable on an amiga 500 with 1mb of ram running workbench 1.3?

Ben Pazolli
 
Old 07 January 2009, 04:21   #2
Redwood
Registered User
 
Join Date: Jun 2008
Location: Sydney / Australia
Posts: 83
What exactly are you trying to do?

If I understand correctly, the assembler should automatically convert labels to relative addresses, so the only time you should need to use an absolute address is if you want to reference one of the hardware registers.
Redwood is offline  
Old 07 January 2009, 09:40   #3
bpazolli
 
Posts: n/a
Redwood wrote:
> What exactly are you trying to do?

What I am doing is using a book that talks about general 68000 assembly language to learn the very basics of 68000 assembly language on the amiga. This book suggests that you place all your data used by your program at memory address $6000 and the actual program at $7000 (or something like that). I am wondering if I could do this considering that the amiga has an operating system and other stuff and probably doesn't like every program placing stuff wherever it feels like.

I just wanted to confirm that I would have to design my program in a way that if it was loaded anywhere it would be able to run (i.e. not use absolute address). From your answer it would seem to be that your suggesting this is the case as I expected.

Thank You,
Ben Pazolli
 
Old 07 January 2009, 10:12   #4
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
using absolute addresses on amiga is possible, a lot of old demos used that. however, it's not really good habit to do so because of the reasons you already suspected (operating system will be trashed etc.). also, it's absolutely NOT necessary to use absolute addressing at all, you can do all using either SECTIONS or allocating your memory. Often absolute addresses were used for speed reasons (having screens/buffers aligned to a 64k boundary makes some neat tricks possible), however, even that can be "emulated" with "clean" coding.

Last edited by StingRay; 07 January 2009 at 10:18.
StingRay is offline  
Old 07 January 2009, 10:14   #5
girv
Mostly Harmless
 
girv's Avatar
 
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
Under AmigaOS you can't safely use absolute addresses as you describe, bpazolli. You have no idea at which memory address your program will be loaded or at which address other programs or OS data structures are located.
girv is offline  
Old 08 January 2009, 07:01   #6
bpazolli
 
Posts: n/a
Can someone please tell me how I would solve this problem with relative address. I want to place the address of a label in an address register, but I keep getting an error. For example I have,
Code:
        MOVEA.W     #FTABLE,A0
...
FTABLE: ......
 
Old 08 January 2009, 08:18   #7
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,993
An address is 32 bit (long), not 16 bit (word). So it should be movea.l, not .w. You are probably reading a book about an embedded system with few memory and small addresses.

Another possible instruction is lea:

lea.l ftable, a0

or really (pc-)relative:

lea.l ftable(pc),a0
thomas is online now  
Old 08 January 2009, 18:57   #8
Ed Cruse
Registered User
 
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
Maybe I'm missing something here, but you can use absolute addressing all you want with the Amiga OS. You shouldn't use specific addresseses unless you are talking to the hardware registers. The following lines of code work perfectly fine anywhere in memory.

movea.l #addlabel,a0 also lea addlabel,a0.

Assemblers and compilers generate offset-tables which the loader uses to relocate the code and data sections in your program, regardless of where they get loaded into memory. You should however always use absolute addressing when referencing a label in another section, the sections can be loaded anywhere in memory with respect to each other, therefore they can be out of 16bit range from each other.

In other words, if you want to use absolute addressing, do it and don't worry about it.
Ed Cruse is offline  
Old 08 January 2009, 22:34   #9
girv
Mostly Harmless
 
girv's Avatar
 
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
Ed you're right about using 68k absolute addressing mode, but I believe bpazolli was talking about using specific addresses for code and data. Or he was at first anyway.

bpazolli, your code in post #6 is fine when assembled with any AmigaOS assembler (maybe apart from the .w size on the movea). As Ed explained, the assembler will use offset tables and other things to automagically relocate your code to whichever address the OS decides to load it to.

It's only when you start saying things like "movea.l #$60000,a0" where you're using hardcoded, numerical addresses (not labels within your own program) that you will run into problems.
girv is offline  
Old 09 January 2009, 00:41   #10
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Ed Cruse View Post
Maybe I'm missing something here
you do

Quote:
but you can use absolute addressing all you want with the Amiga OS. You shouldn't use specific addresseses unless you are talking to the hardware registers. The following lines of code work perfectly fine anywhere in memory.

movea.l #addlabel,a0 also lea addlabel,a0.
while that code is of course perfectly ok, it's not what the thread opener asked about:
Quote:
Originally Posted by bpazolli
This book suggests that you place all your data used by your program at memory address $6000 and the actual program at $7000 (or something like that).
He asked if it is ok to use absolute (or fixed) addresses and something like
lea $7000.w,a0 WON'T be converted to an offset when you use org/load directives, i.e. assemble your program to fixed memory locations!

Quote:
You should however always use absolute addressing when referencing a label in another section, the sections can be loaded anywhere in memory with respect to each other, therefore they can be out of 16bit range from each other.
That's not quite correct either, it is perfectly possible to reach offsets larger than 16 bit (e.g. a different SECTION) WITHOUT using absolute addressing. There's actually NO reason to have any RELOC32 entry in any program. So saying that you should always use absolute addressing when you need to access a label in another section is simply wrong.

Quote:
In other words, if you want to use absolute addressing, do it and don't worry about it.
While there's nothing wrong with it, there ARE reasons why you need to worry about it (sometimes size DOES matter, you know ;D) I for myself HATE non-relocatable code and try to avoid it whenever I can.
StingRay is offline  
Old 09 January 2009, 05:58   #11
bpazolli
 
Posts: n/a
The person saying it should be MOVEA.L #FTABLE,A0 rather than MOVEA.W #FTABLE,A0 was right. I was trying to assemble this code below in Devpac2.

Code:
PROG:   CLR.W  D0
        MOVE.B  VALUE,D0
        ADD.B   D0,D0
        MOVEA.W #FTABLE,A0
        MOVE.W  0(A0,D0),RESULT
 
        RTS
 
FTABLE: DC      1
        DC      1
        DC      2
        DC      6
        DC      24
        DC      120
        DC      720
        DC      5040
 
VALUE:  DS.B    1
        DS.B    1
RESULT: DS.W    1
 
        END     PGM_4_8A
When I try to assemble this I get this error

Code:
Error relative not allowed at line 4
    4 00.0000000A 307C0018                       MOVEA.W #FTABLE,A0
And I interpreted that as having some trouble with FTABLE address being relative to where the program is deployed. It's not entirely my fault though, I was using a book and it specified MOVEA.W #FTABLE,A0. The book isn't specific to the Amiga so I don't know if this is a typo or just for systems that use 16bit addressing.

Ben Pazolli
 
Old 09 January 2009, 19:48   #12
Ed Cruse
Registered User
 
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
Quote:
Originally Posted by StingRay View Post
you do



while that code is of course perfectly ok, it's not what the thread opener asked about:


He asked if it is ok to use absolute (or fixed) addresses and something like
lea $7000.w,a0 WON'T be converted to an offset when you use org/load directives, i.e. assemble your program to fixed memory locations!



That's not quite correct either, it is perfectly possible to reach offsets larger than 16 bit (e.g. a different SECTION) WITHOUT using absolute addressing. There's actually NO reason to have any RELOC32 entry in any program. So saying that you should always use absolute addressing when you need to access a label in another section is simply wrong.



While there's nothing wrong with it, there ARE reasons why you need to worry about it (sometimes size DOES matter, you know ;D) I for myself HATE non-relocatable code and try to avoid it whenever I can.
OK, I have to ask a stupid question. How do you reference to other sections with relative addressing, I may know but right now it don't. I can see doing multiple relative jumps, but you don't know how many. Seems like my C compiler will insert an absolute jump in a situation like that. I suppose I could follow the linking from section to section and get the pointer of the section of interest. I'm actuall interested in knowing, something new to learn.

I'm sorry if I didn't pick my words really well. You're absolutely right, for small fast code absolute addressing is not the way to go, but for situation where you're not to concerned, it's not something to worry about. I will try and pick my words better next time.

Last edited by Ed Cruse; 09 January 2009 at 19:58.
Ed Cruse is offline  
Old 22 January 2009, 01:39   #13
Ray Norrish
Registered User
 
Ray Norrish's Avatar
 
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
I skipped over some stuff, but I think I know what the op means.

He may be talking about PC code, where you can sacrifice an address register as a reference to the start of the executable (or thereabouts)

So..

lea base_label(pc),a6

thereby -depending on compiler- reference other statics as #myvar-a6 or some such.. (I'd have to consult some old code to confirm) but making you code PC or reloc compatible.

Of course addressing MOVEA.W #FTABLE,A0 is ludicrous, as this would only work if #ftable was resident in <64K memory.

I prefer to refer to a label with LEA FTABLE(pc),A0 although move.l #FTABLE,A0 will do.

If PC code is desired, then using the above method (something like LEA FTABLE-a6(pc),a0) would ensure reloc code.

You are able to compile your code without org instructions and use a variety of tools to reloc the code, however you don`t usually need to do this unless you are coding multiple sets of code or relying on a loader to position code etc..

I remember that (pc) only works within a word range? and I used to have countless arguments with fellow coders regarding "pc" coding styles.. but .. if you use the PC register, you can code independant code that can be loaded to any location, although for trackmos / independant loading of code, you can "org" your code and load it there - it will be fine.

Last edited by Ray Norrish; 22 January 2009 at 01:46.
Ray Norrish is offline  
Old 22 January 2009, 13:14   #14
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Quote:
Originally Posted by Ray Norrish View Post
I remember that (pc) only works within a word range? and I used to have countless arguments with fellow coders regarding "pc" coding styles.. but .. if you use the PC register, you can code independant code that can be loaded to any location, although for trackmos / independant loading of code, you can "org" your code and load it there - it will be fine.
On the 68020 and above you can use the extended addressing modes to achieve a PC-relative address with a 32 bit offset if needed.

The automatic code relocation feature in the AmigaOS is very comfortable and to me it doesn't make sense to go to lengths to avoid comfortable features.

If you can use a PC-relative address that's just great, and you should, but f.ex I would never write PC-relative LEA-MOVE constructs to get around single instances of not being able to use a PC-relative address as destination, but rather just take the absolute move with a reloc entry and let the AmigaOS do the work for me.
Leffmann is offline  
Old 22 January 2009, 13:29   #15
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Ed Cruse View Post
OK, I have to ask a stupid question. How do you reference to other sections with relative addressing, I may know but right now it don't. I can see doing multiple relative jumps, but you don't know how many. Seems like my C compiler will insert an absolute jump in a situation like that. I suppose I could follow the linking from section to section and get the pointer of the section of interest. I'm actuall interested in knowing, something new to learn.

To reach offsets in different sections you'll need to get a pointer to the hunk in question (each section adds one hunk) and access the data relative to this pointer. AmigaDOS places a BCPL pointer to the next hunk right in front of the first long of the hunk. To get the actual address you need to multiply the BCPL offset with 4 and add 4 (to skip the long containing the BCPL ptr). Here's some code to do just that:
Code:
START
    move.l    START-4(pc),d0        ; get ptr to hunk
    lsl.l   #2,d0                ; convert to standard pointer
    addq.l  #4,d0               ; skip the long
    move.l    d0,a0                ; a0 -> ptr you can use
So if you for example want to access label "TEST" in that very section you could do something like this:
Code:
    move.l    a0,a1                    ; save ptr
    add.l    #TEST-SECTIONSTART,a1    ; calc offset
result: 100% relocatable code!

Quote:
Originally Posted by Leffmann View Post
If you can use a PC-relative address that's just great, and you should, but f.ex I would never write PC-relative LEA-MOVE constructs to get around single instances of not being able to use a PC-relative address as destination, but rather just take the absolute move with a reloc entry and let the AmigaOS do the work for me.
But what if you NEED 100% relocatable (for whatever reason) code? It is also relevant when doing size optimized code! Also, it's not hard to do something like this with some nifty MACROS.
StingRay is offline  
Old 22 January 2009, 17:16   #16
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Quote:
Originally Posted by StingRay View Post
But what if you NEED 100% relocatable (for whatever reason) code? It is also relevant when doing size optimized code! Also, it's not hard to do something like this with some nifty MACROS.

Absolutely, if you're into 4K intro coding then you should use every trick you can to shave off bytes here and there I like how some assemblers will optimize immediate 32 bit moves into a moveq-shift or similar just to save 2 bytes, pretty neat.
Leffmann 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
Simple KVM switcher question. Thorham support.Hardware 3 25 December 2010 21:18
Simple 14 bit audio question... Thorham Coders. General 7 06 June 2010 10:55
Simple circuit design question: Charlie Hardware mods 13 12 February 2010 10:43
Simple question Raffaz New to Emulation or Amiga scene 2 10 July 2007 14:08
Simple A1200 Question Methanoid support.Hardware 4 29 April 2005 00:34

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 23:48.

Top

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