04 January 2020, 18:07 | #1 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
vasm/mot: macros
I tried to create a MAX macro to set a symbol with the highes value.
Code:
MACRO MAX_VALUE IF \1 >= \2 \1 ELSE \2 ENDIF ENDM MAX_COPPERLINES SET 0 MAX_COPPERLINES SET MAX_VALUE MAX_COPPERLINES,10 MAX_COPPERLINES SET MAX_VALUE MAX_COPPERLINES,12 When I use it like this, then MAX_COPPERLINES is set to MAX_VALUE instead of the result of the macro. Is a macro not an expression? I thought that this would evaluate the macro first and then the result is assigned to the symbol. I rewrote it now to this version which works, but of course is not as generic as the one above: Code:
MACRO MAX_VALUE IF \1 >= \2 \3 SET \1 ELSE \3 SET \2 ENDIF ENDM MAX_COPPERLINES SET 0 MAX_COPPERLINES2 SET 10 MAX_COPPERLINES3 SET 12 MAX_VALUE MAX_COPPERLINES, MAX_COPPERLINES2, MAX_COPPERLINES MAX_VALUE MAX_COPPERLINES, MAX_COPPERLINES3, MAX_COPPERLINES |
04 January 2020, 19:29 | #2 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
|
|
04 January 2020, 21:51 | #3 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Is there some way to print a message so that I can output the current value of a symbol?
|
04 January 2020, 22:57 | #4 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
I created this macro, but for some reason it doesn't work, when I use it a second time.
Code:
SET_MAX MACRO IF \2 >= \3 \1 SET \2 ELSE \1 SET \3 ENDIF ENDM Code:
SET_MAX MACRO PARAM1 set \1 PARAM2 set \2 PARAM3 set \3 FAIL MESSAGE_START 1=\1 : 2=\<PARAM2> : 3=\<PARAM3> : \<MAX_COPPERLINES> IF \<PARAM2> >= \<PARAM3> \1 SET \2 ELSE \1 SET \3 ENDIF FAIL MESSAGE_END 1=\1 : 2=\<PARAM2> : 3=\<PARAM3> : MAX_COPPERLINES=\<MAX_COPPERLINES> ENDM MAX_COPPERLINES SET 0 CopperStartList: dc.w $0180,COLOR_BAR_CURTAIN dc.w (COPPER_START_LINE<<8+$01),$ff00 dc.w $0180,COLOR_BAR_CURTAIN_BOTTOM dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe dc.w $ffff,$fffe CopperStartListSize = *-CopperStartList SET_MAX MAX_COPPERLINES,CopperStartListSize,<MAX_COPPERLINES> CopperStartListPAL: dc.w $0180,COLOR_BAR_CURTAIN dc.w $ff01,$ff00 dc.w $ffe1,$fffe dc.w $0000, $ff00 dc.w $0180,COLOR_BAR_CURTAIN_BOTTOM dc.w $ffff,$fffe CopperStartListPALSize = *-CopperStartListPAL SET_MAX MAX_COPPERLINES,CopperStartListPALSize,<MAX_COPPERLINES> Code:
Here it is correct MESSAGE_START 1=MAX_COPPERLINES : 2=60 : 3=0 : 0 MESSAGE_END 1=MAX_COPPERLINES : 2=60 : 3=0 : MAX_COPPERLINES=60 Code:
MESSAGE_START 1=MAX_COPPERLINES : 2=24 : 3=60 : 60 MESSAGE_END 1=MAX_COPPERLINES : 2=24 : 3=60 : MAX_COPPERLINES=24 |
04 January 2020, 23:04 | #5 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Wow! I just found it.
it should be Code:
if \2<=\3 |
06 January 2020, 14:54 | #6 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
What is considered a constant expression?
I have this code Code:
CopperList: dc.w $0180,$000 dc.w $3c01,$ff00 dc.w $0180,$0fff dc.w $ffe1,$fffe dc.w $0000,$ff00 dc.w $0180,$0f00 dc.w $ffff,$fffe CopperListLines = ((*-CopperList)/4) InitCopper: lea CopperList,a0 move.l CopperListPtr,a1 rept CopperListLines move.l (a0)+,(a1)+ endr rts |
06 January 2020, 17:55 | #7 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
|
Quote:
I think the default behaviour is what most people from the Amiga/Atari world would expect. But I might be wrong. An expression which can be evaluated as a constant at any time. Even in the first assembler pass. Which means, it cannot include undefined symbols (even symbols defined later in the source), labels or differences between labels. Quote:
Hmm... perhaps I was too cautious to require a known, constant value here, but a repetition with a varying count is likely calling for trouble. Note that vasm is a multi-pass assembler, which does so many passes until the perfect optimization in all locations is found. You are right that CopperListLines is constant and defined in this case, but the assembler does not know if the space between * and CopperList may contain instructions which can be optimized or not. Or Alignments, which change their size because optimizations before CopperList took place in a later pass. |
||
06 January 2020, 18:19 | #8 | ||||
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Quote:
Yes. I was using -spaces before, but that causes other problems (don't remember right now what this was), so I'musing this now. I have to get used to this. Caused a lot of "bugs" because I almost automatically write spaces. Quote:
Quote:
But if a symbol is defined with '=' or with 'EQU' it can not change anymore, right? Otherwise I would get an error. Only if the symbol is defined with 'SET' it can be changed. Quote:
Hm.. But since these are hard coded values declared with 'dc' they can not be optimized (or modified) in any way, right? They should always be constant. |
||||
06 January 2020, 18:32 | #9 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
|
Quote:
Quote:
The problem is that the assembler is not intelligent enough to know what is between two labels. It only sees an expression with label2-label1. There may be everything in between. |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
vasm/mot: structure | guy lateur | Coders. Asm / Hardware | 20 | 05 January 2020 00:01 |
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 |
vasm/mot: data structures | guy lateur | Coders. Asm / Hardware | 10 | 29 December 2018 22:15 |
vasm/mot: include failed error message | guy lateur | Coders. Asm / Hardware | 6 | 23 December 2018 20:29 |
|
|