flat assembler
Message board for the users of flat assembler.

Index > Main > Multiple data under a label

Author
Thread Post new topic Reply to topic
kamac



Joined: 06 Dec 2013
Posts: 12
kamac 06 Dec 2013, 16:17
Hey there.

I have lately seen something like that:

Code:
constString:
  dd 3
  dw 97,98,99
    


And I've been wondering how does it work since. I know that if I have something like that:

Code:
constString:
  dw 97,98,99    


Then it is a simple constant "string" of wchars. But what about the 1st example? Is this something like pseudo-struct? (dd 3 would allocate a 4-byte integer, and after that there would be the wchar array? If yes, how would I access separate elements?)

Also, I have seen something like that in BlitzBasic's ASM code:
dd _bbStringClass

Does anybody have a clue what could it possibly be? (the _bbStringClass)

Cheers.
Post 06 Dec 2013, 16:17
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 06 Dec 2013, 16:55
Well constString is a label in your first example.
Could be followed by data of any type or even code (depending on segment rules).
Cool

The meaning of the first example is obviously a structure with a double word for length of string, followed by the string.
Post 06 Dec 2013, 16:55
View user's profile Send private message Send e-mail Reply with quote
kamac



Joined: 06 Dec 2013
Posts: 12
kamac 06 Dec 2013, 16:57
Okay, so constString would point to the 1st element here, which is a 4-byte integer?

How can I access 2nd element (which is dw 97,98,99)?

I access 1st by doing:
mov eax,constString
Post 06 Dec 2013, 16:57
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 06 Dec 2013, 17:09
No, this way you load the address of constString but not the first data.

Use:
Code:
mov ecx,[constString]
mov esi,constString+4
mov al,[esi]
    


This will initialize the counter register ecx with lenght of string and al with the first byte of the string. It is more comfortable to use lods (load string):

Code:
mov esi,constString
lodsd
mov ecx,eax
@@: lodsb
call printch
loop @b
    


Here you load esi with address of string.
lodsd loads a dword from [esi] in eax (the size)
lodsb loads a char from [esi] in al
loop repeats this as long as there are more characters.

Take notice that esi is automatically incremented after read depending on size. So lodsd will add 4 to esi and lodsb will increment by 1. There is a lodsw existing for reading words.

The same could be done with storing data using stos (store string), register edi instead of esi and instructions stosb, stosw, stosd in similar way.
Post 06 Dec 2013, 17:09
View user's profile Send private message Send e-mail Reply with quote
kamac



Joined: 06 Dec 2013
Posts: 12
kamac 06 Dec 2013, 17:20
That's neat Smile

I'm quite green so I'll ask - do I have to use ecx in the 1st example, or is this only convenction?
Post 06 Dec 2013, 17:20
View user's profile Send private message Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop 07 Dec 2013, 01:27
kamac wrote:
I'm quite green so I'll ask - do I have to use ecx in the 1st example, or is this only convenction?
yes cx is the counter register in all string instructions lods stos movs ect
Post 07 Dec 2013, 01:27
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.