flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > String directives for manipulating text

Author
Thread Post new topic Reply to topic
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 14 Nov 2003, 19:13
Is it possible to code some Masm string manipulation directives for Fasm?

The directives are:

Code:
SUBSTR
 Assigns part of string to a new symbol.

INSTR
 Searches for one string within another.

SIZESTR
 Determines the size of a string.

CATSTR
 Concatenates one or more strings to a single string.
    


More detailed explanation at Masm programmer's guide / Chapter 9 - String Directives and Predefined Functions :

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_09.htm

_________________
Code it... That's all...
Post 14 Nov 2003, 19:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Nov 2003, 10:48
In fasm such things are usually done with combination of "virtual" and "load" directives.
And converting non-quoted symbols to strings and concatenations of string can be done with the latest prerelease (so these features will be included in 1.50).
Post 15 Nov 2003, 10:48
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 06 Dec 2003, 09:36
Hi Privalov,

How can I build the CATSTR macro with the "virtual" and "load" directives?

_________________
Code it... That's all...
Post 06 Dec 2003, 09:36
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 06 Dec 2003, 13:08
This one is done with # operator in latest fasm.
Post 06 Dec 2003, 13:08
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 07 Dec 2003, 19:59
Hi Privalov,

Thanks for your help. I am trying to build a kind of substr macro:

Code:
macro substr param
{
virtual at 0
 string db param
 load a0 byte from 0
 load a1 byte from 1
 load a2 byte from 2
 load a3 byte from 3
 load a4 byte from 4
end virtual
}
    


param is a quoted string like 'mystring'
In this macro,I can get the first five characters;but how can I define a symbolic constant containing the first x characters of param?
Or is it possible to extend the load directive for symbolic constants?

Example:

Code:
load mystr <byte number> from 0
    


Here,mystr is a symbolic constant and the byte number is any integer number for the load directive.

_________________
Code it... That's all...
Post 07 Dec 2003, 19:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 07 Dec 2003, 20:36
It's impossible, because directives operating on numbers, like "load" processed at assembly time, and symbolic constants (and macros) are processed by preprocessor.
But please tell for what purpose do you need such thing, so we can think about some other solution.
Post 07 Dec 2003, 20:36
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 08 Dec 2003, 11:12
Hi Privalov,

The substr ( + strcat) macro like in masm would be very usefull for fasm.
For example,finding the last character of a macro parameter to determine if it's an ANSI function:

Code:
MessageBoxA
    


I want to improve my scan and inc2inc tools, that's why I need these two macros.

Implementing these macros would enhance a lot Fasm.

_________________
Code it... That's all...
Post 08 Dec 2003, 11:12
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Dec 2003, 13:51
For such purpose this should be sufficient:
Code:
macro test apiname
{
  virtual at 0
   db apiname
   load last byte from $-1
  end virtual
  if last = 'A' | last = 'W'
   display apiname,' is an ANSI function.',13,10
  else
   display apiname,' is not an ANSI function.',13,10
  end if
}

test 'ExitProcess'
test 'MessageBoxA'    

I mean that you can always find a solution using the existing features - they are just a bit different, and the macros have to be designed the other way, but they are powerful, too.
Post 08 Dec 2003, 13:51
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 08 Dec 2003, 18:11
Privalov,

Thanks for the example.
I hope I will find a way to build the substr macro Very Happy

_________________
Code it... That's all...
Post 08 Dec 2003, 18:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Dec 2003, 19:39
Finding a way is not the main problem, the main problem is to convince me that it would really be neccessary to implement it, as I believe that every such problem can be solved actually by using the features fasm already has. You just have to design your macros using completely different methods - the "fasm way of thinking". And I don't like the idea of littering the fasm's syntax with new complicated constructs that are not really neccessary. When I implement some new feature into fasm, I try to solve as many problems as possible with very few, universal syntax extensions. This way I want to keep fasm simple and consistent, but powerful at the same time. That's why it sometimes takes me very long time before I decide to implement some new feature, as I'm always trying to invent the most simple and universal solution - hopefully I haven't failed yet...
And, BTW, when I was implementing the "load" directive with ability to load from already generated code, I also had in mind the method of doing all such operations on strings. And I thought it was enough - I was even able to make nice UTF-8 to Unicode conversion macro this way (look here).
Post 08 Dec 2003, 19:39
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 23 Mar 2004, 10:59
Hi Privalov,

With the new directive "store" added to Fasm pre-release 1.52, have I chance to code the string manipulation directives above?

_________________
Code it... That's all...
Post 23 Mar 2004, 10:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 23 Mar 2004, 12:14
Depends on what do you want to achieve. Remember that the "virtual", "load" and "store" are all assembly-time mechanism, and they involve a "philosophy of usage", which is a bit different from the one used in macros for MASM.
Post 23 Mar 2004, 12:14
View user's profile Send private message Visit poster's website Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 01 Apr 2004, 10:13
Hi Privalov,

Is it possible to have a new instruction assigning virtual strings to symbolic constants? For example:
Code:
virtual at 0
  db 'Flat assembler',0
end virtual

mystr assign 0
    


Here, the assign statement assigns the virtual string "Flat assembler" to the symbol constant mystr. The zero means that the strings starts at virtual address 0 Or because of technical reasons, instead of using symbolic constants, maybe we can think about creating some new type of variables accepting this style of assignment.

_________________
Code it... That's all...
Post 01 Apr 2004, 10:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 01 Apr 2004, 10:54
Impossible again for the reason that virtual blocks are processed by assembler, and symbolic constant by preprocessor.
Keep in mind that preprocessor is string-based only, and the assembler is value-based.
Post 01 Apr 2004, 10:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Aug 2004, 07:26
In my mind this is something that FASM really needs to be truly powerful and flexible. I have become so used the the TASM and MASM ability to do whatever I want with symbols and string manipulation that it has been a real headache to try to convert these programs to FASM style.

But all the same I still choose to use FASM and my assembler of choice because of the other features I can coax it to do.

I do not know enough of the FASM internals to properly understand the difficulty but could something like the ofllowing be possible:

Step 1: do normal preprocessing etc. before actual assembly.

Step 2: during assembly if we encounter command/directive/construct that requires assigning a string like the above we flag all points in the file with appropriate values and restart the preprocess at Step 1. Once all stings/etc. have been assigned then do the normal assemble and we're done.

Sorry if this seems naive or stupid but with many people wanting such a feature it might be worth considering how to solve this.
Post 31 Aug 2004, 07:26
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.