Array: Difference between revisions

Content added Content deleted
Line 43: Line 43:
An array is simply a sequence of values stored in memory. Its beginning is typically defined with some sort of label that points to the address where that array is stored. Arrays are mutable unless they are stored in ROM, such as on a video game cartridge.
An array is simply a sequence of values stored in memory. Its beginning is typically defined with some sort of label that points to the address where that array is stored. Arrays are mutable unless they are stored in ROM, such as on a video game cartridge.


</lang 6502asm>ArrayRAM equ $00 ;the beginning of an array, stored in zero page RAM
</lang 6502asm> 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>
ArrayROM: db 0,5,10,15,20,25,30,35,40,45,50 ;an array stored in ROM</lang>


Line 49: Line 49:




<lang 68000devpac> LEA myArray,A0
<lang 68000devpac>LEA myArray,A0
MOVE.W #4*5*1,D1 ;five elements per row, so to get the 4th row we multiply the row number by the elements per row,
MOVE.W #4*5*1,D1 ;five elements per row, so to get the 4th row we multiply the row number by the elements per row,
;times the number of bytes per element
;times the number of bytes per element
Line 65: Line 65:


In assembly, there are no built-in safeguards for indexing out of bounds, using an index of the wrong size, etc. The computer has no built-in way of knowing where an array "ends." Higher-level languages often use a "null terminator" at the end of a one-dimensional array to mark the end. C uses this method for strings. Assembly won't do that for you!
In assembly, there are no built-in safeguards for indexing out of bounds, using an index of the wrong size, etc. The computer has no built-in way of knowing where an array "ends." Higher-level languages often use a "null terminator" at the end of a one-dimensional array to mark the end. C uses this method for strings. Assembly won't do that for you!



===[[Fortran]]===
===[[Fortran]]===