English Amiga Board


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

 
 
Thread Tools
Old 15 May 2019, 20:04   #21
Photon
Moderator

Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 4,681
Antiriad_UK seems intent on finding out how it works, and I think there's a fast way.

Let's disregard the other two questions, BSS sections and whether the data is cleared for now.

Assemble this to a release exe:

Code:
SECTION DCBvsDS,CODE_C
Start:
	move.l #Data1,a0
	move.l #Data2,a1
	move.l #Data3,a2
	moveq #0,d0
	rts
Data1:	dcb.b 1000,0
	rts
Data2:	dcb.b 1000,0
Data3:	dcb.b 1000,0
Of course, with DCB there, we expect the file to be 3060 bytes+a few bytes relocs. So, total 3088 bytes.

Now change all 3 DCB to DS, and use your preferred Assembler and preferred options.

If each DS is translated into markers interpreted by the OS1.3+ hunk parser, what we should see is an exe file size of 88 bytes+a few bytes for the DS, say 24 bytes extra, so total 112.

If that's true only for the last DS, we should see a file size of 2088+fewer bytes extra, say total 2096.

~

So, values very near these totals should tell us if DS is recognized by 1) the OS, 2) the Assembler, or 3) none. If the total size is larger than one of the three totals in bold by more than 4 bytes, the assumption is that your Assembler modifies your code and/or your sections.

Last edited by Photon; 15 May 2019 at 20:16.
Photon is offline  
Old 15 May 2019, 20:37   #22
Kalamatee
Registered User

 
Join Date: May 2017
Location: Scotland
Posts: 47
@Antiriad_UK

BSS sections are to store uninitialized values. While strictly speaking they dont need to be initialized, due to statically-allocated objects without an explicit initializer in "c" being initialized to zero (and using bss to store them), in practice ALL(*) operating systems do clear real BSS section(s) of a file.

dc.x explicitly defines a value, and as such it is expected to be initialized before use so has to be stored in the file in a normal data section, however ds.x handling is entirely assembler/compiler dependent. Typically it will be stored in BSS (so that the least space is used on disk), which means the OS will expand it to the correct size and initialize it to 0, in case the binary was written using "C" or another language that expects it to be set to 0 - some however will try to do tricks to combine it with other sections, though it will now take up more disk space since it is no longer expanded in the same manner as a normal BSS section, and will not necessarily be initialized to any specific value.

Edit: Really they are talking about 2 different things though. dc/ds are not referring to how it is stored on disk but represented in memory. BSS refers to how data is actually stored on disk and loaded by the system.

so to answer your actual original question -:

Quote:
In ASMOne/Pro there is a preference option for "DS Clear" but the manual says that outside of ASMOne (final exe) they will NOT be cleared.

Is this a difference in assemblers or is it just the ASM one manual I'm misunderstanding and it's only talking about BSS sections?
when you are doing things _inside_ of ASMOne it will either a> treat the code the same inside of ASMOne, as you would expect if you loaded the binary in the OS (so if it is putting it in its "own" special "bss"-like section that isn't really bss, it will not be initialized) or b> initialize it when you use it in ASMOne - though it warns you the final binary will not initialize it (because of the previously mentioned special way of storing it..). So yes the difference is in the assembler (and how you are using it ) because of the special way it is storing the value. if you explicitly put the value in a "real" BSS section or the compiler puts it there (which is the more general behavior) it will be initialized to 0.

where the values are stored in a file isn't strictly defined by the mnemonics, so an assembler/compiler etc are free to choose which section _they_ think best suits the data.

I hope that helps clarify things.

* - there are a few operating systems/crt's that can use a special BSS format that allows some parts to be initialized and others not, but it isn't the general expected behavior.

Last edited by Kalamatee; 15 May 2019 at 22:54.
Kalamatee is offline  
Old 15 May 2019, 20:47   #23
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,441
Quote:
Originally Posted by Photon View Post
Antiriad_UK seems intent on finding out how it works, and I think there's a fast way.

Let's disregard the other two questions, BSS sections and whether the data is cleared for now.

Assemble this to a release exe:

Code:
SECTION DCBvsDS,CODE_C
Start:
    move.l #Data1,a0
    move.l #Data2,a1
    move.l #Data3,a2
    moveq #0,d0
    rts
Data1:    dcb.b 1000,0
    rts
Data2:    dcb.b 1000,0
Data3:    dcb.b 1000,0
Of course, with DCB there, we expect the file to be 3060 bytes+a few bytes relocs. So, total 3088 bytes.

Now change all 3 DCB to DS, and use your preferred Assembler and preferred options.

If each DS is translated into markers interpreted by the OS1.3+ hunk parser, what we should see is an exe file size of 88 bytes+a few bytes for the DS, say 24 bytes extra, so total 112.

If that's true only for the last DS, we should see a file size of 2088+fewer bytes extra, say total 2096.

~

So, values very near these totals should tell us if DS is recognized by 1) the OS, 2) the Assembler, or 3) none. If the total size is larger than one of the three totals in bold by more than 4 bytes, the assumption is that your Assembler modifies your code and/or your sections.
There is nothing such as markers that would make the exe go down to 112 bytes ; AOS by itself does not crunch sections. Any Amiga asm doing that would be severely broken.
Of course an asm putting garbage data instead of zeroes for DS is also broken

I get 3088 bytes. An assembler recognising the MOVEA and converting it to PC-relative LEA would go down to 3056.

Strict minimum is 1056 but then the exe is no longer ks1.3 compatible.
If an asm does this conversion, it will not do that just for last DS, that would be pretty stupid (imagine it's ds.b 1, lol) - and the OS itself has absolutely no such concept as "DS".
meynaf is offline  
Old 15 May 2019, 22:50   #24
Photon
Moderator

Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 4,681
Meynaf, I agree it would be "awesome if true", but I'm open and looking for facts. If it's possible, someone should be able to post a smaller size together with 1) Assembler, 2) settings, and 3) OS compatibility.

The code snippet is made so that it shows what putting DS in your source means to the combination of these 3 things.

And this is why Antiriad_UK posted, at least I read it as he wants to know what happens. (The statements in the manuals I already answered in my 2nd post, but we all seek knowledge.)
Photon is offline  
Old 15 May 2019, 23:03   #25
Kalamatee
Registered User

 
Join Date: May 2017
Location: Scotland
Posts: 47
Quote:
Originally Posted by Kalamatee View Post
@Antiriad_UK

when you are doing things _inside_ of ASMOne it will either a> treat the code the same inside of ASMOne, as you would expect if you loaded the binary in the OS (so if it is putting it in its "own" special "bss"-like section that isn't really bss, it will not be initialized) or b> initialize it when you use it in ASMOne - though it warns you the final binary will not initialize it (because of the previously mentioned special way of storing it..). So yes the difference is in the assembler (and how you are using it ) because of the special way it is storing the value. if you explicitly put the value in a "real" BSS section or the compiler puts it there (which is the more general behavior) it will be initialized to 0.

where the values are stored in a file isn't strictly defined by the mnemonics, so an assembler/compiler etc are free to choose which section _they_ think best suits the data.
If it helps - don't think of ds.x in terms of how it is stored on disk, just in how it is used in memory. unless you explicitly ask for it to be put in a section on disk, the assembler/compiler/linker will "optimize" its location based upon how it is actually used, and you should always expect ds.x to have an uninitialized value.

e.g. If the compiler/assembler/linker in question decides it saves more space/performs better to use a shorter addressing mode and localize the data represented by ds.x, it will store it in the same section using those preferred instructions. when this is now loaded by the os the value is "uninitialized" and could contain anything.

If you have explicitly asked for it to be put in a real bss section you can expect it to be initialized to 0.
Kalamatee is offline  
Old 15 May 2019, 23:14   #26
Kalamatee
Registered User

 
Join Date: May 2017
Location: Scotland
Posts: 47
Quote:
Originally Posted by Photon View Post
Meynaf, I agree it would be "awesome if true", but I'm open and looking for facts. If it's possible, someone should be able to post a smaller size together with 1) Assembler, 2) settings, and 3) OS compatibility.
erm... surely. ..

Code:
SECTION DCBvsDS,CODE_C
Start:
    move.l #Data1,a0
    move.l #Data2,a1
    move.l #Data3,a2
    moveq #0,d0
    rts

; though really you would move this to BSS also ..
Data1:    dsb.b 1000,0
    rts

SECTION MYBSS,BSS
Data2:    dsb.b 1000,0
Data3:    dsb.b 1000,0
?

the result also being A0 _could_ contain a random value but A!/A2 will contain 0 when loaded by the OS.

Last edited by Kalamatee; 15 May 2019 at 23:21.
Kalamatee is offline  
Old 15 May 2019, 23:23   #27
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 1,114
Every good assembler (used by me) zeroed ds.x area.
But assemblers different handles f.e next code:
rts
cnop 0,4
rts

in cnop 0,4 place, I see 3 types:
1. dc.w 0

2. nop

3. dc.w $xxxx (random value)
Don_Adan is offline  
Old 15 May 2019, 23:25   #28
Photon
Moderator

Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 4,681
Quote:
Originally Posted by Kalamatee View Post
erm... surely. ..
My test code mustn't be altered - it's nothing special, but it's written this way to show the current contention in the thread - what DS does. (As I write, the original question has been answered as stated.)

I.e. for us to find out DS behavior you can perform this test on your combination of choice and report results

Also: don't double-post: this is not allowed. (To avoid this, use the Multi-quote button.)
Photon is offline  
Old 15 May 2019, 23:53   #29
ross
Sum, ergo Cogito

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 1,690
Quote:
Originally Posted by Kalamatee View Post
the result also being A0 _could_ contain a random value but A!/A2 will contain 0 when loaded by the OS.
A0-A2 certainly they won't be 0
This is the reason I always use lea (or strictly movea if I need data in Ax registers).

Anyway if only a single SECTION is allowed, only the last 2000 bytes can be in the 'CODE_BSS' part and zeroed by LoadSeg() on KS2.0+.
No alternatives.
ross is offline  
Old 16 May 2019, 07:36   #30
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,441
Quote:
Originally Posted by Photon View Post
Meynaf, I agree it would be "awesome if true", but I'm open and looking for facts. If it's possible, someone should be able to post a smaller size together with 1) Assembler, 2) settings, and 3) OS compatibility.

The code snippet is made so that it shows what putting DS in your source means to the combination of these 3 things.

And this is why Antiriad_UK posted, at least I read it as he wants to know what happens. (The statements in the manuals I already answered in my 2nd post, but we all seek knowledge.)
You keep looking for mysteries where there is none. The situation is really very simple. It's not "awesome if true", it's simply true.

Regardless of settings, PhxAss will always zero DS.x outside of BSS. Most assemblers, except maybe the really broken ones, also will.
Regardless of the assembler and settings, the OS will always zero true BSS sections and only 1.x will not zero bss part of CODE/DATA sections.
What's not clear in that ?


Quote:
Originally Posted by Kalamatee View Post
If it helps - don't think of ds.x in terms of how it is stored on disk, just in how it is used in memory. unless you explicitly ask for it to be put in a section on disk, the assembler/compiler/linker will "optimize" its location based upon how it is actually used, and you should always expect ds.x to have an uninitialized value.

e.g. If the compiler/assembler/linker in question decides it saves more space/performs better to use a shorter addressing mode and localize the data represented by ds.x, it will store it in the same section using those preferred instructions. when this is now loaded by the os the value is "uninitialized" and could contain anything.
While a compiler may eventually perform this kind of thing, an assembler will not do a thing "upon how it is actually used"...


Quote:
Originally Posted by Kalamatee View Post
the result also being A0 _could_ contain a random value but A!/A2 will contain 0 when loaded by the OS.
What is pointed to by A0 (not A0 itself !) contains 0, not a random value.
I don't know of an assembler that would do otherwise.


Quote:
Originally Posted by Don_Adan View Post
Every good assembler (used by me) zeroed ds.x area.
But assemblers different handles f.e next code:
rts
cnop 0,4
rts

in cnop 0,4 place, I see 3 types:
1. dc.w 0

2. nop

3. dc.w $xxxx (random value)
PhxAss has the option to use either 0 or nop padding.
And every good enough assembler should be more or less similar.
meynaf is offline  
Old 16 May 2019, 16:49   #31
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,340
Quote:
Originally Posted by Photon View Post
If it's possible, someone should be able to post a smaller size together with 1) Assembler, 2) settings, and 3) OS compatibility.
1) vasmm68k
2) -databss option is needed to enable this feature
3) OS2.0+, of course. For Kickstart 1.x you have to clear the Databss-region yourself.

Code:
frank@sun cat databsstest.s
        SECTION DCBvsDS,CODE_C
Start:
        move.l #Data1,a0
        move.l #Data2,a1
        move.l #Data3,a2
        moveq #0,d0
        rts
Data1:  dcb.b 1000,0
        rts
Data2:  dcb.b 1000,0
Data3:  dcb.b 1000,0

frank@sun vasmm68k_mot -Fhunkexe -nosym -databss databsstest.s
vasm 1.8f (c) in 2002-2019 Volker Barthelmann
vasm M68k/CPU32/ColdFire cpu backend 2.3e (c) 2002-2019 Frank Wille
vasm motorola syntax module 3.12b (c) 2002-2019 Frank Wille
vasm hunk format output module 2.10 (c) 2002-2019 Frank Wille

DCBvsDS(acrx2):         3018 bytes
frank@sun ll a.out
-rw-r--r--  1 frank  users  1056 May 16 16:46 a.out
frank@sun hexdump -C a.out
00000000  00 00 03 f3 00 00 00 00  00 00 00 01 00 00 00 00  |................|
00000010  00 00 00 00 40 00 02 f3  00 00 03 e9 00 00 00 ff  |....@...........|
00000020  41 fa 00 0e 43 fa 03 f4  45 fa 07 d8 70 00 4e 75  |A...C...E...p.Nu|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000410  00 00 00 00 00 00 00 00  4e 75 4e 71 00 00 03 f2  |........NuNq....|
00000420
phx is offline  
Old 16 May 2019, 17:31   #32
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,340
OMG! Anybody spotted the bug in the last line of the executable's hexdump?

It's always good to make these tests. Fixed with tomorrow's vasm-snapshot.
phx is offline  
Old 16 May 2019, 19:16   #33
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 91
Hunk padded with 2 random bytes (hunk size is in LWs, but Data2 is at a non-LW aligned offset), thus trashing first 2 bytes of Data2?

Or 3 "bugs" in line 3 where movea is converted to lea? :P Yeah, I don't like that :P.
If I write movea, I mean it unless I specify +opt or similar. But don't really want to argue about it, so it's OK.
a/b is offline  
Old 16 May 2019, 19:37   #34
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,441
Quote:
Originally Posted by phx View Post
OMG! Anybody spotted the bug in the last line of the executable's hexdump?

It's always good to make these tests. Fixed with tomorrow's vasm-snapshot.
Indeed the first 2 bytes of Data2 are not gonna be zero. Damned NOP padding (but 4E71 are not random bytes).

Last edited by meynaf; 16 May 2019 at 19:39. Reason: oops - found the bug after posting
meynaf is offline  
Old 16 May 2019, 20:12   #35
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,340
Correct! I thought it would be a good idea to pad code sections with NOP, when their size is not a multiple of four. So a linker can merge two halfs of a function without any risk.

But I didn't have -databss in mind. So now I'm leaving it zero when the filesize is smaller than the section size.

Quote:
Originally Posted by a/b View Post
Or 3 "bugs" in line 3 where movea is converted to lea? :P Yeah, I don't like that :P.
Yes, personal taste. I like to have optimizations enabled all the time, because situations where the instruction size matters are rare (e.g. jump-tables).

Run vasm with -devpac in Devpac-compatibility mode and there will be no optimizations until you enable them. Or make sure there will be none with an "OPT O-" directive on top or a -no-opt command line option.
phx is offline  
Old 16 May 2019, 23:33   #36
Bruce Abbott
Registered User

Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 161
Quote:
Originally Posted by phx
-databss option is needed to enable this feature
vasm documentation says:-

"-databss Try to shorten sections in the output file by removing zero words without re-location from the end. This technique is only supported by AmigaOS 2.0 and higher."

But there is a well-known technique that involves adding 'bss' to the end of a code or data section by making the size in the hunk length table (which is used to allocate memory) larger than the hunk's actual size. This technique works in all OS versions.

ProAsm and Barfly use the 'dx' directive to allocate space in these 'extended' code/data sections. PhxAss accepts dx for 'compatibility', but doesn't appear to to honour it (has the same affect as ds).

Any chance of vasm supporting this feature?

Quote:
I like to have optimizations enabled all the time, because situations where the instruction size matters are rare (e.g. jump-tables).
I like to have optimizations enabled never, because I want the assembler to do what I tell it - not change things behind my back.

Does anyone know how to stop Barfly from 'optimizing' cmp to cmpi ?
Bruce Abbott is offline  
Old 17 May 2019, 12:56   #37
ross
Sum, ergo Cogito

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 1,690
Quote:
Originally Posted by phx View Post
It's always good to make these tests. Fixed with tomorrow's vasm-snapshot.
Probably it's time to give to vasm a serious try (I'm obsolete, I'm too used to native assemblers )
There is a win32 (or 64) binary available for the snapshots?
ross is offline  
Old 17 May 2019, 12:57   #38
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,340
Quote:
Originally Posted by Bruce Abbott View Post
But there is a well-known technique that involves adding 'bss' to the end of a code or data section by making the size in the hunk length table (which is used to allocate memory) larger than the hunk's actual size.
That's what we are talking about in this thread...

Quote:
This technique works in all OS versions.
No. As mentioned in earlier posts, 1.x doesn't clear this area.

Quote:
ProAsm and Barfly use the 'dx' directive to allocate space in these 'extended' code/data sections. PhxAss accepts dx for 'compatibility', but doesn't appear to to honour it (has the same affect as ds).

Any chance of vasm supporting this feature?
Sure. I like this idea. But I see a problem with labels.

The space allocated by DX will have to be moved to the end of a section, which means you cannot expect it to be at the same location as you see it in the source. So what happens when you write:
Code:
mydxspace:
        dx.l    1
The space allocated by DX moves, but mydxspace does not! The assembler cannot know what the label is refering to. It could also mark the end of a memory region before it.

Quote:
I like to have optimizations enabled never, because I want the assembler to do what I tell it - not change things behind my back.
That's fair enough. So you also check the distances of all your branches manually to see if they are .b or .w?

Quote:
Does anyone know how to stop Barfly from 'optimizing' cmp to cmpi ?
Unfortunately many assemblers are doing it and I always hated that too, so I made sure PhxAss and vasm assemble exactly what you write. Also makes such an assembler work better with reassemblers.
phx is offline  
Old 17 May 2019, 13:01   #39
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,340
Quote:
Originally Posted by ross View Post
Probably it's time to give to vasm a serious try (I'm obsolete, I'm too used to native assemblers )
There is a win32 (or 64) binary available for the snapshots?
No. The binary snapshots are built automatically over night on my NetBSD server with vbcc. There is no Windows target.
phx is offline  
Old 17 May 2019, 13:13   #40
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 50
Posts: 1,114
Quote:
Originally Posted by phx View Post
Correct! I thought it would be a good idea to pad code sections with NOP, when their size is not a multiple of four. So a linker can merge two halfs of a function without any risk.

But I didn't have -databss in mind. So now I'm leaving it zero when the filesize is smaller than the section size.


Yes, personal taste. I like to have optimizations enabled all the time, because situations where the instruction size matters are rare (e.g. jump-tables).

Run vasm with -devpac in Devpac-compatibility mode and there will be no optimizations until you enable them. Or make sure there will be none with an "OPT O-" directive on top or a -no-opt command line option.
Padding code sections with NOP is not good idea. I never like this. Especially when I resourced code. Only padding with dc.w 0 or $4AFC in debug mode has sense for me. I dont like auto optimisations too. If i used bra.w then it must be bra.w, not bra.b.
Don_Adan 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 basereg example directive mcgeezer Coders. Asm / Hardware 5 22 December 2018 23:38
Issues with ORG directive (vasm + FS-UAE) Maggot Coders. Asm / Hardware 6 21 November 2018 19:48
REPT directive in vasm phx Coders. Asm / Hardware 8 01 October 2014 21:48
AsmOne even directive...? pmc Coders. General 30 04 December 2009 09:33
Invalid Directive Kimmo support.WinUAE 1 23 July 2004 11:23

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 09:16.


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