English Amiga Board


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

 
 
Thread Tools
Old 24 May 2022, 17:26   #21
hop
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
hop is offline  
Old 21 June 2022, 20:03   #22
hop
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
Assembling with
Code:
vasmm68k_mot -Fhunk test.s
Gives
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
but

Code:
SCREEN_WIDTH_PIXELS	EQU	320
	ASSERT SCREEN_WIDTH_PIXELS!=0,"Invalid width"
	SECTION	code
	rts
built with the same command line gives:

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
Is this expected behaviour?

Last edited by hop; 21 June 2022 at 20:08. Reason: clarification
hop is offline  
Old 22 June 2022, 09:58   #23
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
It's not great, but to be expected. An
assert
directive 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
phx is offline  
Old 22 June 2022, 14:03   #24
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
It's not great, but to be expected.
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.
hop is offline  
Old 22 June 2022, 19:15   #25
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hop View Post
Not sure if it is worth making a note of this in the docs next to the description of the assert directive.
Fixing it is not much more work than describing the current sad state. So I prefered to improve the situation.

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:
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.
That's a feature of the selected output module from vasm. The Hunk and ELF output modules automatically remove empty sections, unless you specified
-keepempty
.
phx is offline  
Old 22 June 2022, 20:40   #26
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
Fixing it is not much more work than describing the current sad state. So I prefered to improve the situation.

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.
Great. Hope there are no complications. I'll test this out.

Quote:
Originally Posted by phx View Post
That's a feature of the selected output module from vasm. The Hunk and ELF output modules automatically remove empty sections, unless you specified
-keepempty
.
Thanks - I'd always forget to look in the output module docs. I can see
-keepempty
in vasm.pdf but not in vlink.pdf
hop is offline  
Old 25 June 2022, 17:36   #27
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
Fixing it is not much more work than describing the current sad state. So I prefered to improve the situation.

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.
I build today's snapshot, and seems to be working great. Thanks very much.

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
After:
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
hop is offline  
Old 25 June 2022, 20:08   #28
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Thanks for testing.

Quote:
Originally Posted by hop View Post
I can see
-keepempty
in vasm.pdf but not in vlink.pdf
vlink doesn't remove empty sections automatically. You need option
-gc-empty
for it.

BTW, I just implemented
-wfail
into vlink, as requested.
phx is offline  
Old 26 June 2022, 11:24   #29
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
Thanks for testing.


vlink doesn't remove empty sections automatically. You need option
-gc-empty
for it.
Thanks for implementing, and thanks for the tip.

Quote:
Originally Posted by phx View Post
BTW, I just implemented
-wfail
into vlink, as requested.
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.
When I download this file it is 1,054,720 bytes in size. Not sure if it's pulling down the wrong file, or if the changes haven't made it in yet. Is a changelog available anywhere? Thanks

EDIT: Found the
history
file 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.
hop is offline  
Old 26 June 2022, 15:32   #30
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
I just implemented
-wfail
into vlink, as requested.
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>
The build script was exiting on fail and could (should?) print its own own custom message, but it might be nice for the developer if the tool could itself output a line to stderr (possibly a new internal error) to state that it had stopped on a warning because warnings were treated as errors.

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.
I guess the vlink equivalent would be:

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>
But I guess this would require a refactor to make warnings generate an internal error when -wfail is used.

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
hop is offline  
Old 26 June 2022, 20:28   #31
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
As you wish.
Done.
phx is offline  
Old 28 June 2022, 08:53   #32
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
As you wish.
Done.
Wonderful thanks.

Code:
Warning 22: Attributes of section .chip were changed from r-x- to rwx- in hunk_to_rawseg_loadfile.
Error 152: Warnings treated as errors.
hop is offline  
Old 28 June 2022, 10:04   #33
Tigerskunk
Inviyya Dude!
 
Tigerskunk's Avatar
 
Join Date: Sep 2016
Location: Amiga Island
Posts: 2,770
What does ASSERT exactly do and how is it useful?
Tigerskunk is offline  
Old 28 June 2022, 10:29   #34
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by Tigerskunk View Post
What does ASSERT exactly do and how is it useful?
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.B
or
DC.W
or
INCBIN
data 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"
Note that here
*
is the address of the current location in the file. Think of it like the 68000 PC, but at assembly time. So
*-table
is 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"
And could quickly be fixed by adding the missing value.

This also works for externally incbined data:
Code:
table: 
	INCBIN "table.bin"
	ASSERT*-table==8,"Expect 8 bytes in table"
The assember can also perform maths for you, so you could confirm that the number of words in a 16x16 pixel 2-bitplane sprite was correct:

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
The left hand side of the assert is calculating the number of words of data defined. The right hand side is calculating the expected number of words of data: 2 control words at the start + 16 lines of two words each + 2 control words at the end.
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
Here's another real world example. Check that the size of the imported image matches the size expected by the code.

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
hop is offline  
Old 07 December 2023, 09:42   #35
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
Hard to explain. A combination of enough new features or important bug fixes, and the feeling that it has been sufficiently tested.
Hi. Thanks again for implementing the ASSERT directive. I make heavy use of it and couldn't live without it. It would be great if it could be released into the wider community so they could benefit too (and I wouldn't have to manage locally built exes )

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
hop is offline  
Old 07 December 2023, 20:01   #36
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
FWIW I usually use something like
Code:
  ifne *-8
  error assumptions changed!
  endc
for asserts, but it'd probably be nice with dedicated syntax even if it isn't portable
paraj is offline  
Old 10 December 2023, 12:09   #37
phx
Natteravn
 
phx's Avatar
 
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
But with ASSERT it does:
Code:
a:      move.l  #sym,d0
b:      rts
        assert  b-a==2,"not optimized"
sym     =       1
phx is offline  
Old 10 December 2023, 12:33   #38
hop
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!
hop 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
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

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

Top

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