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 |
|
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? |
|||
20 Sep 2003, 17:01 |
|
decard 21 Sep 2003, 10:13
Arrrgh... I found another stupid bug (with StrLen)... it's fixed now.
|
|||
21 Sep 2003, 10:13 |
|
decard 21 Sep 2003, 12:32
Right, it's better (only 26 bytes..), however it doesn't work with string handles
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 |
|||
21 Sep 2003, 12:32 |
|
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] |
|||
21 Sep 2003, 12:47 |
|
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 |
|||
21 Sep 2003, 12:48 |
|
decard 21 Sep 2003, 13:35
roticv: your routines doesn't know about string handles. Can you fix it?
|
|||
21 Sep 2003, 13:35 |
|
JohnFound 21 Sep 2003, 15:01
decard wrote: John, No, I don't think this is good solution. 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. |
|||
21 Sep 2003, 15:01 |
|
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 |
|||
21 Sep 2003, 15:18 |
|
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 |
|||
25 Sep 2003, 16:35 |
|
JohnFound 25 Sep 2003, 19:23
Thank you Decard.
I will implement it in Fresh tomorow. At first glance - good work. |
|||
25 Sep 2003, 19:23 |
|
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. 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 |
|||
26 Sep 2003, 13:31 |
|
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 |
|||
26 Sep 2003, 13:39 |
|
decard 26 Sep 2003, 13:53
IMO libproc is the best
So I will wait for those macros, and I will not add "if used XXX", right? JohnFound wrote:
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 |
|||
26 Sep 2003, 13:53 |
|
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. |
|||
26 Sep 2003, 15:37 |
|
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 ) Please, help a little. Regards. |
|||
26 Sep 2003, 15:47 |
|
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 |
|||
26 Sep 2003, 16:53 |
|
JohnFound 26 Sep 2003, 17:35
Hi, scientica.
I am glad that you have an inspiration. 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. |
|||
26 Sep 2003, 17:35 |
|
scientica 26 Sep 2003, 22:09
JohnFound wrote: Hi, scientica. 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 |
|||
26 Sep 2003, 22:09 |
|
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 |
|||
27 Sep 2003, 09:21 |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.