English Amiga Board


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

 
 
Thread Tools
Old 31 March 2021, 16:02   #1
girv
Mostly Harmless
 
girv's Avatar
 
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
vasm - symbols in label names?

I have some unrolled loops that look a bit like this, with the loop body in a macro 'TDMR1COL'.

Code:
move.l      .td_mr1_jt(pc,d5.w),a5
jmp         (a5)

.td_mr1_jt:
dc.l        .td_mr1_1
dc.l        .td_mr1_2
dc.l        .td_mr1_3
dc.l        .td_mr1_4
dc.l        .td_mr1_5
dc.l        .td_mr1_6
dc.l        .td_mr1_7
dc.l        .td_mr1_8

TDMR1COL:    MACRO
.td_mr1_\1: ...
ENDM

TDMR1COL    8
TDMR1COL    7
TDMR1COL    6
TDMR1COL    5
TDMR1COL    4
TDMR1COL    3
TDMR1COL    2
 TDMR1COL    1

Is there a way to set up something like this with a REPT (or two) in vasm? I can't see a way to construct the .td_mr1_X labels automatically by including a symbol generated from the repeat count in a label name, either a REPTN or a SET-value.
girv is offline  
Old 31 March 2021, 16:39   #2
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
I'd be really interested in knowing if this is possible as well. I've not found any way to do it, but that doesn't mean it can't be done
roondar is offline  
Old 31 March 2021, 21:21   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
It is possible, although not in a very elegant way. If you look into the mot-syntax documentation you see that the special macro argument
\<symbolname>
is supported (same syntax as Devpac?). It will insert the current decimal value of the absolute symbol with that name.

So you can solve the problem by defining a helper-macro, like
Code:
TDMR1COL_REPTN  macro
CNT     set     8-REPTN
        TDMR1COL \<CNT>
        endm
Then run your REPT-loop with it:
Code:
        rept    8
        TDMR1COL_REPTN
        endr
phx is offline  
Old 31 March 2021, 21:29   #4
Exodous
Registered User
 
Join Date: Sep 2019
Location: Leicester / England
Posts: 201
This is pretty much what I used to do in Devpac.

I've put some tabs in your code and added an 'rts' into your macro:

Code:
	moveq	#4,d5	; Just so this is within the table.

	move.l      .td_mr1_jt(pc,d5.w),a5
	jmp         (a5)

.td_mr1_jt:
	dc.l        .td_mr1_1
	dc.l        .td_mr1_2
	dc.l        .td_mr1_3
	dc.l        .td_mr1_4
	dc.l        .td_mr1_5
	dc.l        .td_mr1_6
	dc.l        .td_mr1_7
	dc.l        .td_mr1_8

TDMR1COL    MACRO
.td_mr1_\1:	rts
ENDM

	TDMR1COL    8
	TDMR1COL    7
	TDMR1COL    6
	TDMR1COL    5
	TDMR1COL    4
	TDMR1COL    3
	TDMR1COL    2
	TDMR1COL    1
Saved it as "test.s" then assembled this with:

Code:
vasmm68k_mot -devpac -Fhunkexe test.s -o test
EDIT: Actually, the "-devpac" option isn't necessary as it still assembles and works without it

And get the following result:

Code:
vasm 1.8j (c) in 2002-2020 Volker Barthelmann
vasm M68k/CPU32/ColdFire cpu backend 2.3n (c) 2002-2020 Frank Wille
vasm motorola syntax module 3.14c (c) 2002-2020 Frank Wille
vasm hunk format output module 2.13 (c) 2002-2020 Frank Wille

CODE(acrx2):	          56 bytes
Which results in a binary file "test", which runs successfully and exits.
Exodous is offline  
Old 01 April 2021, 09:10   #5
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
Ah, of course!
For some reason I thought REPTN couldn't be used as a macro argument

Good to know it can.
roondar is offline  
Old 01 April 2021, 11:29   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by roondar View Post
For some reason I thought REPTN couldn't be used as a macro argument
It can't. The text given as macro arguments is never interpreted in any way, but just pasted into the macro source text at the positions marked with \1, \2, etc...

So when you call the original macro as
TDMR1COL REPTN
, you will get eight times the same label
.td_mr1_REPTN:
as REPTN is regarded being part of the label name.

Therefore you have to use
\<symbol>
within the macro to make the parser insert the current symbol's value instead. It has nothing to do with any argument given to the macro.

EDIT: Maybe I confused you by designating
\<symbol>
as "special macro argument", like all other codes starting with '\' within a macro. These escape codes always insert some text, but only in some cases this text will be directly taken from an argument given to the macro. Refer to the documentation.

Last edited by phx; 01 April 2021 at 11:36. Reason: Special macro argument
phx is offline  
Old 01 April 2021, 11:34   #7
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
I see, I misread that macro.
So, am I then correct in saying that the workaround is that you set a symbol to a value based on REPTN in a macro and then you expand that symbol in the same macro?
roondar is offline  
Old 01 April 2021, 11:41   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by roondar View Post
So, am I then correct in saying that the workaround is that you set a symbol to a value based on REPTN in a macro and then you expand that symbol in the same macro?
Exactly. Of course, you can also use REPTN directly, when its value suits you.
EDIT: Within
\<REPTN>
of course...

Last edited by phx; 01 April 2021 at 11:42. Reason: \<symbol>
phx is offline  
Old 02 April 2021, 12:31   #9
girv
Mostly Harmless
 
girv's Avatar
 
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
Thanks, a clever trick. I have other loops like this with 24 and more iterations so it will be nice to tidy those up!
girv 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: Access to a local label litwr Coders. Language 4 23 October 2020 15:54
VASM - not getting debug symbols mcgeezer Coders. Asm / Hardware 3 09 August 2018 11:09
Matching device names with volume names. Thorham Coders. System 2 27 July 2015 12:20
User Symbols in ReSource selco Coders. General 3 11 April 2015 21:26
SAS/C: Undefined symbols Yesideez Coders. C/C++ 14 13 February 2014 16:36

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

Top

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