20 April 2022, 18:21 | #1 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
VASM assert directive
Is there a way to use ASSERT directives with the vasm motorola syntax module?
I wrote a ZX Spectrum Next game using sjasmplus and it was great to be able to do stuff like this: Code:
; 9-bit colour palette spritePalette: ; RRR'GGG'BB B DB %000'000'00,%0 ; $00 black DB %111'111'11,%1 ; $01 white DB %011'011'11,%1 ; $02 blue-grey DB %011'111'01,%1 ; $03 green-grey DB %111'011'01,%1 ; $04 red-grey DB %111'000'00,%0 ; $05 red DB %000'111'00,%0 ; $06 green DB %000'000'11,%1 ; $07 blue DB %111'111'00,%0 ; $08 yellow DB %111'101'00,%0 ; $09 orange DB %101'101'10,%1 ; $0a light grey DB %010'010'01,%0 ; $0b dark grey DB %111'100'10,%0 ; $0c pink (invader bullets) ASSERT ($ - spritePalette) % 2 == 0 ; expect even number of bytes SPRITE_PALETTE_COUNT EQU ($ - spritePalette) / 2 ; number of colours ASSERT SPRITE_PALETTE_COUNT <= 256 ufoPattern: DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$0a,$0a,$0a,$0a,$0a,$0a,$00,$00,$00,$00,$00 DB $00,$00,$00,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$00,$00,$00 DB $00,$00,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$00,$00 DB $00,$0a,$0a,$0a,$09,$09,$0a,$08,$08,$0a,$09,$09,$0a,$0a,$0a,$00 DB $0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a,$0a DB $0a,$0b,$0a,$0b,$0b,$0a,$0b,$0b,$0b,$0b,$0a,$0b,$0b,$0a,$0b,$0a DB $0a,$00,$0a,$00,$00,$0a,$00,$00,$00,$00,$0a,$00,$00,$0a,$00,$0a DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ASSERT $-ufoPattern == 256 |
20 April 2022, 20:10 | #2 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
With some conditional assembly you could easily reach the same effect: Code:
ifne (*-spritePalette)%2 fail odd address endif Last edited by phx; 20 April 2022 at 20:39. Reason: Bad workaround |
|
20 April 2022, 20:16 | #3 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
I'm using this in asm-one/pro, similar to assert (IF2 = assembler is in pass 2):
Code:
_CHECK MACRO (CC, Value1, Value2) IF2 IF\1 (\2)-(\3) PRINTT "\2 is *\1* \3." PRINTV (\2)-(\3) FAIL ENDIF ENDIF ENDM CHECKEQ MACRO (Value1, Value2) _CHECK NE,\1,\2 ENDM CHECKNE MACRO (Value1, Value2) _CHECK EQ,\1,\2 ENDM CHECKGT MACRO (Value1, Value2) _CHECK LE,\1,\2 ENDM CHECKLT MACRO (Value1, Value2) _CHECK GE,\1,\2 ENDM |
20 April 2022, 20:37 | #4 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Only works with two-pass assemblers. vasm parses the source only once, but uses a variable number of passes until the optimization is perfect (can be hundreds of passes). But it's good that you mentioned IF2, because the reason for its existence is that conditional assembly doesn't work very well with optimizations and multiple passes. So the workaround I have shown above it useless. The IFNE is evaluated only during initial parsing and later changes due to optimizations are not recognized (which is bad when testing label differences). So there is a reason for an ASSERT directive to exist. Because it is not affected by these problems. It evaluates the expression in the final pass only. As vasm doesn't really support IF2, an ASSERT directive might make sense... |
|
20 April 2022, 20:58 | #5 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
I would do the above example this way for 68k :
Code:
SPRITE_PALETTE_COUNT set 0 dbx macro dc.w \1 SPRITE_PALETTE_COUNT set SPRITE_PALETTE_COUNT +1 endm spritePalette: dbx %000000000 ; $00 black dbx %111111111 ; $01 white dbx %011011111 ; $02 blue-grey dbx %011111011 ; $03 green-grey dbx %111011011 ; $04 red-grey dbx %111000000 ; $05 red dbx %000111000 ; $06 green dbx %000000111 ; $07 blue dbx %111111000 ; $08 yellow dbx %111101000 ; $09 orange dbx %101101101 ; $0a light grey dbx %010010010 ; $0b dark grey dbx %111100100 ; $0c pink (invader bullets) ; use of dc.w implies even number of bytes ifgt SPRITE_PALETTE_COUNT - 256 fail endc |
20 April 2022, 20:59 | #6 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Thanks for the insight and suggestions. I don't want to encourage divergence in assembler syntax, so I think macros sound like the way to go.
I usually use asserts to verify data size, struct member offsets (for code that makes assumptions) in which case optimisations would not affect them. This is assuming that like a C compiler, the assembler will never modify data structures or data. It would however be nice to assert section sizes which would be affected by optimisations though. |
20 April 2022, 21:23 | #7 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Code:
ds.b label2-label1 Quote:
Otherwise I would probably settle for assert <expression>[,<optional message on failure>] |
||
20 April 2022, 23:14 | #8 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
|
21 April 2022, 13:23 | #9 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Done.
assert <expr>[,<msg>]will be in tomorrow's daily source snapshot (and the next release). |
21 April 2022, 21:05 | #10 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Excellent. Many thanks.
How do you decide when to release? |
22 April 2022, 00:38 | #11 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Hard to explain. A combination of enough new features or important bug fixes, and the feeling that it has been sufficiently tested.
|
22 April 2022, 20:56 | #12 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
Code:
set VBCC_VERSION=2022-03-23 ... SET VBCC_BIN_ZIP=vbcc_bin_win64.zip ... curl -O http://phoenix.owl.de/vbcc/%VBCC_VERSION%/%VBCC_BIN_ZIP% I can't see vbcc daily binaries at http://sun.hasenbraten.de/vbcc/ so I guess I need to download the vasm daily binaries from http://sun.hasenbraten.de/vasm/index.php?view=bincur but which one do I want from the list to get the equivalent (to cross-compile on win64 for classic Amiga OS (1.3/2.0/3.2))?
Or do I need to build from source? |
|
22 April 2022, 22:53 | #13 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Quote:
Quote:
|
|||
23 April 2022, 09:32 | #14 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,099
|
Attached is a build for 64-bit windows. Only did some very light testing to check out the feature, so there might be issues with it, that won't be present in an official release. Obviously completely unsupported, so use at your own risk.
Also note that you can't use it in devpac or phxass compatibility mode, and if you're used to the latter you probably want to add "-spaces" to the command line |
23 April 2022, 11:50 | #15 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
23 April 2022, 20:09 | #16 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,099
|
Yes, absolutely reasonable, I was just trying to preempt possible questions based on my own quick interaction. I tried it a random project and it didn't work => Ah, phxass mode enabled => Nothing works => Need "-spaces"
|
23 April 2022, 21:15 | #17 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Thanks very much. It will be very reassuring to be able to plonk the binary in place and (static_)assert
|
24 April 2022, 11:33 | #18 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
ASSERT seems to be doing the job. Many thanks.
|
24 May 2022, 13:44 | #19 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
ASSERT in action
Code:
move.l (a2)+,d1 ; hunkIndex ; calcuate byte offset into RootHunk array IF 0 mulu #RootHunk_SIZEOF,d1 ELSE ASSERT RootHunk_SIZEOF==8 lsl.w #3,d1 ; more optimal, but brittle ENDIF movea.l #rootHunks,a4 ; first RootHunk movea.l RootHunk_Address(a4,d1.w),a4 ; referenced hunk address |
24 May 2022, 15:51 | #20 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Although you could also write
IF RootHunk_SIZEOF==8in this example, so there would be no need for ASSERT. |
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 |
|
|