Array length: Difference between revisions
m
→{{header|68000 Assembly}}
Puppydrum64 (talk | contribs) |
|||
Line 50:
=={{header|68000 Assembly}}==
Array length is computed at compilation time with the formula: (Array_End-Array). The "bit width" of this value is the bit width of the result, not the bit width of the inputs. In other words, even though code labels are 32-bit memory addresses, if their difference is 8 or 16-bit you can use a <code>.B</code> or <code>.W</code> instruction or directive on them without a compile-time error.
The biggest limitation to the (Array_End-Array) method is that it always measures in total bytes. So if your array elements are of a different type you'll have to adjust accordingly. For an array strings, you should instead construct an array of pointers to strings and divide the result of the difference by 4 to get the total number of "strings" in the array.
<lang 68000devpac>start:
MOVE.B #(
RTS
Apple:
DC.B "apple",0
even
Orange:
DC.B "orange",0
even
Array_End:</lang>▼
MyArray:
DC.L Apple
DC.L Orange
=={{header|8th}}==
|