15 May 2019, 20:04 | #21 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
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 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. |
15 May 2019, 20:37 | #22 | |
Registered User
Join Date: May 2017
Location: Scotland
Posts: 53
|
@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:
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. |
|
15 May 2019, 20:47 | #23 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
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". |
|
15 May 2019, 22:50 | #24 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
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.) |
15 May 2019, 23:03 | #25 | |
Registered User
Join Date: May 2017
Location: Scotland
Posts: 53
|
Quote:
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. |
|
15 May 2019, 23:14 | #26 | |
Registered User
Join Date: May 2017
Location: Scotland
Posts: 53
|
Quote:
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. |
|
15 May 2019, 23:23 | #27 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,957
|
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) |
15 May 2019, 23:25 | #28 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
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.) |
15 May 2019, 23:53 | #29 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
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. |
|
16 May 2019, 07:36 | #30 | ||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
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:
Quote:
I don't know of an assembler that would do otherwise. Quote:
And every good enough assembler should be more or less similar. |
||||
16 May 2019, 16:49 | #31 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
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 |
|
16 May 2019, 17:31 | #32 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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. |
16 May 2019, 19:16 | #33 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,038
|
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. |
16 May 2019, 19:37 | #34 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
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 |
16 May 2019, 20:12 | #35 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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:
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. |
|
16 May 2019, 23:33 | #36 | ||
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,543
|
Quote:
"-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:
Does anyone know how to stop Barfly from 'optimizing' cmp to cmpi ? |
||
17 May 2019, 12:56 | #37 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
|
17 May 2019, 12:57 | #38 | |||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Quote:
Quote:
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 Quote:
Quote:
|
|||||
17 May 2019, 13:01 | #39 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
No. The binary snapshots are built automatically over night on my NetBSD server with vbcc. There is no Windows target.
|
17 May 2019, 13:13 | #40 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,957
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Issues with ORG directive (vasm + FS-UAE) | Maggot | Coders. Asm / Hardware | 15 | 05 September 2023 11:56 |
vasm basereg example directive | mcgeezer | Coders. Asm / Hardware | 7 | 18 November 2020 19:58 |
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 |
|
|