Howdy, Stranger!

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

Categories

Continuous Memory Location :: ASM

kuphrynkuphryn Member Posts: 266
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

  • jeffleydajeffleyda Member Posts: 390
    : -----
    : .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!
  • kuphrynkuphryn Member Posts: 266
    Okay. Thanks.

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

    Kuphryn
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [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]


  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _ \ http://forcoder.org \ free video tutorials and ebooks about ( PL/SQL, Python, MATLAB, Assembly, Java, Perl, Objective-C, R, C, Swift, Visual Basic .NET, PHP, C++, Go, Delphi, C#, Visual Basic, Ruby, JavaScript, Scratch ML, LabVIEW, D, Ada, Apex, Transact-SQL, Awk, Logo, Lisp, Erlang, Fortran, Alice, Dart, VBScript, Kotlin, Clojure, Crystal, Scheme, Bash, SAS, Scala, FoxPro, Julia, Prolog, Lua, Rust, ABAP, F#, Hack, COBOL ) __________

Sign In or Register to comment.