04 January 2024, 18:19 | #1 |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Redefining or undefining vasm macros
I'm trying to use vasm to assemble a disk image containing file binaries and associated file table, using a C preprocessor pattern. Here's a contrived example:
FileList.h: Code:
// n.b. No include guards in this header, which is designed to be included multiple times in the same compilation unit. #ifndef FILE_LIST_MACRO #error FILE_LIST_MACRO is not defined #endif FILE_LIST_MACRO(FileA); FILE_LIST_MACRO(FileB); ... #undef FILE_LIST_MACRO // allow macro to be redefined Code:
#define FILE_LIST_MACRO(T) static File* Get##T() {...} #include "FileList.h" #define FILE_LIST_MACRO(T) static int GetSize##T() {...} #include "FileList.h" FileList.inc: Code:
FILE_MACRO caves_.cms FILE_MACRO city__.cms Code:
FILE_MACRO2 caves_.cms FILE_MACRO2 city__.cms Code:
ORG 0 INCLUDE "bootblock" ORG $400 FILE_TABLE_OFFSET EQU $50000 FILE_TABLE_SIZE_BYTES EQU $1800 ; original format ORG FILE_TABLE_OFFSET ; Use vasm macros to generate file table MACRO FILE_MACRO ; \1 = file name DC.B '\1' ; filename DCB.B 16-\?1,0 ; zero-pad to 16 bytes DC.L \1 ; disk address DC.L \1_SIZE_BYTES ; size in bytes ENDM INCLUDE "FileList.inc" ASSERT *-FILE_TABLE_OFFSET<=FILE_TABLE_SIZE_BYTES ORG FILE_TABLE_OFFSET+FILE_TABLE_SIZE_BYTES Files: MACRO FILE_MACRO2 ; want to re-use FILE_MACRO here \1: INCBIN "Files/\1" \1_SIZE_BYTES: EQU *-\1 ENDM INCLUDE "FileList2.inc" ; want to include FileList.inc here DiskImage.asm: Code:
ORG 0 INCLUDE "bootblock" ORG $400 FILE_TABLE_OFFSET EQU $50000 FILE_TABLE_SIZE_BYTES EQU $1800 ; original format ORG FILE_TABLE_OFFSET ; Use vasm macros to generate file table MACRO FILE_MACRO ; \1 = file name DC.B '\1' ; filename DCB.B 16-\?1,0 ; zero-pad to 16 bytes DC.L \1 ; disk address DC.L \1_SIZE_BYTES ; size in bytes ENDM INCLUDE "FileList.inc" ASSERT *-FILE_TABLE_OFFSET<=FILE_TABLE_SIZE_BYTES ORG FILE_TABLE_OFFSET+FILE_TABLE_SIZE_BYTES Files: MACRO FILE_MACRO \1: INCBIN "Files/\1" \1_SIZE_BYTES: EQU *-\1 ENDM INCLUDE "FileList.inc" Code:
error 3007: undefined symbol <city__.cms_SIZE_BYTES> error 3007: undefined symbol <city__.cms> error 3007: undefined symbol <caves_.cms_SIZE_BYTES> error 3007: undefined symbol <caves_.cms> Is it possible to achieve this? Thanks for any advice. Last edited by hop; 04 January 2024 at 18:28. Reason: Correction |
05 January 2024, 02:09 | #2 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
Quote:
Good news is that vasm can indeed undefine macros. But the mot-syntax module doesn't implement any directive to do that. Only madmac-syntax offers macundeffor now. And then there might also be a bug, which I should address soon: The second macro definition with the same name shouldn't be accepted without error message (but I have to check other assemblers first). Before you ask: Yes, maybe I could implement a macro-undef directive for mot-syntax. But I have rarely seen one among assemblers following the Motorola syntax, and I would prefer to adopt a directive which is commonly used instead of inventing new ones. |
|
05 January 2024, 11:09 | #3 | ||
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
Quote:
Using filenames as labels was a bad idea too! Filenames starting with numbers (5000pts.bal) didn't work with the macro and filenames containing hyphens (bonus--1.ald) were no good as labels. I tried renaming (invasive), and prefixing the generated labels with an underscore e.g. _\1 and hit further problems that I didn't understand. I couldn't see how to use the the unique id / global id / stack to connect the labels in the generated output of two seperate sets of macro invokations. I've come to the conclusion that programatically generated assembly language in the build pipeline is the way to go. Far more flexible and straightforward. Thanks again. EDIT: Is it possible to view the generated vasm asm after macro expansion? Last edited by hop; 05 January 2024 at 11:44. |
||
05 January 2024, 16:45 | #4 | |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 866
|
Quote:
Should at least throw a warning. |
|
05 January 2024, 17:09 | #5 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
|
Yes, by accident it will even work most of the time, as the new macro is seen before the old one in the hash table.
Quote:
Quote:
Quote:
Code:
abc macro dc.l \1 endm abc 1 abc macro dc.b "\1",0 endm abc hej Code:
Source: "tst.s" 1: abc macro 2: dc.l \1 3: endm 4: 5: abc 1 00:00000000 00000001 1M dc.l 1 6: 7: abc macro 8: dc.b "\1" 9: endm 10: 11: abc hej 00:00000004 68656A 1M dc.b "hej" 12: Agreed. Fixed it. You may try tomorrow's source snapshot. |
|||
07 January 2024, 17:20 | #6 | |
Registered User
Join Date: Apr 2019
Location: UK
Posts: 172
|
Quote:
vasm 1.9a: 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 binary output module 2.1 (c) 2002-2021 Volker Barthelmann and Frank Wille CODE(acrx1): 8 bytes Code:
vasm 2.0beta (c) in 2002-2024 Volker Barthelmann vasm M68k/CPU32/ColdFire cpu backend 2.6c (c) 2002-2023 Frank Wille vasm motorola syntax module 3.18 (c) 2002-2023 Frank Wille vasm binary output module 2.3b (c) 2002-2023 Volker Barthelmann and Frank Wille error 89 in line 7 of "test.asm": macro redefinition >abc macro * The terminal process "C:\Amiga\Crack\VenusTheFlytrap\BuildTest.bat" terminated with exit code: 1. Of course. Can't belive I didn't think to look. Thanks. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Question about XREF vs XDEF (vasm 1.8 vs vasm 1.9) | roondar | Coders. Asm / Hardware | 8 | 01 May 2023 20:59 |
vasm - Use defined object code in macros/expressions? | dansalvato | Coders. Asm / Hardware | 2 | 24 March 2022 01:38 |
vasm/mot: macros | sparhawk | Coders. Asm / Hardware | 8 | 06 January 2020 18:32 |
VASM macros/equates for registers | jotd | Coders. Asm / Hardware | 5 | 06 September 2019 18:47 |
Macros for debugging in VASM | mcgeezer | Coders. Asm / Hardware | 11 | 14 May 2019 15:27 |
|
|