Hi.

I notice an interesting property of data variables declared in the .DATA section. For example, when you use BYTE swapping i.e. BYTE PSTR VariableName + #bytes, you could actually go belong the memory addresses of that a variable, which in this example is VariableName.

-----
.DATA

varOne DB 'testing 1 2 3'
varTwo DW 'September 2002'
...
...

mov ax, WORD PTR DB + 12
-----

In the last line above, the code will make a copy of "3" and "S." ASM is interesting because when you declare variables in .DATA, variables get memory locations right after one another. I am most familiar with C++. In C++, you have no idea where memory gets allocated.

Is it valid that in ASM memory gets allocated continuously, or is it random?

Thanks,
Kuphryn
Posted on 2002-09-18 02:00:54 by kuphryn


Is it valid that in ASM memory gets allocated continuously, or is it random?


Its allocated in the order you "declare" it in your .date or .data? section.
But you should NULL terminate your strings if you want to use them with APIs :grin:
Posted on 2002-09-18 02:31:35 by bazik
Okay. Thanks.

I definitely like the control you get with ASM.

Can you show an example of NULL terminating a variable?

Kuphryn
Posted on 2002-09-18 09:29:38 by kuphryn

Okay. Thanks.

I definitely like the control you get with ASM.

Can you show an example of NULL terminating a variable?

Kuphryn


MyString db "Hello World",0
Posted on 2002-09-18 09:36:48 by Fordy
>Can you show an example of NULL terminating a variable?



.data
myVar db "Blah, blah, blah", 0



Easy, eh ? ;)


Edit: Ahhh...... Fordy got me by a minute ;)
Posted on 2002-09-18 09:37:50 by bazik
Yes! Thanks.

Now I understand we use '0' to terminate a string in C++. Although, 'NULL' help clarify the code.

Kuphryn
Posted on 2002-09-18 09:57:07 by kuphryn
As NULL is equated to zero you could:
myVar BYTE "Blah, blah, blah", NULL

(BYTE works the same way as db)
Posted on 2002-09-19 02:38:18 by huh
Okay. Thanks.

I interpret that WORD and DWORD are equivalent t DW and DD.

Kuphryn
Posted on 2002-09-19 02:55:56 by kuphryn