English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Asm / Hardware (https://eab.abime.net/forumdisplay.php?f=112)
-   -   vasm - symbols in label names? (https://eab.abime.net/showthread.php?t=106440)

girv 31 March 2021 16:02

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.

roondar 31 March 2021 16:39

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 ;)

phx 31 March 2021 21:21

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


Exodous 31 March 2021 21:29

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.

roondar 01 April 2021 09:10

Ah, of course!
For some reason I thought REPTN couldn't be used as a macro argument :confused

Good to know it can.

phx 01 April 2021 11:29

Quote:

Originally Posted by roondar (Post 1474318)
For some reason I thought REPTN couldn't be used as a macro argument :confused

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.

roondar 01 April 2021 11:34

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?

phx 01 April 2021 11:41

Quote:

Originally Posted by roondar (Post 1474334)
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...

girv 02 April 2021 12:31

Thanks, a clever trick. I have other loops like this with 24 and more iterations so it will be nice to tidy those up!


All times are GMT +2. The time now is 21:59.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04425 seconds with 11 queries