flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > macro use inside repeat block: symbol already defined

Author
Thread Post new topic Reply to topic
redsock



Joined: 09 Oct 2009
Posts: 311
Location: Australia
Admittedly my board search skills are lacking, so apologies as I am sure this has already been asked before...

The below code results in:
Code:
repmacro.asm 14
                do_something
repmacro.asm 11 do_something 5
.label
error symbol already defined.    
... What is the correct way to do this? Code:
Code:
        format ELF64

public _start
_start

macro do_something 
        local   .label

        jmp     .label
        dd      1,2,3,4
.label

        repeat 8
                do_something
        end repeat

        mov     eax, 60         ; exit
        xor     edi, edi        ; return code
        syscall
    

_________________
2 Ton Digital - https://2ton.com.au/
Post 25 Oct 2016, 22:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
You will need to use rept.
Code:
        rept 8 
                do_something
            
When you use repeat the code inside is assembled multiple times. When you use rept the code inside is generated multiple times. You need the local label to be generated multiple times so that it is unique each time it is generated.
Post 25 Oct 2016, 22:06
View user's profile Send private message Visit poster's website Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 311
Location: Australia
thanks for that... rept versus repeat means that % can't be used ... so iteration counts have to be done manually then? e.g. the following code doesn't do what I want:
Code:
        format ELF64

public _start
_start

macro do_something i* 
        local   .label

        jmp     .label
        dd      i,i+1,i+2,i+3
.label

        rept 8 
                do_something %
        

        mov     eax, 60         ; exit
        xor     edi, edi        ; return code
        syscall
    

_________________
2 Ton Digital - https://2ton.com.au/
Post 25 Oct 2016, 22:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
You can use an iteration counter with rept:
Code:
rept 8 x 
  do_something x
    
Post 25 Oct 2016, 22:21
View user's profile Send private message Visit poster's website Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 311
Location: Australia
lol must've missed that in the docs, hahah, thx! Straight from the docs:
Code:
So this

    rept 3 counter
     
        byte#counter db counter
     

will generate lines

    byte1 db 1
    byte2 db 2
    byte3 db 3
    
Smile Care to delete my obvious idiotic questions for me then? hahah

As an aside, perhaps it is because of my "lean" use of macros in the first place that I have never had to use rept instead of repeat ... so much code and still learn new tricks Smile mucho gracias
Post 25 Oct 2016, 22:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16702
Location: In your JS exploiting you and your system
redsock wrote:
Care to delete my obvious idiotic questions for me then?
I won't delete it. This can be instructive to others.
Post 26 Oct 2016, 00:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.