flat assembler
Message board for the users of flat assembler.
Index
> Windows > String functions Goto page 1, 2, 3, 4 Next |
Author |
|
revolution 05 Feb 2013, 12:23
Can we assume you use ccall convention? Edit: No wait, you didn't seen to use any convention that I can tell. You destroy registers seemingly randomly.
Also, you posted in the Windows section and some of those function are already provided by the Windows API. |
|||
05 Feb 2013, 12:23 |
|
Kazyaka 05 Feb 2013, 12:29
I'm using stdcall to call the procedures.
Here's a pice of my code: Code: ... stdcall StringCopy,[SymbolStart],[SymbolBuffer],[SymbolLenght] ;Checks if first string is keyword stdcall StringCmpCS,[SymbolBuffer],"Hello" ... |
|||
05 Feb 2013, 12:29 |
|
revolution 05 Feb 2013, 12:36
Kazyaka wrote: I'm using stdcall to call the procedures. |
|||
05 Feb 2013, 12:36 |
|
Kazyaka 05 Feb 2013, 12:47
Thanks for note. I'm beginner FASM programmer and I didn't know about this. You mean that I should use proc/endp macros, right? But what if it works fine with wrong construction, I have to use it? Or maybe is some other way to correctly call my procedures without changing them?
|
|||
05 Feb 2013, 12:47 |
|
revolution 05 Feb 2013, 13:32
You don't have to use proc/endp, they are only for convenience, you can do it manually if you want to.
Also, it won't work fine with the wrong construction in all cases. There are some situations where they will work but don't expect it all to be fine when using stdcall as you caller. Your test code is probably not worried about stack or register preservation so it won't show a problem for you until you start using it in a real program. I would suggest you change the functions to conform with your caller function. It is less confusing and easier to integrate into other code. |
|||
05 Feb 2013, 13:32 |
|
JohnFound 05 Feb 2013, 14:04
Kazyaka, I am sure, you want to see FreshLib/data/strlib.asm library. It is full of string functions. Although, this library uses slightly different string format in order to provide dynamically sized strings.
|
|||
05 Feb 2013, 14:04 |
|
Kazyaka 05 Feb 2013, 14:41
revolution,
Quote: You don't have to use proc/endp, they are only for convenience, you can do it manually if you want to. Doing it manually only impedes the work. So if I've to change my procedures I'd to use proc/endp macros. Quote: Also, it won't work fine with the wrong construction in all cases. There are some situations where they will work but don't expect it all to be fine when using stdcall as you caller. Your test code is probably not worried about stack or register preservation so it won't show a problem for you until you start using it in a real program. That's right. It explains some odd bugs. Now I can see sense of following your way. Quote:
Like this? Code: include 'win32ax.inc' .code start: stdcall StringCopy,text,empty,5 invoke MessageBox,HWND_DESKTOP,empty,"Title",MB_OK invoke ExitProcess,0 proc StringCopy uses esi edi ecx,str1,str2,len mov esi,[str1] mov edi,[str2] mov ecx,[len] rep movsb ret endp .end start text db "Hello, my Friend!",0 empty rb 10 Please say me, if something's wrong. JohnFound, I already have FreshLib on my computer (I downloaded it 2 days ago), but it's easier to read when all string manipulation functions are on the one side. So thanks. However I still can't find "StringReplace" procedure. |
|||
05 Feb 2013, 14:41 |
|
revolution 05 Feb 2013, 14:50
Kazyaka wrote: Like this? Also it might be a good idea to always ensure you return a zero terminated string. Your "empty" display only works because the previous storage at that location had a zero byte in the sixth position. In many real programs you can't always be sure what the next byte will be so placing an explicit zero byte is generally a good idea. |
|||
05 Feb 2013, 14:50 |
|
AsmGuru62 05 Feb 2013, 15:22
There is no need for any conventions in ASM -- they are needed only for CALLBACK functions in Win API.
If you design your own string functions - you can do whatever you wish. Just describe in a function header what exactly your function does and how it accepts parameters and returns results. I have a function like this one in my library: Code: Lib_StrCopy: ; ----------------------------------------------------------------- ; INPUT: ; ESI = source string ; EDI = destination buffer ; OUTPUT: ; EDI = points to a NULL terminator in destination buffer ; ----------------------------------------------------------------- ... ret I use it to concatenate text. That is why ASM allows for great coding freedom. |
|||
05 Feb 2013, 15:22 |
|
HaHaAnonymous 05 Feb 2013, 15:23
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:42; edited 1 time in total |
|||
05 Feb 2013, 15:23 |
|
revolution 05 Feb 2013, 15:31
AsmGuru62 & HaHaAnonymous: Yes, of course you can use whatever calling format you please but the OP here stated they were using stdcall so there was clearly a problem. I only suggested to change the function to conform, an alternative could have been to simply change the caller to agree with the functions.
However not using any standard (whether stdcall, ccall or some other private standard) can get very confusing for larger programs. It is up to the programmer how they wish to do call/ret, but consideration should be given to potential bug reduction at a small cost in size/speed. Often spending days chasing an obscure bug easily loses to using more uniform call/ret procedures. |
|||
05 Feb 2013, 15:31 |
|
f0dder 05 Feb 2013, 15:46
AsmGuru62 wrote: There is no need for any conventions in ASM -- they are needed only for CALLBACK functions in Win API. almost true - if you STD, you'll need to CLD calling APIs, you'll need to make sure the stack is aligned (and within the limits set by [fs:whatever]), and probably a couple of other things as well... but sure, you're free to wildly trash registers in your own code, as long as it's not callback... whether it's a good idea is an open question _________________ - carpe noctem |
|||
05 Feb 2013, 15:46 |
|
HaHaAnonymous 05 Feb 2013, 15:51
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:42; edited 1 time in total |
|||
05 Feb 2013, 15:51 |
|
Picnic 05 Feb 2013, 17:19
Kazyaka wrote: However I still can't find "StringReplace" procedure. See szRep (szreplac.asm) inside masm32 package, it should be fairly easy to use in fasm. |
|||
05 Feb 2013, 17:19 |
|
HaHaAnonymous 05 Feb 2013, 17:31
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:42; edited 1 time in total |
|||
05 Feb 2013, 17:31 |
|
AsmGuru62 05 Feb 2013, 17:47
String replacement is fun to code -- especially with some weirdo testing code, like:
1. Replace "AA" in "123-AAAAAAAAAAAA-456" with "AAA". 2. Replace "AAAA" in "123-AAAAAAAAAAAA-456" with "A". |
|||
05 Feb 2013, 17:47 |
|
Kazyaka 05 Feb 2013, 19:59
How many replies... you took over the thread. It's an invasion!
I don't know where to start, so I begin from the end. AsmGuru62, AsmGuru62 wrote: String replacement is fun to code -- especially with some weirdo testing code, like: I don't understand. Do you think, it will loop infinitely at the first case and remove all "A" characters at the second, or what? In my point of view, it's just a normal code. The correctly working functions should return: Code: 1. "123-AAAAAAAAAAAAAAAAAA-456" 2. "123-AAA-456" HaHaAnonymous, It's not as easy as you think (for me). If you want to replace string as in the first case above, you must use some memory management functions like GlobalAlloc or HeapAlloc, because the size of replaced string can be much more then before function call. It only complicates matters. Picnic, Picnic wrote: See szRep (szreplac.asm) inside masm32 package, it should be fairly easy to use in fasm. Thanks for information. I'm going to check it for a while. @To all: I see that your opinions are divided. So I've a question: can I use functions from the first post with a clear conscience, or not? By the way, thank you all for your replies. You're making this word better! |
|||
05 Feb 2013, 19:59 |
|
baldr 05 Feb 2013, 20:06
Kazyaka wrote: How many replies... you took over the thread. It's an invasion! Guys, don't you think that delimited arbitrary length strings should be banned from existense in favor of counted strings? Delphi style looks intimidating. |
|||
05 Feb 2013, 20:06 |
|
f0dder 05 Feb 2013, 20:26
baldr wrote: Guys, don't you think that delimited arbitrary length strings should be banned from existense in favor of counted strings? Indeed - length-counted strings are both faster as well as safer to work with. Re-creating libc style functions is just madness _________________ - carpe noctem |
|||
05 Feb 2013, 20:26 |
|
Goto page 1, 2, 3, 4 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.