Variables: Difference between revisions

Line 23:
<lang 11l>Int p, a, d</lang>
=={{header|6502 Assembly}}==
===Declaration===
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 ;some assemblers require equ directives to not be indented.
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>
 
 
Line 60 ⟶ 61:
sound_on .rs 1
;no closer needed for this method</lang>
 
===Initialization===
This mostly depends on the hardware you are programming for. If the code runs in RAM, you can initialize an entire block of RAM to the value of choice with <code>ds <count>,<value></code> (replace count and value with numbers of your choice, no arrow brackets.) On systems like the NES which have dedicated RAM areas on the CPU and the whole program is in ROM, you're best off setting all RAM to zero on startup and initializing the ram to the desired values at runtime.
 
=={{header|360 Assembly}}==
1,489

edits