A similar construction can be seen in
outline.pas from the original Borland Turbo Vision package:
{$IFDEF FPC}{$ASMMODE INTEL}{$ENDIF}
procedure Test;
var I: Integer;
procedure Nested;
{var J: Integer;}
begin
asm
{$IFDEF VER70}
mov bx, word ptr [bp] {get parent BP}
mov word ptr ss:[bx + OFFSET I], 12345
{$ELSE}
mov eax, dword ptr [ebp] {get parent EBP}
mov dword ptr [eax + OFFSET I], 12345
//mov dword ptr [eax - 4], 12345
{$ENDIF}
end;
end;
begin
I := 0;
Nested;
WriteLn(I); { outputs '12345' }
end;
begin
Test;
end.
This way it compiles and works with both TP and FPC 3.2.2. However, if you uncomment the declaration of the
J variable, then FPC refuses to compile it (
Error: You cannot reach I from that code). At the same time, the declaration of the
J variable does not affect the offsets at all — if you use a line with [eax - 4] instead of OFFSET, it will work in both cases.