English Amiga Board


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

 
 
Thread Tools
Old 18 May 2024, 17:44   #21
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,044
Yeah, that might "work" in proasm, but it's wrong (bug?): reloc-abs should result in a reloc. It's not different than reloc +/- offset.
a/b is offline  
Old 18 May 2024, 18:43   #22
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,684
Quote:
Originally Posted by a/b View Post
Yeah, that might "work" in proasm, but it's wrong (bug?): reloc-abs should result in a reloc. It's not different than reloc +/- offset.
address - address = number. Every assembler should be happy with it.

Of course this only works with absolute code (no relocs involved). The reason it doesn't work with load modules is that the loader only relocates 32 bit numbers, and the copper list has 16 bit numbers.

BTW the only reason I developed this macro was for use with my disassembler, where it is required to generate assemblable source code. In my own code I generate the numbers at run time, which works everywhere.
Bruce Abbott is offline  
Old 18 May 2024, 20:02   #23
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,044
Quote:
Originally Posted by Bruce Abbott View Post
address - address = number. Every assembler should be happy with it.
Generally speaking, assemblers don't use just plain addresses/numbers, they use symbols instead. Number is just a part of that, the other typical parts are section and type/attributes (abs, reloc, var, const, register/EQUR, ...) and they determine what operations can be performed.
So when you send a string down to the expression parser/evaluator you don't get back just a number. On the surface it might look simple but there's a lot going on in the background. And then, if the asm is multi-pass, you often get "undefined" values and have to defer to pass2+.
reloc1-reloc2 works fine with relocs, and in some asms they don't have to be in the same section, while the others won't accept the shorthand version and you have to write it as e.g. (reloc1-start1)-(reloc2-start2), with extra subtractions as explicite conversion from reloc to abs const, which can be then used with fewer constraints.
All this text because OP is dealing with relocs, and if everything is abs then yeah, hack away just as back in the old ORG/LOAD days ;p.
a/b is offline  
Old 19 May 2024, 17:16   #24
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,517
Quote:
Originally Posted by a/b View Post
reloc-abs should result in a reloc.
I tend to agree (if "abs" means absolute address label). It would be logical. Although I cannot imagine a use-case for adding or subtracting a label from an ORG-section.

I was confused, because vasm, like ProAsm, flagged the resulting expression as constant. This happens because an
org
within a relocatable code section is treated as a block of absolutely relocated code within that relocatable section. So, technically it's still the same section and distances between labels from the same section are constant.

I should proably fix that.


Quote:
Originally Posted by Bruce Abbott View Post
address - address = number. Every assembler should be happy with it.
An address is also a "number". The important difference is if an expression can be evaluated as being constant at compile time or not.

Quote:
Of course this only works with absolute code (no relocs involved).
I wonder why you need that macro trick with labels from absolute code? There should be no problem.
phx is offline  
Old 20 May 2024, 22:33   #25
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,684
Quote:
Originally Posted by a/b View Post
Generally speaking, assemblers don't use just plain addresses/numbers, they use symbols instead. Number is just a part of that, the other typical parts are section and type/attributes (abs, reloc, var, const, register/EQUR, ...) and they determine what operations can be performed.
Yes, and the assembler will deal with those types according to what they are used for.

A label represents an offset from the start of the section, whose value isn't known until the code has been parsed. In a load module the OS relocates it to an absolute value by adding the address of the start of the section it is relative to in memory. When generating absolute code the assembler 'relocates' the value itself, by adding the ORG address to it when creating the output file.

When one label is subtracted from another the result is an absolute value that is also not defined until pass 2, but does not require relocating. Therefore the assembler treats it differently. Constant values created with 'equ' or '=' are a third type that is defined in pass 1. The question is what happens when you mix them, eg. adding an absolute value to a label.

Page 83 of the Devpac 3 manual has a chart showing allowable type combinations and results. An 'A' (absolute) value added to or subtracted from an 'R' (relative) value results in an 'R'. 'R' - 'R' = 'A', but 'R' + 'R' is illegal. Logical operations are not permitted on 'R' values. However (not mentioned in the manual) this rule is relaxed when generating absolute code, presumably because the assembler has already converted the 'R's to 'A's by the time it does the calculation.

Quote:
reloc1-reloc2 works fine with relocs, and in some asms they don't have to be in the same section, while the others won't accept the shorthand version and you have to write it as e.g. (reloc1-start1)-(reloc2-start2), with extra subtractions as explicite conversion from reloc to abs const, which can be then used with fewer constraints.
All this text because OP is dealing with relocs, and if everything is abs then yeah, hack away just as back in the old ORG/LOAD days ;p.
Both ProAsm and Basm (Barfly assembler) require the method I used to convert the 'R' value to an 'A' value before applying logical operations to it. It could be argued that they are being too picky here when generating absolute code, but that's how they work.

Why not just use another assembler, you say? The reason is that they are the fastest by far. I paid to get ProAsm registered back in 1996 and have used it ever since, so I prefer it over Basm even though it assembles at only half the speed (but 5-10 times faster than Devpac). The other problem with Devpac is that it doesn't output binary files, only S-records or (absolute) linker files.

Quote:
All this text because OP is dealing with relocs, and if everything is abs then yeah, hack away just as back in the old ORG/LOAD days ;p.
Yeah, the OP appears to be using an AsmOne style assembler so a lot of this discussion may not be relevant to their situation, but it's still worth discussing IMO.
Bruce Abbott is offline  
Old 20 May 2024, 23:01   #26
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,684
Quote:
Originally Posted by phx View Post
Did you really test it?
I have only tested it on reassembling a disassembled binary file. If there is something wrong with it with please tell me.

I used this macro to assist with reassembling source code produced by my disassembler. It is only included in the disassembly of binary files or memory, not load modules. This code will never appear in a load module unless it has absolute code embedded in it (which my disassembler doesn't recognize, so...).

I recently changed my disassembler to use two CMOVE's rather than this macro, which makes it more 'transparent' (ie. you can see what it's doing). Now I have to test other assemblers to see what they need - no rest for the wicked!

Quote:
You found a way to trick the assembler, so you no longer get the helpful error message. But in the end you trick yourself, because the relocation information is missing and the bitplane addresses are wrong after starting the program.
There is no relocation information in a binary file.

The address will be correct relative to the specified ORG address. It is the programmer's responsibility to ensure that the code and data gets there (ie. by loading or moving it to the correct address). For this and other reasons I recommend calculating the values at run time, if practicable.
Bruce Abbott is offline  
Old 21 May 2024, 18:53   #27
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,642
Bruce - OP wants the impossible: to declare a (too) modified value from a label, and have it relocatable in a section.

As correctly stated, no code, assembler (or compiler) can fix this (until the Amiga exe hunk format supports it - currently, it supports longword only pointer +/- absolute offset).

This to say that ORG or runtime solutions are not part of the question, which wants to (impossibly) avoid those.
Photon is offline  
Old 22 May 2024, 04:37   #28
KONEY
OctaMED Music Composer
 
KONEY's Avatar
 
Join Date: Jan 2009
Location: Venice - Italy
Age: 49
Posts: 670
I reached a compromise,

first I put the label I want in the copperlist, like this:

PHP Code:
Copper:
    ...
    .
BplPtrs:
    
DC.W $E0
    DC
.W $E2
    DC
.L BG1
    DC
.W $E4,... 
Then before starting it I fix it but without needing to provide any label:

PHP Code:
    LEA    Copper\.BplPtrs+2,a1
    MOVE
.L    (A1),D0
    SWAP    D0
    MOVE
.L    D0,(A1
No guru so far so I may well say it works
KONEY is offline  
Old 22 May 2024, 13:33   #29
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,642
...which is like PokePtrs, but with disadvantages (hard to read copperlist which will be invalid if the swapping code isn't run (in time)) and none of the advantages (dynamic, PC- or register-relativity possible).

IDK about that one.

Maybe as code obfuscation as part of copy protection, except... the error is clear and to do with the Copper, so it will be found quickly.
Photon 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
Changing Bitplane Pointers Mid-Scanline Rob68K Coders. Asm / Hardware 9 11 April 2024 02:13
Can you use 1 bitplane anims to modify 6th bitplane only ImmortalA1000 Coders. Blitz Basic 0 18 December 2021 11:55
Copperlist crash? TCH Coders. C/C++ 23 22 February 2021 20:52
When is the modulo added to the bitplane pointers? DanScott Coders. Asm / Hardware 3 07 March 2016 18:24
Modifying a copperlist CmdrVimes Coders. General 5 06 September 2010 12: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 13:23.

Top

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