English Amiga Board


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

 
 
Thread Tools
Old 20 April 2022, 18:21   #1
hop
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
I can see that the vasm MadMac module suports 'assert' and hoping there is a way to enable it for MOT.
hop is offline  
Old 20 April 2022, 20:10   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hop View Post
Is there a way to use ASSERT directives with the vasm motorola syntax module?
It could be added in a minute. Probably 2 or 3 lines of C code. The reason why it's not there is that I have never seen an Assert directive in common Amiga assemblers, like Devpac, etc., and I don't like to introduce new vasm-only directives, which make source texts incompatible.

With some conditional assembly you could easily reach the same effect:
Code:
        ifne    (*-spritePalette)%2
        fail    odd address
        endif
EDIT: I was too fast. This is a bad workaround to check label differences in an optimizing assembler. See below.

Last edited by phx; 20 April 2022 at 20:39. Reason: Bad workaround
phx is offline  
Old 20 April 2022, 20:16   #3
a/b
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
a/b is online now  
Old 20 April 2022, 20:37   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by a/b View Post
I'm using this in asm-one/pro, similar to assert (IF2 = assembler is in pass 2):
Oh yes, IF2...
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...
phx is offline  
Old 20 April 2022, 20:58   #5
meynaf
son of 68k
 
meynaf's Avatar
 
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
meynaf is offline  
Old 20 April 2022, 20:59   #6
hop
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.
hop is offline  
Old 20 April 2022, 21:23   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hop View Post
This is assuming that like a C compiler, the assembler will never modify data structures or data.
Yes. Usually there is nothing to optimize in pure data. But directives to declare storage may use expressions depending on labels:
Code:
        ds.b    label2-label1
Quote:
It would however be nice to assert section sizes which would be affected by optimisations though.
I guess I will add an assert to mot-syntax. If anybody knows such a directive from a 68k assembler, then please tell me the syntax, so I don't invent something new.

Otherwise I would probably settle for
assert <expression>[,<optional message on failure>]
phx is offline  
Old 20 April 2022, 23:14   #8
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
I guess I will add an assert to mot-syntax.
That would be great thanks, as long as you are sure it's the right decision. Perhaps a command line option would be required to enable it in case pre-existing projects that define 'assert' break.
hop is offline  
Old 21 April 2022, 13:23   #9
phx
Natteravn
 
phx's Avatar
 
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).
phx is offline  
Old 21 April 2022, 21:05   #10
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Excellent. Many thanks.

How do you decide when to release?
hop is offline  
Old 22 April 2022, 00:38   #11
phx
Natteravn
 
phx's Avatar
 
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.
phx is offline  
Old 22 April 2022, 20:56   #12
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
Quote:
Originally Posted by phx View Post
Done.
assert <expr>[,<msg>]
will be in tomorrow's daily source snapshot (and the next release).
Please forgive me but I am a bit confused by all the combinations of downloads. I approached Amiga OS programming from C, and have now descended into assembly. My "update_dependencies.bat" script is set to:

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%
So I am using vasm from the vbcc binary package.

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))?
  1. vasmm68k_mot_os3.lha 22 Apr 2022 02:17:03 (190506 bytes)
  2. vasmm68k_std_os3.lha 22 Apr 2022 02:19:25 (186955 bytes)
  3. vasmppc_std_os3.lha 22 Apr 2022 02:20:18 (154705 bytes)
  4. vasmm68k_mot_mos.lha 22 Apr 2022 02:22:55 (230575 bytes)
  5. vasmm68k_std_mos.lha 22 Apr 2022 02:25:30 (226048 bytes)
  6. vasmppc_std_mos.lha 22 Apr 2022 02:26:23 (191261 bytes)
  7. vasmm68k_mot_os4.lha 22 Apr 2022 02:29:02 (243367 bytes)
  8. vasmm68k_std_os4.lha 22 Apr 2022 02:31:37 (237368 bytes)
  9. vasmppc_std_os4.lha 22 Apr 2022 02:32:32 (201691 bytes)
  10. vasmm68k_mot_TOS.zip 22 Apr 2022 02:35:11 (183026 bytes)
  11. vasmm68k_std_TOS.zip 22 Apr 2022 02:37:49 (179669 bytes)
  12. vasmm68k_mot_MiNT.zip 22 Apr 2022 02:40:11 (186157 bytes)
  13. vasmm68k_std_MiNT.zip 22 Apr 2022 02:42:32 (182488 bytes)

Or do I need to build from source?
hop is offline  
Old 22 April 2022, 22:53   #13
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hop View Post
so I guess I need to download the vasm daily binaries from http://sun.hasenbraten.de/vasm/index.php?view=bincur
Correct.

Quote:
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))?
Unfortunately there are no Windows executables for daily source snapshots. We only build those for official releases.

Quote:
Or do I need to build from source?
Yes. Or wait for the release. Or ask somebody to compile it. But not me, because I have no Windows cross compiler installed. Volker does that, whenever there is a release.
phx is offline  
Old 23 April 2022, 09:32   #14
paraj
Registered User
 
paraj's Avatar
 
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
Attached Files
File Type: 7z vasmm68k_mot_win32_20220423.7z (183.8 KB, 37 views)
paraj is offline  
Old 23 April 2022, 11:50   #15
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by paraj View Post
Attached is a build for 64-bit windows.
Tak skal du have!

Quote:
Also note that you can't use it in devpac or phxass compatibility mode
That's the least I could do to make people aware that they are using a vasm-only directive.
phx is offline  
Old 23 April 2022, 20:09   #16
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,099
Quote:
Originally Posted by phx View Post
That's the least I could do to make people aware that they are using a vasm-only directive.
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"
paraj is offline  
Old 23 April 2022, 21:15   #17
hop
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
hop is offline  
Old 24 April 2022, 11:33   #18
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
ASSERT seems to be doing the job. Many thanks.
hop is offline  
Old 24 May 2022, 13:44   #19
hop
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
hop is offline  
Old 24 May 2022, 15:51   #20
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Although you could also write
IF RootHunk_SIZEOF==8
in this example, so there would be no need for ASSERT.
phx 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 01:07.

Top

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