FPC BASM32 POP bug?

151 views Asked by At

Another discrepancy between Delphi and FPC BASM:

program PopTest;

{$IFDEF FPC}
  {$mode delphi}
  {$asmmode intel}
{$ELSE}
  {$APPTYPE CONSOLE}
{$ENDIF}

var
  B: LongWord;

procedure Pop(A: LongWord; var B: LongWord);
asm
         PUSH   EAX
         POP    [EDX]
end;

begin
  Pop(5, B);
  Writeln(B);
  Readln;
end.

This 32-bit code works as expected in Delphi XE and produces access violation in FPC (2.6.4)

Debugging reveals that POP instruction (in FPC compiler) pops a word instead of expected double word, thus destroying the stack and the procedure's return address. The solution is

procedure Pop(A: LongWord; var B: LongWord);
asm
         PUSH   EAX
         POP    DWORD [EDX]
end;

which is actually better code since it removes the parameter size ambiguity.

Bug or not?

0

There are 0 answers