English Amiga Board


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

 
 
Thread Tools
Old 27 January 2021, 18:42   #1
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Another Vasm question

Hi,

How do you make this without making Vasm shout "error 39 : illegal relocation" ?

add.l #label1-label0,a1


Thanks,
LeCaravage is offline  
Old 27 January 2021, 18:50   #2
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Ok, got it. The pb seems to be found in section. If label1 & label0 are not in the same section than the instruction, vasm don't recognize the labels. Why ? I don't know, because it's a relative value.
LeCaravage is offline  
Old 27 January 2021, 19:00   #3
DMWCashy
Registered User
 
Join Date: Dec 2019
Location: Newcastle
Posts: 67
This is do to linker relocation, Vasm is unable to calculate the offset between the 2 labels as that is done at link time.
DMWCashy is offline  
Old 27 January 2021, 20:18   #4
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Quote:
Originally Posted by DMWCashy View Post
This is do to linker relocation, Vasm is unable to calculate the offset between the 2 labels as that is done at link time.
Why not ? Both labels are in the same section. Could it be possible to change this error to a warning with a param sent to vasm ?
LeCaravage is offline  
Old 27 January 2021, 20:33   #5
DMWCashy
Registered User
 
Join Date: Dec 2019
Location: Newcastle
Posts: 67
I think this is an issue with Vasm, are both labels in the same file?

I may be wrong, but I am sure this has been discussed before on this forum somewhere.
DMWCashy is offline  
Old 27 January 2021, 20:34   #6
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,386
workaround: define a
Code:
diff:
   dc.l  label1-label0
in the section where the labels are. Then use this

Code:
 add.l  diff,a1
or first add then sub the other value (or precompute it in a register if time critical)
jotd is offline  
Old 27 January 2021, 20:39   #7
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Quote:
Originally Posted by DMWCashy View Post
I think this is an issue with Vasm, are both labels in the same file?

I may be wrong, but I am sure this has been discussed before on this forum somewhere.
Indeed, I'm no specialist with Vasm but really too bad to make restriction with this feature.
Yes they are in same include file and same section too.

Quote:
Originally Posted by jotd View Post
workaround: define a
Code:
diff:
   dc.l  label1-label0
in the section where the labels are. Then use this

Code:
 add.l  diff,a1
or first add then sub the other value (or precompute it in a register if time critical)
Thanks for the tip. (too bad to waste 4 bytes though).

Last edited by LeCaravage; 27 January 2021 at 20:45.
LeCaravage is offline  
Old 27 January 2021, 23:30   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,552
Quote:
Originally Posted by LeCaravage View Post
If label1 & label0 are not in the same section than the instruction, vasm don't recognize the labels. Why ? I don't know, because it's a relative value.
The issue is certainly elsewhere. The difference between two labels in the same section is never a problem, as it is constant. And the two labels also don't have to be in the same section as the instruction - why should they? Example:
Code:
frank@nerthus cat tst.s
        code
        add.l   #label1-label0,a1

        data
label0:
        dc.b    1,2,3
label1:
frank@nerthus vasmm68k_mot tst.s
vasm 1.8i (c) in 2002-2020 Volker Barthelmann
vasm M68k/CPU32/ColdFire cpu backend 2.3m (c) 2002-2020 Frank Wille
vasm motorola syntax module 3.14a (c) 2002-2020 Frank Wille
vasm test output module 1.0 (c) 2002 Volker Barthelmann

CODE(acrx2):               2 bytes
DATA(adrw1):               3 bytes
Unlike many other assemblers vasm even supports label differences when the first label is unknown or in a different section, provided that the second label is in the same section as the instruction. Example:
Code:
frank@nerthus cat tst.s
        xref    label1
        code
label0:
        add.l   #label1-label0,a1

        data
label1:
frank@nerthus vasmm68k_mot -quiet tst.s
frank@nerthus more a.out
Sections:
section CODE (attr=<acrx> align=2):
(...)
       0: symbol: label0 LAB (0x0) sec=CODE
       0: data(6): d3 fc 00 00 00 02 rpc(2,0-31,0xffffffff,0x2,label1 LAB (0x0) EXPORT REF sec=DATA )
It does this trick by using a 32-bit PC-relative relocation and adapting the addend accordingly. These relocations even work under AmigaOS since OS2.0 (or 3.0?) using HUNK_RELRELOC32.


Quote:
Originally Posted by LeCaravage View Post
Indeed, I'm no specialist with Vasm but really too bad to make restriction with this feature.
Yes they are in same include file and same section too.
There is no such restriction. Please check your code again or provide an example which reproduces the error. Probably one or both of your labels is undefined or both are in different sections.
phx 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
Vasm “so.” directive Curbie Coders. General 9 09 April 2020 20:55
vasm and comments xxxxx Coders. Asm / Hardware 10 03 February 2015 12:59
vasm question marduk_kurios Coders. Asm / Hardware 7 14 February 2014 20:06
vasm fsincos dalton Coders. Asm / Hardware 4 03 September 2012 10:35
vasm 1.5 RFC phx Coders. General 30 11 December 2010 02:08

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:29.

Top

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