English Amiga Board


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

 
 
Thread Tools
Old 04 January 2020, 18:07   #1
sparhawk
Registered User
 
sparhawk's Avatar
 
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
sparhawk is offline  
Old 04 January 2020, 19:29   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
Quote:
Originally Posted by sparhawk View Post
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?
No. Macros are handled like new directives.
phx is offline  
Old 04 January 2020, 21:51   #3
sparhawk
Registered User
 
sparhawk's Avatar
 
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?
sparhawk is offline  
Old 04 January 2020, 22:57   #4
sparhawk
Registered User
 
sparhawk's Avatar
 
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
I put some debug messages in there to see whats going on:

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>
The output is
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
But here it doesn't evaluate like expected

Code:
MESSAGE_START 1=MAX_COPPERLINES : 2=24 : 3=60 : 60
MESSAGE_END 1=MAX_COPPERLINES : 2=24 : 3=60 : MAX_COPPERLINES=24
So as you can see, param 2 is 24 and param 3 is 60, so why is the result suddenly 24? And why does it work as expected in the first case?
sparhawk is offline  
Old 04 January 2020, 23:04   #5
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Wow! I just found it.

it should be
Code:
    if \2<=\3
I had spaces in the comparison which caused this. After removing them it works now.
sparhawk is offline  
Old 06 January 2020, 14:54   #6
sparhawk
Registered User
 
sparhawk's Avatar
 
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
But I get an error that the expression must be const, which IMO it is.
sparhawk is offline  
Old 06 January 2020, 17:55   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
Quote:
Originally Posted by sparhawk View Post
I had spaces in the comparison which caused this. After removing them it works now.
Like with Devpac, a white-space character in the operand ends the operand field and starts the comment field. This can be turned off by the -spaces option.

I think the default behaviour is what most people from the Amiga/Atari world would expect. But I might be wrong.

Quote:
Originally Posted by sparhawk View Post
What is considered a constant expression?
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:
But I get an error that the expression must be const, which IMO it is.
I guess the error message was caused by the REPT?
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.
phx is offline  
Old 06 January 2020, 18:19   #8
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
Quote:
Originally Posted by phx View Post
Like with Devpac, a white-space character in the operand ends the operand field and starts the comment field. This can be turned off by the -spaces option.

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:
I guess the error message was caused by the REPT?
Yes.


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.

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

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.
sparhawk is offline  
Old 06 January 2020, 18:32   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,538
Quote:
Originally Posted by sparhawk View Post
But if a symbol is defined with '=' or with 'EQU' it can not change anymore, right? Otherwise I would get an error.
You cannot reassign it with a different expression. But in an optimizing assembler the values of all labels will constantly change with every pass.

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.
Sure. And I think I wrote that.

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.
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
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

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 15:48.

Top

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