flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > AT&T nested macros to FASM: solving 'symbol already defined'

Author
Thread Post new topic Reply to topic
raoul



Joined: 03 Aug 2021
Posts: 2
raoul
Hi,

For further learning after 'Hello World', I am attempting a remake of JonesForth, originally writen in GAS. I am stuck on translating the following, where the defvar macro passes its arguments to a nested defcode macro:

Code:
        .macro defcode name, namelen, flags=0, label
        .section .rodata
        .align 4
        .globl name_\label
name_\label :
        .int link               // link
        .set link,name_\label
        .byte \flags+\namelen   // flags + length byte
        .ascii "\name"          // the name
        .align 4                // padding to next 4 byte boundary
        .globl \label
\label :
        .int code_\label        // codeword
        .text
        //.align 4
        .globl code_\label
code_\label :                   // assembler code follows
        .endm

        .macro defvar name, namelen, flags=0, label, initial=0
        defcode \name,\namelen,\flags,\label
        push $var_\name
        NEXT
        .data
        .align 4
var_\name :
        .int \initial
        .endm
    


... with example uses:

Code:
defcode "XOR",3,,XOR    // bitwise XOR
        pop %eax
        xorl %eax,(%esp)
        NEXT

defvar "S0",2,,SZ
    


My attempts that result in:

Quote:
Error: symbol already defined << link dd name_SZ >> forth.asm


Code:
macro defcode nm,namelen,flags:0,label {
section 'rodata' readable
align 8
name_#label#:
 link dd name_#label
 db flags + namelen
 db `nm
align 8
label#:
 dd code_#label
section 'text' readable executable
code_#label#:
}

macro defvar name,namelen,flags:0,label,initial:0 {
defcode name,namelen,flags,label
 push var_#name
 NEXT
section 'data' readable writable
align 8
var_#name#:
 dd initial
}
    


I tried to sprinkle some 'local' declarations, which modifies the error without improving my understanding of the issue at hand. Would you please help a beginner? Thanks!
Post 04 Aug 2021, 00:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18220
Location: In your JS exploiting you and your system
revolution
The label "link" is being defined for each invocation of defcode.

You don't appear to be using that label so you can remove it:
Code:
name_#label#:
 dd name_#label  ; <-- no need to put the 'link' label here
 db flags + namelen    
Post 04 Aug 2021, 03:01
View user's profile Send private message Visit poster's website Reply with quote
raoul



Joined: 03 Aug 2021
Posts: 2
raoul
Ah yes, thank you! I was so fixated on the 'name_#label' part that I forgot about the 'link' part.

Now, I have another error but clearly I don't understand the code well enough because 'link' is used elsewhere, so back to studying I guess! :-S
Post 04 Aug 2021, 07:30
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.