i made macro named print as following :

print macro str
.data
x db str
.code
mov ax,seg x
mov ds,ax
mov ah,09
lea dx,x
int 21h
endm

it's worked very well when called for one time but when called 2 or more error message appears that is 'duplicated defining of x ... etc'
can some one give me solution to this problem i use masm 5.0 and calling like that

print 'hello world' for example

thank you

Macros aren't functions. When you use a macro the text of the macro is inserted verbatim into your code. Hence:

print macro str
.data
        x       db      str
.code
        mov     ax,     seg x
        ...

Gets used:

print "Hello"
print "world"

and becomes:

.data
        x       db      "Hello"
.code
        mov     ax,     seg x
        ...

.data
        x       db      "world"
.code
        mov     ax,     seg x
        ...

Which is the same as:

.data
        x       db      "Hello"
        x       db      "world"
.code
        ...

Why don't you just stick all your strings in the data segment with names to begin with? You can still use a macro:

.data
        str_hello db "Hello"
        str_world db "world"

.code
        print str_hello

thank you for answer
thats right but not enough because old basic have print which prints any thing you want ,as well i had develope macro easist than your method which is as following:

print   macro var,msg
          .data
     var  db  msg
          .code
      mov ax,seg var
      mov ds,ax
      mov ah,09
      lea dx,var
      int 21h
endm

      
when calling you just change var values like that:

           print v1,'hello'
           print v2,'world'
           print v3,'any thing'
for examples

and it still not enough as i see because i hope to make print exactly like basic .

BASIC is a high-level-language. Assembly is not. You can't think like BASIC in assembly.

BASIC actually has a named variable somewhere in the data segment. When you say PRINT "something" it first copies the string "something" over to the variable in the data segment, then prints that, basically like I showed you above. (In reality, it is a bit more complex than that, because of the way BASIC stores data in the data segment, but the essentials are the same.)

This article has been dead for over six months. Start a new discussion instead.