A89: Back to arrays... =(
[Prev][Next][Index][Thread]
A89: Back to arrays... =(
> move.w #4,2(array)
> move.w #4,4(array)
> lea array,a6
> ...
> array
> ds.b 20
> ...
>
> and the program won't compile. So I tried:
>
> ...
> lea array,a6
> move.w #4,2(a6)
> move.w #4,4(a6)
> ...
> array
> ds.b 20
> ...
>
> and that works. I just want to know why I have to use a register for it to
> work. Thanks.
Well, the first form you ask the processor to do this:
write '4' to the word of which the address is 2 more than that of the
address of 'array'. This is a totally legal request, only you used a
wrong syntax. From the CPU's point of view the offset (2) and the base
address (array) are both constants. The 68k can not add two constants
when calculating an effective address. Therefore you have to ask the
assembler to calculate the result (which it can, since both components
are constants) and tell the CPU to write the 4 to the addres of
'array+2' (storead a single constant).
Try this:
move.w #4,array+2
move.w #4,array+4
When you say move.w #4,2(a6) you ask the CPU to store the 4 in a word
of which the address the content of a6 plus 2. The 68K supports this
construct directly, it is a valid thing to do. On the other hand, the
assembler could not help here for the assembler have no idea what will
be in a6 when you actually execute the insn.
Regards,
Zoltan
Follow-Ups:
References: