Array: Difference between revisions
m
→Assembly
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) m (→Assembly) |
||
Line 65:
DC.B 50,51,52,53,54</lang>
Iteration over the elements of an array is fairly straightforward.
<lang 68000devpac>
LEA myArray,A0
loop:
MOVE.B (A0)+,D0
JMP loop</lang>
Skipping elements can be easily done with a "dummy read," whereby an auto-incrementing/decrementing addressing mode is used solely for updating the pointer, or by incrementing/decrementing a loop counter multiple times per loop.
<lang asm>;8086 Assembly example
iterate:
movsb ;store [ds:si] into [es:di], increment both pointers, and decrement cx.
lodsb ;dummy read to increment the pointer and decrement cx. The value loaded into AL gets discarded.
inc di ;increment destination index
jcxz exitloop ;exit loop if cx equals zero.
jmp iterate</lang>
Implementation of a reverse array slice such as <code>a[100:0:-2]</code> example for [[Python]] is much more difficult. First of all, computers cannot implicitly understand the concept of the "end" of an array. The start of an array is easy for a computer to grasp, it is simply a pointer to its first element. However, encoding an array's end point requires some form of metadata, such as a null terminator or an additional variable representing the array's maximum size. High-level languages typically handle this automatically.
===[[Fortran]]===
|