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
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
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:
Okay. Thanks.
I definitely like the control you get with ASM.
Can you show an example of NULL terminating a variable?
Kuphryn
I definitely like the control you get with ASM.
Can you show an example of NULL terminating a variable?
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
>Can you show an example of NULL terminating a variable?
Easy, eh ? ;)
Edit: Ahhh...... Fordy got me by a minute ;)
.data
myVar db "Blah, blah, blah", 0
Easy, eh ? ;)
Edit: Ahhh...... Fordy got me by a minute ;)
Yes! Thanks.
Now I understand we use '0' to terminate a string in C++. Although, 'NULL' help clarify the code.
Kuphryn
Now I understand we use '0' to terminate a string in C++. Although, 'NULL' help clarify the code.
Kuphryn
As NULL is equated to zero you could:
myVar BYTE "Blah, blah, blah", NULL
(BYTE works the same way as db)
myVar BYTE "Blah, blah, blah", NULL
(BYTE works the same way as db)
Okay. Thanks.
I interpret that WORD and DWORD are equivalent t DW and DD.
Kuphryn
I interpret that WORD and DWORD are equivalent t DW and DD.
Kuphryn