Address of a variable: Difference between revisions

Content added Content deleted
No edit summary
Line 22: Line 22:
MYDSECT DSECT
MYDSECT DSECT
J DS F</lang>
J DS F</lang>

=={{header|68000 Assembly}}==
When programming in assembly language yourself (i.e. not having a compiler do it for you), generally the addresses of variables are known in advance and chosen by the programmer rather than dynamically determined by the compiler. Therefore you pretty much always know a variable's address at all times.

<lang 68000devpac>UserRam equ $100000
Cursor_X equ UserRam ;$100000, byte length
Cursor_Y equ UserRam+1 ;$100001, byte length
SixteenBitData equ UserRam+2 ;$100002, word length (VASM doesn't allow labels to begin with numbers.)
ThirtyTwoBitData equ UserRam+4 ;$100004, long length

;GET THE ADDRESS

LEA ThirtyTwoBitData,A0 ;load $100004 into A0.</lang>

Setting a variable to an address is as simple as storing a desired value in memory. Assembly languages in general do not have automated memory management, so it is important to manage your memory well.

<lang 68000devpac>MOVE.L #$11223344,D0
MOVE.L D0,(A0) ; store D0 into ThirtyTwoBitData ($100004)
; HEXDUMP OF $100004:
; $100004: $11
; $100005: $22
; $100006: $33
; $100007: $44</lang>



=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
When programming in assembly language yourself (i.e. not having a compiler do it for you), generally the addresses of variables are known in advance and chosen by the programmer rather than dynamically determined by the compiler. Therefore you pretty much always know a variable's address at all times. However there is a little more work that needs to be done to get the address in 8086 Assembly compared to assembly for other machines.
When programming in assembly language yourself (i.e. not having a compiler do it for you), generally the addresses of variables are known in advance and chosen by the programmer rather than dynamically determined by the compiler. Therefore you pretty much always know a variable's address at all times. However there is a little more work that needs to be done to get the address in 8086 Assembly compared to assembly for other machines.