24 May 2022, 17:26 | #21 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
But then I would would be unaware of the potential for optimisation if the size changed to another power of 2
|
21 June 2022, 20:03 | #22 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
It looks like adding an ASSERT outside of a section can result in the creation of an extra, empty CODE section.
test.s: Code:
SCREEN_WIDTH_PIXELS EQU 320 SECTION code rts Code:
vasmm68k_mot -Fhunk test.s Code:
vasm 1.9a (c) in 2002-2022 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 2.5a (c) 2002-2022 Frank Wille vasm motorola syntax module 3.15e (c) 2002-2022 Frank Wille vasm hunk format output module 2.14 (c) 2002-2022 Frank Wille code(acrx2): 2 bytes Code:
SCREEN_WIDTH_PIXELS EQU 320 ASSERT SCREEN_WIDTH_PIXELS!=0,"Invalid width" SECTION code rts Code:
vasm 1.9a (c) in 2002-2022 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 2.5a (c) 2002-2022 Frank Wille vasm motorola syntax module 3.15e (c) 2002-2022 Frank Wille vasm hunk format output module 2.14 (c) 2002-2022 Frank Wille CODE(acrx1): 0 bytes code(acrx2): 2 bytes Last edited by hop; 21 June 2022 at 20:08. Reason: clarification |
22 June 2022, 09:58 | #23 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
It's not great, but to be expected. An
assertdirective creates an "atom" of the type ASSERT, similar to DATA, INSTRUCTION, LABEL or OPTS atoms. In vasm a section is a list of atoms, which will be processed in multiple passes. Which means: an atom cannot exist outside of a section. When there is no section once the parser runs into an atom-generating directive, then the default section will be created. EDIT: In your example you may think this is not required, which is correct, as the symbol is absolute and already known when the parser meets the directive. But assertions also have to work with labels, where the value is not known or correct until the final pass. Last edited by phx; 22 June 2022 at 10:07. Reason: more explanations |
22 June 2022, 14:03 | #24 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Thanks for the explaination. Not sure if it is worth making a note of this in the docs next to the description of the assert directive.
It looks like the empty CODE section does not result in an empty hunk when either vasm or vlink is used to generate the executable. |
22 June 2022, 19:15 | #25 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Solution: a few kinds of atoms may be worth to save in an intermediate container, before I add them in front of the first real section. You may try tomorrow's snapshot. Besides ASSERT there are also other directives, like PRINTT, PRINTV, ECHO, FAIL, etc. which could wait until a section exists. Adapted the code for all these directives. Other atoms, like data, instruction or label still start the default section, of course, if you didn't specify one. Quote:
-keepempty. |
||
22 June 2022, 20:40 | #26 | ||
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
Quote:
-keepemptyin vasm.pdf but not in vlink.pdf |
||
25 June 2022, 17:36 | #27 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
Before: Code:
vasm 1.9a (c) in 2002-2022 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 2.5a (c) 2002-2022 Frank Wille vasm motorola syntax module 3.15e (c) 2002-2022 Frank Wille vasm hunk format output module 2.14 (c) 2002-2022 Frank Wille CODE(acrx1): 0 bytes code(acrx2): 2 bytes Code:
vasm 1.9a (c) in 2002-2022 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 2.5c (c) 2002-2022 Frank Wille vasm motorola syntax module 3.16 (c) 2002-2022 Frank Wille vasm hunk format output module 2.14a (c) 2002-2022 Frank Wille code(acrx2): 2 bytes |
|
25 June 2022, 20:08 | #28 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
26 June 2022, 11:24 | #29 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
Great! I don't think I'm seeing this in the latest daily source snapshot 26 Jun 2022 02:15:18 UTC: vlink.tar.gz (238896 bytes) Code:
C:\tmp>vlink -Wfail Warning 2: Unrecognized option '-Wfail'. Fatal error 6: No input files. Aborting. EDIT: Found the historyfile and can see -wfail mentioned in there. Let me try again... EDIT: Coming through now human error... Last edited by hop; 26 June 2022 at 11:36. |
|
26 June 2022, 15:32 | #30 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Thanks for this. It is great for making builds more robust.
It caught me out the first time I tested it because I was expecting an error message. Code:
C:\amiga-dev\target\loaders\hunk_to_rawseg>vlink -brawseg -q -Thunk_to_rawseg_loadfile.ld -nowarn=12 -wfail -o intermediates\hunk_to_rawseg_loadfile.rawseg intermediates\hunk_to_rawseg_loadfile || EXIT /B 1 Warning 22: Attributes of section .chip were changed from r-x- to rwx- in hunk_to_rawseg_loadfile. C:\amiga-dev\target\loaders\hunk_to_rawseg> This is the MS compiler output in a similar circumstance: Code:
1>C:\amiga-dev\host_tools\src\HunkHelpers.cpp(50,11): error C2220: the following warning is treated as an error 1>C:\amiga-dev\host_tools\src\HunkHelpers.cpp(50,11): warning C4189: 'numBytes': local variable is initialized but not referenced 1>Done building project "HunkLoad.vcxproj" -- FAILED. Code:
C:\amiga-dev\target\loaders\hunk_to_rawseg>vlink -brawseg -q -Thunk_to_rawseg_loadfile.ld -nowarn=12 -wfail -o intermediates\hunk_to_rawseg_loadfile.rawseg intermediates\hunk_to_rawseg_loadfile || EXIT /B 1 Warning 22: Attributes of section .chip were changed from r-x- to rwx- in hunk_to_rawseg_loadfile. Fatal error 150: Warnings treated as errors Aborting. C:\amiga-dev\target\loaders\hunk_to_rawseg> Please just tell me to GTFO if I'm being pedantic, or confusing -wfail with -Werr and giving you unnecessary work. Great toolchain! Last edited by hop; 26 June 2022 at 15:35. Reason: clarification |
26 June 2022, 20:28 | #31 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
As you wish.
Done. |
28 June 2022, 08:53 | #32 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
|
28 June 2022, 10:04 | #33 |
Inviyya Dude!
Join Date: Sep 2016
Location: Amiga Island
Posts: 2,770
|
What does ASSERT exactly do and how is it useful?
|
28 June 2022, 10:29 | #34 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
It provides build-time error checking. It is better to catch problems as early as possible. Bugs can be fixed much faster if the assember tells you there is a problem right after you make the edit, rather than have a bug in your code which causes a crash or corruption at runtime that can be difficult and time-consuming to debug.
It is similar in principle to the C++ static_assert. See this Stack Overflow post for more info. In assembly programs, I often use ASSERT make the assember check (assert) that the size of some DC.Bor DC.Wor INCBINdata matches the required size. For example if I was declaring a table of 8 values Code:
table: DC.B $00,$01,$03,$04,$05,$06,$07 ASSERT*-table==8,"Expect 8 bytes in table" *is the address of the current location in the file. Think of it like the 68000 PC, but at assembly time. So *-tableis the measured size of the table at assembly time (end-start) When assembled this would error with: Code:
error 48 in line 94 of "proc.s": assertion "*-table==8" failed: Expect 8 bytes in table > ASSERT*-table==8,"Expect 8 bytes in table" This also works for externally incbined data: Code:
table: INCBIN "table.bin" ASSERT*-table==8,"Expect 8 bytes in table" Code:
sprite: DC.W $444C, $5401 ; Control words DC.W $5555, $3333 ;First line of 16 pixels DC.W $1234, $5678 ;Second line DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W $1234, $5678 DC.W 0, 0 ; End ASSERT (*-sprite)/2==2+(16*2)+2 A line was missing - so when assembled, vasm reports: Code:
error 48 in line 109 of "proc.s": assertion "(*-sprite)/2==2+(16*2)+2" failed: > ASSERT (*-sprite)/2==2+(16*2)+2 Code:
LOGO_WIDTH_PIXELS EQU 176 LOGO_HEIGHT_PIXELS EQU 114 ASSERT LOGO_WIDTH_PIXELS&7==0,"Logo image width is not an integral number of bytes" LOGO_WIDTH_BYTES EQU LOGO_WIDTH_PIXELS>>3 ASSERT LOGO_WIDTH_BYTES&1=0,"Logo image width is not an integral number of words" LOGO_WIDTH_WORDS EQU LOGO_WIDTH_BYTES>>1 ... ; some blitting later on move.w #SCREEN_WIDTH_BYTES-LOGO_WIDTH_BYTES,BLTDMOD(a5) move.w #(LOGO_HEIGHT_PIXELS<<6)+LOGO_WIDTH_WORDS,BLTSIZE(a5) ; start the blitter ... SECTION data_c,data,chip EVEN ; word align for blitting logo: INCBIN "logo.raw" logoSizeBytes EQU *-logo PRINTT "Logo size, bytes:" PRINTV logoSizeBytes ASSERT logoSizeBytes==LOGO_WIDTH_BYTES*LOGO_HEIGHT_PIXELS*BITPLANE_COUNT Last edited by hop; 29 June 2022 at 10:11. Reason: Real-world example |
07 December 2023, 09:42 | #35 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
I am finding it very handy for constructing disk images: Code:
include "DiskGeometry.i" ORG 0 ; Put VASM in absolute mode. See https://eab.abime.net/showpost.php?p=1542178&postcount=4 INCBIN "Build/bootblock" PRINTT "Bootblock size (bytes):" PRINTV * ASSERT *<=BOOTBLOCK_SIZE_BYTES,"Bootblock code exceeds max bootblock size of $400 (1024) bytes" ; Requires pre-release version of VASM. See https://eab.abime.net/showpost.php?p=1542732&postcount=14 PRINTT "Bootblock bytes free:" PRINTV BOOTBLOCK_SIZE_BYTES-* .... ORG 12*TRACK_SIZE_BYTES INCBIN "disk1.adf",12*TRACK_SIZE_BYTES,148*TRACK_SIZE_BYTES PRINTT "Disk image size (bytes):" PRINTV * ASSERT *==DISK_SIZE_BYTES,"Expect disk image to be $DC000 (901120) bytes" ; Requires pre-release version of VASM. See https://eab.abime.net/showpost.php?p=1542732&postcount=14 END |
|
07 December 2023, 20:01 | #36 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
|
FWIW I usually use something like
Code:
ifne *-8 error assumptions changed! endc |
10 December 2023, 12:09 | #37 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
That's what I am usually doing as well. But conditional assembly doesn't work in all cases, because it must evalulate the expression during the first pass. The ASSERT directive creates an atom in the section, which is evaluated in the final pass with the final values.
Example, this doesn't work with IF: Code:
a: move.l #sym,d0 b: rts if b-a!=2 fail "not optimized" endc sym = 1 Code:
a: move.l #sym,d0 b: rts assert b-a==2,"not optimized" sym = 1 |
10 December 2023, 12:33 | #38 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
I like the way asserts keep the assertion positive, rather than having to negate it. Double negatives often mix me up!
|
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 |
Question about NEAR directive in vasm | dansalvato | Coders. Asm / Hardware | 2 | 18 March 2022 12:40 |
vasm basereg example directive | mcgeezer | Coders. Asm / Hardware | 7 | 18 November 2020 19:58 |
Vasm “so.” directive | Curbie | Coders. General | 9 | 09 April 2020 20:55 |
REPT directive in vasm | phx | Coders. Asm / Hardware | 8 | 01 October 2014 21:48 |
|
|