Recent

Author Topic: FPC compiles pusha/popa as a pushaw/popaw. Is it doing right?  (Read 575 times)

Avinash

  • New Member
  • *
  • Posts: 41
I would expect PUSHAD/POPAD from 32-bit compiler.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9445
  • FPC developer.
Re: FPC compiles pusha/popa as a pushaw/popaw. Is it doing right?
« Reply #1 on: June 05, 2021, 02:34:52 pm »
They have the same opcode, so the meaning is probably set by the mode ?  That might be the disassembler at fault. (or whatever the backend assembler accepts, in the case of -a)

Avinash

  • New Member
  • *
  • Posts: 41
Re: FPC compiles pusha/popa as a pushaw/popaw. Is it doing right?
« Reply #2 on: June 05, 2021, 03:51:48 pm »
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$asmmode intel}
  3. var L: LongInt;
  4. begin
  5.   asm
  6.     xor  eax,eax
  7.     //pusha
  8.     dec  eax
  9.     //popa
  10.     mov  L, eax
  11.   end;
  12.  
  13.   WriteLn(HexStr(L, 8));
  14. end.

FFFFFFFF

Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$asmmode intel}
  3. var L: LongInt;
  4. begin
  5.   asm
  6.     xor  eax,eax
  7.     pusha
  8.     dec  eax
  9.     popa
  10.     mov  L, eax
  11.   end;
  12.  
  13.   WriteLn(HexStr(L, 8));
  14. end.

FFFF0000

PascalDragon

  • Hero Member
  • *****
  • Posts: 3191
  • Compiler Developer
Re: FPC compiles pusha/popa as a pushaw/popaw. Is it doing right?
« Reply #3 on: June 05, 2021, 04:56:08 pm »
Yes, this is by design. See this comment from the compiler's source:

Code: Pascal  [Select][+][-]
  1.           { pushf/popf/pusha/popa have to default to 16 bit in Intel mode
  2.           (Intel manual and Delphi-compatbile) -- setting the opsize for
  3.           these instructions doesn't change anything in the internal assember,
  4.           so change the opcode }

 

TinyPortal © 2005-2018