Array: Difference between revisions

m
→‎Assembly: clarification on rom/ram arrays
m (→‎Assembly: clarification on rom/ram arrays)
Line 41:
* [[letter frequency]]
===[[Assembly]]===
An array is simply a sequence of values stored in consecutive memory locations. Its beginning is typically defined with some sort of label that points to the address where that array is stored. ArraysWhether arean array is mutable unlessor theyimmutable aredepends on the hardware; in older assembly languages, an array is only typically immutable if it's stored in ROM,. suchHome ascomputer software that runs on a videodisk gamecan define an array at compile time that can be mutable; ROM cartridge programs cannot. The syntax is the same for both, however. ROM cartridge programs will need to construct their array in ROM, copy it to RAM, and alter the copy.
 
<lang 6502asm>;6502 Assembly example
ArrayRAM equ $00 ;the beginning of an array, stored in zero page RAM
ArrayROM: db 0,5,10,15,20,25,30,35,40,45,50 ;an array stored in ROM</lang>
;on Commodore 64 (for example) this can be RAM but on the NES or something similar it would be read-only
 
Almost all assembly languages have a method of loading from a memory address offset by some sort of variable amount. That offset is the index into the array. Depending on the size of each element that index is multiplied by the number of bytes each element takes up. What constitutes an "element," "row," or "column" of the array is entirely decided by the programmer. Arrays in assembly are always zero-indexed.
1,489

edits