Code: Select all
program Test;
var
MyArray: array[0..7] of Byte;
begin
// Trick the optimizer into thinking we use MyArray
MyArray := MyArray;
asm
MOVF MyArray+1, W
MOVWF MyArray+0
MOVFF MyArray+2, MyArray+3
end;
end.
Code: Select all
; Assembly code generated by mikroVirtualMachine - V. 5.0.0.3
; Date/Time: 12/03/2007 13.15.38
; Info: http://www.mikroe.com
; ADDRESS OPCODE ASM
; ----------------------------------------------
$0000 $EF04 F000 GOTO _main
$0008 $ _main:
;Test.ppas,4 :: MyArray: array[0..7] of Byte;
;Test.ppas,11 :: MOVF MyArray+1, W
$0008 $5000 MOVF MYARRAY+1, W, 0
;Test.ppas,12 :: MOVWF MyArray+0
$000A $6E00 MOVWF MYARRAY+0, 0
;Test.ppas,13 :: MOVFF MyArray+2, MyArray+3
$000C $C000 F000 MOVFF MYARRAY+2, MYARRAY+3
;Test.ppas,14 :: end;
$0010 $ Test_L_0:
;Test.ppas,16 :: end.
$0010 $D7FF BRA $
The same thing happens with MyArray declared as ABSOLUTE: if MyArray's address is $50, "MOVFF MyArray+2, MyArray+3" becomes "$C050 $F050" (instead of "$C052 $F053").
Curiously enough, compiler-generated labels (STACK_0 and the like) are handled correctly, i.e. if STACK_0+0 is $00, STACK_0+1 is $01; this made the above misbehaviour a lot harder to track, because assembling machine code was definitely the last thing I expected to go wrong.