flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > There has to be a macro for this (strings in code)

Author
Thread Post new topic Reply to topic
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 05 Sep 2004, 19:52
Basically, i would like to have:

Code:
section '.text'
main:
string name, "Hello World!!"
push name
call printf
add esp, 4

ret
    


Or something similar. Are there any macro solutions? Or am i thinking to hard...
Post 05 Sep 2004, 19:52
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 05 Sep 2004, 21:12
You'd probably want to put the strings in a '.data' section, but this should work for zero terminated strings:

Code:
macro string id, value {
  id db value, 0
}    
Post 05 Sep 2004, 21:12
View user's profile Send private message Visit poster's website Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 06 Sep 2004, 00:14
The point of the macro is to put the string into the '.data' section automatically

Else i would just jump the string.
Post 06 Sep 2004, 00:14
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 06 Sep 2004, 00:27
Just to let you know, i already read:
http://board.flatassembler.net/topic.php?t=1166

And it doesn't suit this specific purpose. However... I think i'll start using it anyway.

I'll try a bit better this time with the explanation of what i want...

Code:
section '.text'
main:
string name, "Hello World!!"
push name
call printf
add esp, 4

ret
    


Should turn into:

Code:
section '.text'
main:
push name
call printf
add esp, 4

ret

section '.data'
name db "Hello World!!", 0
    
Post 06 Sep 2004, 00:27
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 06 Sep 2004, 01:27
There is a globals.inc in fresh includes you could find useful.
Post 06 Sep 2004, 01:27
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Sep 2004, 14:57
yes, include globals inc and then yours macro is:
Code:
macro string,name,data
{
  iglobal
   name db,data,0
  endg
}
    
Post 06 Sep 2004, 14:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 06 Sep 2004, 16:56
Hopefully i can change that to:

Code:
struc string, [data]
{
  iglobal
   name db,data,0
  endg
} 
    


Right?
Post 06 Sep 2004, 16:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 07 Sep 2004, 18:30
yes (except that you didn't declare "name" argument), but it would be faster this way
Code:
struc string, [name,data]
{
  common
    iglobal
  forward
      name db data,0
  common
    endg
}
    

or (if you want one nam for all strings)
Code:
struc string, [name,data]
{
  common
    iglobal
    label name byte
  forward
    db data,0
  common
    endg
}
    
Post 07 Sep 2004, 18:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Sep 2004, 07:08
The last one should be:
Code:
struc string, name, [data]
    


btw, there is a macro "constStr" in "globals.inc" that works similar way.

Regards.
Post 08 Sep 2004, 07:08
View user's profile Send private message Visit poster's website ICQ Number 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.