flat assembler
Message board for the users of flat assembler.

Index > Main > Problems with labels inside macros

Author
Thread Post new topic Reply to topic
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 15 Aug 2006, 19:38
Hi, I have this code in one file:

format MZ
org 100h
include 'functions.inc'
jmp main
msg db 'Hello World!', 13, 10, 0

main:
lea si, [msg]
PrintString

lea si, [msg]
PrintString

; ***************
; End of code
; ***************

and in the "functions.inc" file I have this code:

macro PrintString
{
print:
mov ah,0Eh
start:
lodsb
cmp al,0
jz exit
int 10h
jmp start
exit:
}

When I try to compile I get this error: "Symbol already defined"
I can figure out that the problem is becouse the compiler replace the "PrintString" instruction in the main file with all the code inside "PrintString" macro, so when the compiler do this, all the labels appears more than once.
If I just call the PrintString macro only one time, there is no problema, but if I call more than one time, problem appears.
In masm I used to use "proc's", but in fasm I couldn't find this possibility.
So, how can I solve this problem ?
Post 15 Aug 2006, 19:38
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 15 Aug 2006, 19:52
To solve the problem with the macros do this:

Code:
macro PrintString
{
local print, start, exit
.
.
.
} 
    


But since this is a macro it must be defined before any use of it. And for proc check the FASM examples, you have proc32.inc, there is no 16 bit version but you can try with this (without warranties) http://board.flatassembler.net/topic.php?p=40011#40011

Regards


Last edited by LocoDelAssembly on 15 Aug 2006, 19:56; edited 1 time in total
Post 15 Aug 2006, 19:52
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 15 Aug 2006, 19:54
You probably don't want to use a macro. Just use this instead:
Code:
format MZ
org 100h
include 'functions.inc'
jmp main
msg db 'Hello World!', 13, 10, 0

main:
lea si, [msg]
call PrintString

lea si, [msg]
call PrintString
    

Code:
PrintString:
.print:
mov ah,0Eh
.start:
lodsb
cmp al,0
jz .exit
int 10h
jmp .start
.exit:
    

This is equivalent to using "proc".
If you really want to use a macro, then you will have to use "local" to "localize" the variables print,start and exit.
BTW: Enclose your code in [code] tags, since it allows scrolling and syntax highlighting.
Post 15 Aug 2006, 19:54
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 15 Aug 2006, 20:11
Thanks for the answers.

I'm not using any Os behind, I have my own boot diskette who provides me the option to run a file, this is just for test.
The thing is that I wanted to use something like proc in masm, but if it doesn't exists I have to be satisfied with the UCM's option.


PS: Sorry for the untags code.
Post 15 Aug 2006, 20:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 15 Aug 2006, 20:24
Or test proc16.inc, it provides stack frame variables which can be useful for you. However, if you want full control of what is get assembled then use UCM's option.
Post 15 Aug 2006, 20:24
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.