07 January 2009, 03:18 | #1 |
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 |
07 January 2009, 04:21 | #2 |
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. |
07 January 2009, 09:40 | #3 |
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 |
07 January 2009, 10:12 | #4 |
move.l #$c0ff33,throat
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. |
07 January 2009, 10:14 | #5 |
Mostly Harmless
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,149
|
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.
|
08 January 2009, 07:01 | #6 |
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: ...... |
08 January 2009, 08:18 | #7 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,021
|
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 |
08 January 2009, 18:57 | #8 |
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. |
08 January 2009, 22:34 | #9 |
Mostly Harmless
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,149
|
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. |
09 January 2009, 00:41 | #10 | ||||
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
you do
Quote:
Quote:
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:
Quote:
|
||||
09 January 2009, 05:58 | #11 |
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 Code:
Error relative not allowed at line 4 4 00.0000000A 307C0018 MOVEA.W #FTABLE,A0 Ben Pazolli |
09 January 2009, 19:48 | #12 | |
Registered User
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
|
Quote:
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. |
|
22 January 2009, 01:39 | #13 |
Registered User
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. |
22 January 2009, 13:14 | #14 | |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
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. |
|
22 January 2009, 13:29 | #15 | ||
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Quote:
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 Code:
move.l a0,a1 ; save ptr add.l #TEST-SECTIONSTART,a1 ; calc offset Quote:
|
||
22 January 2009, 17:16 | #16 | |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
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. |
|
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 |
|
|