Continuous Memory Location :: ASM

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

Comments

  • : -----
    : .DATA
    :
    : varOne DB 'testing 1 2 3'
    : varTwo DW 'September 2002'
    :
    : 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?

    That's the .asm works all right. Stuff is allocated exactly how you place it; exactly where you'd expect to find it. There are no secrets, nothing random (except maybe the starting segment of your program).

    This can be a blessing or a pain of course, but I find it makes debugging so much easier knowing where your data is!
  • Okay. Thanks.

    Definitely, yes I like the control you get with ASM.

    Kuphryn
  • [b][red]This message was edited by AsmGuru62 at 2002-9-18 7:29:41[/red][/b][hr]
    : 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
    :
    [red]mov ax, WORD PTR DB + 12[/red]
    [blue]I am not sure you can compile that... 'DB' is reserved word and [b]WORD PTR[/b] expects the label (which is [b]varOne[/b]).

    Also, I think you can't declare literal ('September 2002') as [b]DW[/b][/blue]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories