English Amiga Board


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

 
 
Thread Tools
Old 06 May 2016, 22:54   #1
Beska
Registered User
 
Join Date: Apr 2014
Location: Calgary/Canada
Posts: 26
Calculate offset using labels

First off let me say I have no idea what I am doing. I'm just starting to figure out 68k assembly. Now that thats out of the way... I'm working on some code that as part of its operation, relocates itself and then continues on using an offset address. This code was originally written for Macro68 but I'm using DevPac 3.
The part where I'm struggling is where the program relocates itself and then jumps to the new address which is calculated as an offset of the new memory block.

The code in question looks like:

; a3 is a pointer to the newly allocated block of memory
donewithreloc:
jmp (newaddress,a3) ;execute from now on from the allocated
;memory space
newaddress:
;Allocate four 220K chunks of memory for the big buffer
moveq #$16,d4
rol.l #8,d4 ;512*11 trackdisk buffer
lea (RamPtr+FastBoot,pc),a4
movea.l a4,a3
When this is assembled in DevPac I get an error "Relative not allowed" at the jmp.

So my question is, Is there another way to calculate this offset in DevPac without getting the "Relative not allowed" error? I am pretty sure there must be a way to do this but since I'm not experienced in 68k assembly I have to turn to more knowledgable folk.
Beska is offline  
Old 06 May 2016, 23:00   #2
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Quote:
Originally Posted by Beska View Post
First off let me say I have no idea what I am doing. I'm just starting to figure out 68k assembly. Now that thats out of the way... I'm working on some code that as part of its operation, relocates itself and then continues on using an offset address. This code was originally written for Macro68 but I'm using DevPac 3.
The part where I'm struggling is where the program relocates itself and then jumps to the new address which is calculated as an offset of the new memory block.

The code in question looks like:

; a3 is a pointer to the newly allocated block of memory
donewithreloc:
jmp (newaddress,a3) ;execute from now on from the allocated
;memory space
newaddress:
;Allocate four 220K chunks of memory for the big buffer
moveq #$16,d4
rol.l #8,d4 ;512*11 trackdisk buffer
lea (RamPtr+FastBoot,pc),a4
movea.l a4,a3
When this is assembled in DevPac I get an error "Relative not allowed" at the jmp.

So my question is, Is there another way to calculate this offset in DevPac without getting the "Relative not allowed" error? I am pretty sure there must be a way to do this but since I'm not experienced in 68k assembly I have to turn to more knowledgable folk.
When using PC relative code, 220k offset is too big, max size for PC relative offsetting is $7fff
Galahad/FLT is offline  
Old 06 May 2016, 23:35   #3
Beska
Registered User
 
Join Date: Apr 2014
Location: Calgary/Canada
Posts: 26
The offset will be significantly smaller than 220k, just enough to jump over the initial copy code.
Beska is offline  
Old 06 May 2016, 23:59   #4
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,958
Quote:
Originally Posted by Beska View Post
First off let me say I have no idea what I am doing. I'm just starting to figure out 68k assembly. Now that thats out of the way... I'm working on some code that as part of its operation, relocates itself and then continues on using an offset address. This code was originally written for Macro68 but I'm using DevPac 3.
The part where I'm struggling is where the program relocates itself and then jumps to the new address which is calculated as an offset of the new memory block.

The code in question looks like:

; a3 is a pointer to the newly allocated block of memory
donewithreloc:
jmp (newaddress,a3) ;execute from now on from the allocated
;memory space
newaddress:
;Allocate four 220K chunks of memory for the big buffer
moveq #$16,d4
rol.l #8,d4 ;512*11 trackdisk buffer
lea (RamPtr+FastBoot,pc),a4
movea.l a4,a3
When this is assembled in DevPac I get an error "Relative not allowed" at the jmp.

So my question is, Is there another way to calculate this offset in DevPac without getting the "Relative not allowed" error? I am pretty sure there must be a way to do this but since I'm not experienced in 68k assembly I have to turn to more knowledgable folk.
Use:
lea (RamPtr+FastBoot),a4
Don_Adan is offline  
Old 07 May 2016, 01:02   #5
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
It's not surprising that Devpac doesn't like the "jmp (newaddress,a3)".
"newaddress" is a label, so it cannot be used as 16-bit displacement on A3.

But I'm not sure if I, or anybody else here, understood what you are trying to do. Am I correct that you want to relocate the code below "newaddress", and you already copied it to a new memory region with its base address stored in A3? Then you only have to jump to this address: "jmp (a3)". :
phx is offline  
Old 08 May 2016, 08:30   #6
Beska
Registered User
 
Join Date: Apr 2014
Location: Calgary/Canada
Posts: 26
yes, newaddress is where I want to jump to at a3. The code starting at a3 will have the relocation code. Once that has executed I don't need to execute it again so I want to skip over it.
Beska is offline  
Old 08 May 2016, 10:38   #7
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
You have to compute the offset with
jmp (start-orig, a3)
, but I would just do as phx suggested and not move the relocation code at all.
Leffmann is offline  
Old 09 May 2016, 18:56   #8
Beska
Registered User
 
Join Date: Apr 2014
Location: Calgary/Canada
Posts: 26
Your suggestion seems to do the trick. I can't believe I didn't think of this myself.
thanks!
Beska 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
gfxbase negative offset Asman Coders. System 14 28 May 2015 23:24
Calculate Time-Tracks Pixel width? AGS Coders. General 22 10 March 2015 19:19
Calculate a color gradient. AGS Coders. Asm / Hardware 13 11 February 2015 11:20
Program Counter with Offset - why? Jherek Carnelia Coders. General 26 21 March 2011 10:49
GfxRip Palette and Offset questions stef80 project.Sprites 2 06 July 2007 19: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 15:47.

Top

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