flat assembler
Message board for the users of flat assembler.
Index
> Windows > New to fasm! - Please, I need help! Goto page 1, 2 Next |
Author |
|
revolution 22 Dec 2008, 23:05
db and du are the basic string definers. dword is only suitable for short strings and tchar is a structure/macro. You can use any of them you like, is all depends upon your requirement for the code.
If you want to avoid lodsb you can always directly code the two instructions: mov al,[esi]/inc esi But they are not exactly the same because lodsb does not alter the flags. |
|||
22 Dec 2008, 23:05 |
|
LocoDelAssembly 23 Dec 2008, 00:29
Quote:
Lets fix that mov al, [esi]/lea esi, [esi+1] Yet, this is still not exactly the same, do you see why? (not counting code difference) |
|||
23 Dec 2008, 00:29 |
|
madmatt 23 Dec 2008, 01:29
you use 'du' for unicode strings:
Code: ustring du "a unicode string",0. use 'db' for ASCII strings: Code: astring db "an ASCII string", 0 dd is used rarely for 'data identifier' of 4 ASCII characters: Code: tag dd 'DATI' You usually don't put a zero at the end of the data identifier string. |
|||
23 Dec 2008, 01:29 |
|
revolution 23 Dec 2008, 01:40
LocoDelAssembly wrote: Yet, this is still not exactly the same, do you see why? (not counting code difference) |
|||
23 Dec 2008, 01:40 |
|
LocoDelAssembly 23 Dec 2008, 02:44
Quote:
|
|||
23 Dec 2008, 02:44 |
|
shoorick 23 Dec 2008, 06:14
TCHAR is usefull if you wish your string will automatically depend on currently selected mode (ansi or unicode), what is determining with including or "win*a*.inc", either "win*w*.inc".
|
|||
23 Dec 2008, 06:14 |
|
revolution 23 Dec 2008, 06:29
LocoDelAssembly wrote:
Code: mov al,[esi] push ecx pushfd pop ecx shl ecx,31-10 ;DF is bit 10 sar ecx,31 or ecx,1 lea esi,[esi+ecx] pop ecx |
|||
23 Dec 2008, 06:29 |
|
baldr 23 Dec 2008, 10:35
revolution,
Memory below esp should be considered volatile, isn't it? |
|||
23 Dec 2008, 10:35 |
|
revolution 23 Dec 2008, 11:05
In real mode, yes. In ring3 PM mode, no.
Although, in general, it is not good practice to rely on something that is below the stack pointer. |
|||
23 Dec 2008, 11:05 |
|
baldr 23 Dec 2008, 19:40
revolution,
I'd meant generic case, regarding interrupt/trap through gate with DPL==CPL. Some amendments to your code: Code: mov al, [esi] push ecx pushfd bt dword [esp], 10 sbb ecx, ecx lea esi, [esi+1+2*ecx] popfd pop ecx _________________ "Don't belong. Never join. Think for yourself. Peace." – Victor Stone. |
|||
23 Dec 2008, 19:40 |
|
revolution 24 Dec 2008, 06:21
Code: mov al,[esi] pushf bt word[esp],10 sbb esi,0 bt word[esp],10 cmc adc esi,0 popf |
|||
24 Dec 2008, 06:21 |
|
Alexander 12 Jan 2009, 13:48
Hello,
Thank you for all your answers ! The difference between unicode and ansi/ascii is absolutly clear, but when do I use a string, defined with du, and when do I use TCHAR? Can you please give me an example. And here another question: How do I iterate (count a string's length) in an NASM32 Dll's exported function, which takes a "VB6" string (or any Win32/Win64 string) as an argument. Which string do I choose? Would you please be so kind to give me an example too? Thank you in advance Alexander |
|||
12 Jan 2009, 13:48 |
|
revolution 12 Jan 2009, 14:03
TCHAR is just a macro that is defined by the "win32[a|w].inc" file. If you include the "a" version you get bytes strings with TCHAR, if you include the "w" version you get word strings. That is all. It is a convenience for C code to be bi-textual, that is, the same source code can be either ASCII or UNICODE simply by using the TCHAR operator. In assembly the distinction is much more pronounced and making the code bi-textual is much more complicated and thus TCHAR is not as useful as with C.
|
|||
12 Jan 2009, 14:03 |
|
vid 12 Jan 2009, 14:06
My advice would be: don't use TCHAR. If you need unicode string, use du, otherwise use db.
I am not sure which kind of string is used by VB6. Win32/64 APIs use both ASCII string (defined by "db") and unicode string (defined by "du"). Those which take ascii string end with A (like MessageBoxA), and those which take unicode string end with W (like MessageBoxW) |
|||
12 Jan 2009, 14:06 |
|
Alexander 12 Jan 2009, 14:13
Thank you revolution and thank you vid.
So it is better to use du instead of tchar. Okay ... my first question is now clear. But the second one ... when I'm coming from a programming language, like VB6 or C# other than NASM, my string has wrong values. Could you please give me an example how I'm able to iterate through a string? |
|||
12 Jan 2009, 14:13 |
|
revolution 12 Jan 2009, 14:30
Alexander: To "iterate through a string" just use lodsb/lodsw, when you come to a zero value then you've reached the end. I don't know why you are against using lodsb/lodsw. For a newbie I think you shouldn't try be fussy about which instructions you don't want to use.
|
|||
12 Jan 2009, 14:30 |
|
Alexander 12 Jan 2009, 14:41
I'm not against lodsb or lodsw. But I think I've problems accessing a BSTR (VB6 and .NET ie C# or VB.NET work internally with BSTRs). BSTRs are organized like the following:
Length prefix (4 Bytes) | datastring (2 Bytes * Length) | NULL (2 Bytes) I think what I'm accidently accessing is the BSTR-Length prefix. I think that's the reason why I get "wrong values". Normally a pointer to a BSTR should point to the data, not to the length prefix itself. I know the following question is a stupid one : But what shall I do? Thank you |
|||
12 Jan 2009, 14:41 |
|
revolution 12 Jan 2009, 15:11
Just add 4 to your pointer before accessing the data words. You could also read the first 4 bytes and thus get the length into a register and then start iterating through your string with lodsw until your counter reaches zero.
|
|||
12 Jan 2009, 15:11 |
|
Alexander 12 Jan 2009, 15:16
Thank you for all your help!
Alexander |
|||
12 Jan 2009, 15:16 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.