flat assembler
Message board for the users of flat assembler.

Index > Windows > new version of dynamic string library

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 20 Sep 2003, 17:01
roticv wrote:
:/ Grr.. irritating... txt file not accepted.


Use .asm extension instead .txt - We are assembly programmers, isn't it? Very Happy
Post 20 Sep 2003, 17:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 21 Sep 2003, 10:13
Arrrgh... Mad I found another stupid bug (with StrLen)... it's fixed now.
Post 21 Sep 2003, 10:13
View user's profile Send private message Visit poster's website Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv 21 Sep 2003, 12:00
hmmm can remove some bytes
Code:
StrLen:       ; proc StrLen [hString]
     mov     eax,[esp+4]             ; mov eax,[hString]
 stdcall StrPtr,eax
 .scan:
   cmp     byte[eax],0
 lea     ecx,[eax+1]
 jnz     .scan
       sub     eax, [esp+4]
        dec     eax                     ; return value in eax
       ret     4
    
Post 21 Sep 2003, 12:00
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 21 Sep 2003, 12:32
Right, it's better (only 26 bytes..), however it doesn't work with string handles Sad

I had to change it:
Code:
StrLen:    ; proc StrLen [hString]
        push    ebx      ; esp = esp-4
        mov     eax,[esp+4+4]      ; mov eax,[hString]
        stdcall StrPtr,eax
        mov     ebx,eax
  .scan:
        cmp     byte[eax],0
        lea     eax,[eax+1]
        jnz     .scan
        sub     eax,ebx
        dec     eax         ; return value in eax
        pop     ebx
        ret     4    

(28 bytes)

btw: going this way soon we will have the fastest StrLen in the world Very Happy
Post 21 Sep 2003, 12:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 21 Sep 2003, 12:47
What about:
Code:
        push    dword [esp+4+4]
        call    StrPtr     
?
This is anyway the same as:
Code:
        stdcall StrPtr,[esp+4+4]    
Post 21 Sep 2003, 12:47
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 21 Sep 2003, 12:48
John,

When coding a routine that inserts one string into another I realized that I could make NumToStr to create new string only, and inserting number into the string could be done this way:
Code:
       stdcall NumToStr, 255, ntsHex
      stdcall StrInsert,hString,eax,8    


if hString="total 0x bytes" after that code it will be "total 0xFF bytes"

IMO this solution is more flexible, as you don't have to care about space for numbers when creating strings. Also, it will make NumToStr much simpler...

What do you think?

btw: thanks, Privalov!

regards
Post 21 Sep 2003, 12:48
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 21 Sep 2003, 13:35
roticv: your routines doesn't know about string handles. Can you fix it?
Post 21 Sep 2003, 13:35
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 21 Sep 2003, 15:01
decard wrote:
John,
When coding a routine that inserts one string into another I realized that I could make NumToStr to create new string only, and inserting number into the string could be done this way:
Code:
       stdcall NumToStr, 255, ntsHex
      stdcall StrInsert,hString,eax,8    


if hString="total 0x bytes" after that code it will be "total 0xFF bytes"

IMO this solution is more flexible, as you don't have to care about space for numbers when creating strings. Also, it will make NumToStr much simpler...

What do you think?


No, I don't think this is good solution.Sad At first this trick works only with dynamic strings, but NumToString should work with static strings the same way as with handles. At second, the problem is, that to create 2 strings and to insert one to another is double work. Better to put the result directly in his place in the target string. If you optimise the routines to the level of removing stack frames, making the source less readable, go to the end and make everything the proper way. Wink
Post 21 Sep 2003, 15:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv 21 Sep 2003, 15:18
decard wrote:
roticv: your routines doesn't know about string handles. Can you fix it?

Okay, I will look into it. Thanks for telling me
Post 21 Sep 2003, 15:18
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 25 Sep 2003, 16:35
Hi!

That's current version of StrLib. Several new functions were added. It is almost compatybile with previous version, except for one thing: now NumToStr is more complex, stdcall routine. Previous version is renamed to _NumToStr.

regards

(attachment removed - new version is posted below)


Last edited by decard on 29 Sep 2003, 16:14; edited 2 times in total
Post 25 Sep 2003, 16:35
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 25 Sep 2003, 19:23
Thank you Decard.
I will implement it in Fresh tomorow.
At first glance - good work. Smile
Post 25 Sep 2003, 19:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 26 Sep 2003, 13:31
Hi, decard.
Here are my small fixes after reaching working Fresh with it. My fixes are marked with "JohnFound" word.
NumToStr is not complete. Please make something. Smile
Here are another two my procedures about number to string convertion, but for fixed width strings. You may use them in NumToStr together with _NumToStr and _NumToStrU.
BTW, We have to use "if used" statements to make only used subroutines to be included in the program. I will try include this approach in proc macro to make it more smart to avoid using of enter/leave when there is no local variables.
Code:
;***********************************************
; NumToStrF:
;   Converts signed integer value to string.
; NumToStrUF:
;   Converts unsigned integer value to string.
;
; EDI - pointer to string buffer
; EAX - Number to convert
; ECX - radix from 2 to $ff
; EBX - length of the number in chars
;
; Note: Don't use 1 as radix.
;************************************

if used NumToStrF

NumToStrF:

        test    eax,eax
        jns     NumToStrUF
        neg     eax
        mov     byte [edi],'-'

        push    ebx

        dec     ebx
        add     edi,ebx
        jmp     .loopc

end if

if used NumToStrUF

NumToStrUF:
        push    ebx
        add     edi, ebx
        dec     edi

.loopc:
        xor     edx,edx
        div     ecx

        xchg    al,dl
        cmp     al,$0a
        sbb     al,$69
        das

        mov     [edi],al
        dec     edi
        xchg    al,dl


        dec     ebx
        jnz     .loopc

        pop     ebx
        ret

end if
    


Regards.

[edit]Outdated file removed[/edit]


Last edited by JohnFound on 16 May 2004, 23:58; edited 1 time in total
Post 26 Sep 2003, 13:31
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 26 Sep 2003, 13:39
JohnFound wrote:
BTW, We have to use "if used" statements to make only used subroutines to be included in the program. I will try include this approach in proc macro to make it more smart to avoid using of enter/leave when there is no local variables.

A (few) name suggestion(s) for that proc macro:
libproc, LibProc, libProc, lproc, lib_proc
As it's a kind of source library, I think something with lib is suitable. What do you think?

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 26 Sep 2003, 13:39
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 26 Sep 2003, 13:53
IMO libproc is the best Very Happy

So I will wait for those macros, and I will not add "if used XXX", right?

JohnFound wrote:

NumToStr is not complete. Please make something. Smile


What do you mean? To add things like resizing destination string when the number doesn't fit in it? Or maybe I forgot about something?

regards
Post 26 Sep 2003, 13:53
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 26 Sep 2003, 15:37
Hi decard.

About NumToStr: Yea, I am talking about resizing/check bounds. If you don't know the length of the number string, simply resize with maximal length for given radix, string buffer can be longer than string itself. Don't forget that [str] can be pointer and in this case you can't resize - simply convert without check. If you use _NumToStrF and _NumToStrFU - you can use uniform approach: "call ebx" for every set of flags.
I think that the code must be a little bit ordered and optimised and it will become smaller and simpler.

About macroses: the name will be simply "proc" because this "if used" approach is useful not only for libs but for user program too. Here is my versions:

Code:
macro proc name,[arg]                   ; define procedure
 { common
    if used name
      name:
      virtual at ebp+8
      if ~ arg eq
     forward
       local ..arg
       ..arg dd ?
       arg equ ..arg
     common
       end if
       ..ret = $ - (ebp+8)
      end virtual
      local ..dynamic_data,..dynamic_size
      dynamic_data equ ..dynamic_data
      dynamic_size equ ..dynamic_size
      virtual at ebp - dynamic_size
       dynamic_data: }

macro enter                             ; begin procedure instructions
 { rb (4 - ($-dynamic_data) and 11b) and 11b
   dynamic_size = $ - dynamic_data
   end virtual

   if dynamic_size = 0
     push ebp                     ; smaller is dynamic_size = 0
     mov  ebp, esp
   else
     enter dynamic_size,0
   end if
 }

macro return                            ; return from procedure
 {
     leave
     ret ..ret
   else
     display 'Procedure skipped',$0d, $0a
   end if
 }    


Replace this macroses in "StdCall.inc"

You still must put "if" statements on _NumToStr etc. because they don't use "proc" macro - they are not "stdcall" procedures.

Thanks.
Regards.
Post 26 Sep 2003, 15:37
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 26 Sep 2003, 15:47
Question for Privalov:

Hi. Please look at the above macroses. The idea is to output messages what procedures are not included in the output file. But I can't make "display" to display the name of the label. You are macro expert. (naturally Smile )
Please, help a little. Smile

Regards.
Post 26 Sep 2003, 15:47
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 26 Sep 2003, 16:53
I've got some feature request on the strlib, it would be great with some kind of string search function and a substring function.
Here is an proposal on how it can be done:
A function named substring (or "better_name"), with the following proto type:
proc substring, string, offset
which returns a pointer to the substring, for "plain" strings (string + offset) is returned, and for dynamic, well it's up to you, which you fnd the best, either a pointer to new dynmmic string which is the substring or the (real_string_address + offset)

proc strFind, string, what_to_find
returns the offset of the string "what_to_find" or (eax==-1 || CF==1) if the string wasn't found. The offset can be used with teh substring for dynamic strings, but can simply be added to "plain" strings.

you may discard my suggestions above, but I think that the strlib should have some kind of string search, it would make things easier (I'm trying to get the FPR working - I'm going to try to implement the strlib, a substring, strFind would make the work easier).
I'll try to post a draft on a common FPR comment style soon. (I've gotten some inspiration from the javadoc (it uses "/**", "*/" as special javadoc comments))

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 26 Sep 2003, 16:53
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 26 Sep 2003, 17:35
Hi, scientica.
I am glad that you have an inspiration. Smile

StrPos is search in string:
Code:
;**********************************************************************************
; StrPos returns a pointer to the first occurence of a pattern string
;   in another string
; Arguments:
;   hPattern - 'pattern' string
;   hString -  string to search
; Returns: a pointer to the pattern string in source , or NULL if pattern string
; doesn't occur in the string to search
;**********************************************************************************    


About SubString, you are right - we need such function.

Regards.
Post 26 Sep 2003, 17:35
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 26 Sep 2003, 22:09
JohnFound wrote:
Hi, scientica.
I am glad that you have an inspiration. Smile

StrPos is search in string:

Hi, feels good to have inspiration again (haven't felt like doing anything for sometime, plus a few test in school). Btw, I've tried to run Fresh in linux (using Wine), after I updated wine I got it to run but it crashes in some GUI32.dll function (probably a bug in wine).

I missed the StrPos, I only took a quick look in (the latest) strlib. I'm not quite finished with the draft, but tomorrow it should be done.

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 26 Sep 2003, 22:09
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 27 Sep 2003, 09:21
do you mean something like this:
Code:
substring:
    mov eax,[esp+4]      ; first parameter
    stdcall StrPtr,eax
    add eax,[esp+8]       ; second parameter
    ret 8    


creating new handle to existing string could cause problems with string resizing and with unallocating string's memory, but it can be done... Do you think you will need this?

Now StrLib has almost 20 functions, and they are described in source, so it is quite easy to miss some feature. In next release I will try to create some .txt file and put there description of all routines, and general information about StrLib.

regards
Post 27 Sep 2003, 09:21
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:  
Goto page Previous  1, 2, 3  Next

< 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.