flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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). ![]() The meaning of the first example is obviously a structure with a double word for length of string, followed by the string. |
|||
![]() |
|
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 |
|||
![]() |
|
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. |
|||
![]() |
|
kamac 06 Dec 2013, 17:20
That's neat
![]() I'm quite green so I'll ask - do I have to use ecx in the 1st example, or is this only convenction? |
|||
![]() |
|
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? |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.