Variables: Difference between revisions

No edit summary
Line 23:
<lang 11l>Int p, a, d</lang>
=={{header|6502 Assembly}}==
Declaration is not actually needed in 6502 Assembly. Any portion of RAM can be read or written at any time. However, it is very helpful to use descriptive labels of memory locations. Different assemblers handle this differently, with directives such as "Equals" <code>equ</code>, "Enumerate" <code>.enum</code>, "Reserve Storage Space" <code>.rs</code>, or "Define Storage Bytes:<code>.dsb</code>. These directives allow you to name a memory address to something you can more easily remember than an arbitrary number. One important caveat to note is that the <code>equ</code> directives do not take up space in your program. This is easier to illustrate with an example than explain in words:
<lang 6502asm> org $1200
SoundRam equ $1200
SoundChannel_One equ $1200
SoundChannel_Two equ $1201
SoundChannel_Three equ $1202
LDA #$FF ;this still gets assembled starting at $1200, since equ directives don't take up space!</lang>
 
 
 
Each example below is equivalent, but which one you use depends on the assembler.
 
The <code>equ</code> method:
<lang 6502asm>joystick equ $00 ;this variable is located at zero page memory address $00
Player_Xpos equ $01 ;this variable is located at $01
Player_Ypos equ $02
pointer equ $03 ;intended to take up 2 bytes
sound_on equ $05</lang>
 
The <code>enum</code> method:
<lang 6502asm>enum $0000
;these will be defined starting at $0000 and increasing in the order listed, incremented by the amount after DSB.
joystick dsb 1 ;this takes up 1 byte
Player_Xpos dsb 1
Player_Ypos dsb 1
pointer dsb 2 ;this takes up 2 bytes
sound_on dsb 1
ende ;end enumeration</lang>
 
The <code>rs</code> method:
<lang 6502asm>.rsset $0000
joystick .rs 1
Player_Xpos .rs 1
Player_Ypos .rs 1
pointer .rs 2
sound_on .rs 1
;no closer needed for this method</lang>
 
=={{header|360 Assembly}}==
;assignment, reference, referencing:
1,489

edits