Error FPC BASM32 POP?

Another mismatch 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 creates an access violation in FPC (2.6.4)

Debugging shows that the POP command (in the FPC compiler) issues a word instead of the expected double word, thereby destroying the stack and the return address of the procedure. Decision

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

which is actually the best code as it removes the ambiguity of the parameter size.

Error or not?

+5
source share

Source: https://habr.com/ru/post/1239476/


All Articles