How to translate Delphi Assembly MOV EAX,[EBP+4]

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to translate Delphi Assembly MOV EAX,[EBP+4]

Dennis
The following delphi code when compiled by FPC, raised these errors:
Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1,
Errors: 10, Warnings: 2
StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
StrBuffer.pas(100,23) Error: Assembler syntax error in operand
StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
StrBuffer.pas(100,29) Error: Invalid constant expression
StrBuffer.pas(100,29) Error: Invalid reference syntax
StrBuffer.pas(100,29) Warning: No size specified and unable to determine
the size of the operands, using DWORD as default
StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
StrBuffer.pas(207,23) Error: Assembler syntax error in operand
StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
StrBuffer.pas(207,29) Error: Invalid constant expression
StrBuffer.pas(207,29) Error: Invalid reference syntax
StrBuffer.pas(207,29) Warning: No size specified and unable to determine
the size of the operands, using DWORD as default

Can anyone help me?

class procedure TStrBuffer.Error(const Msg: string; Data: Integer);

   function ReturnAddr: Pointer;
   asm
           MOV     EAX,[EBP+4]
   end;

begin
   raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
end;
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to translate Delphi Assembly MOV EAX,[EBP+4]

Free Pascal - General mailing list
Dennis <[hidden email]> schrieb am Mi., 18. Juli 2018, 17:19:
The following delphi code when compiled by FPC, raised these errors:
Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1,
Errors: 10, Warnings: 2
StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
StrBuffer.pas(100,23) Error: Assembler syntax error in operand
StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
StrBuffer.pas(100,29) Error: Invalid constant expression
StrBuffer.pas(100,29) Error: Invalid reference syntax
StrBuffer.pas(100,29) Warning: No size specified and unable to determine
the size of the operands, using DWORD as default
StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
StrBuffer.pas(207,23) Error: Assembler syntax error in operand
StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
StrBuffer.pas(207,29) Error: Invalid constant expression
StrBuffer.pas(207,29) Error: Invalid reference syntax
StrBuffer.pas(207,29) Warning: No size specified and unable to determine
the size of the operands, using DWORD as default

Can anyone help me?

class procedure TStrBuffer.Error(const Msg: string; Data: Integer);

   function ReturnAddr: Pointer;
   asm
           MOV     EAX,[EBP+4]
   end;

begin
   raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
end;

There are two ways to solve this.

The first one is an easy one, however the code still won't be platform independent due to the assembly code. For this simply add "{$asmmode intel}" at the top. 

The second solution is cross platform and with correct checks also Delphi compatible:

=== code begin ===
raise EListError.CreateFmt(Msg, [Data]) at
{$ifdef fpc} 
get_caller_addr(get_frame),  
    get_caller_frame(get_frame)
{$else}
ReturnAddr
{$endif} ;
=== code end ===

Disable the ReturnAddr function also with "{$ifndef fpc}...{$endif}" and you should be set. 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to translate Delphi Assembly MOV EAX,[EBP+4]

Giuliano Colla
In reply to this post by Dennis


Il 18/07/2018 17:19, Dennis ha scritto:

> The following delphi code when compiled by FPC, raised these errors:
> Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1,
> Errors: 10, Warnings: 2
> StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
> StrBuffer.pas(100,23) Error: Assembler syntax error in operand
> StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
> StrBuffer.pas(100,29) Error: Invalid constant expression
> StrBuffer.pas(100,29) Error: Invalid reference syntax
> StrBuffer.pas(100,29) Warning: No size specified and unable to
> determine the size of the operands, using DWORD as default
> StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
> StrBuffer.pas(207,23) Error: Assembler syntax error in operand
> StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
> StrBuffer.pas(207,29) Error: Invalid constant expression
> StrBuffer.pas(207,29) Error: Invalid reference syntax
> StrBuffer.pas(207,29) Warning: No size specified and unable to
> determine the size of the operands, using DWORD as default
>
> Can anyone help me?
>
> class procedure TStrBuffer.Error(const Msg: string; Data: Integer);
>
>   function ReturnAddr: Pointer;
>   asm
>           MOV     EAX,[EBP+4]
>   end;
>
> begin
>   raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
> end;
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

It looks like Intel asm syntax, while fpc defaults to AT&T assembler.
According the docs you should prepend a switch
{$ASMMODE intel)
to your asm section, or at the top of the unit.

Hope that it helps,

Giuliano

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to translate Delphi Assembly MOV EAX,[EBP+4]

Dennis
In reply to this post by Free Pascal - General mailing list
Thanks.

So the following will give an address+frame of the calling routine ?
     get_caller_addr(get_frame),  get_caller_frame(get_frame)

Dennis

Sven Barth via fpc-pascal wrote:

> Dennis <[hidden email] <mailto:[hidden email]>> schrieb
> am Mi., 18. Juli 2018, 17:19:
>
>     The following delphi code when compiled by FPC, raised these errors:
>     Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1,
>     Errors: 10, Warnings: 2
>     StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
>     StrBuffer.pas(100,23) Error: Assembler syntax error in operand
>     StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
>     StrBuffer.pas(100,29) Error: Invalid constant expression
>     StrBuffer.pas(100,29) Error: Invalid reference syntax
>     StrBuffer.pas(100,29) Warning: No size specified and unable to
>     determine
>     the size of the operands, using DWORD as default
>     StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
>     StrBuffer.pas(207,23) Error: Assembler syntax error in operand
>     StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
>     StrBuffer.pas(207,29) Error: Invalid constant expression
>     StrBuffer.pas(207,29) Error: Invalid reference syntax
>     StrBuffer.pas(207,29) Warning: No size specified and unable to
>     determine
>     the size of the operands, using DWORD as default
>
>     Can anyone help me?
>
>     class procedure TStrBuffer.Error(const Msg: string; Data: Integer);
>
>        function ReturnAddr: Pointer;
>        asm
>                MOV     EAX,[EBP+4]
>        end;
>
>     begin
>        raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
>     end;
>
>
> There are two ways to solve this.
>
> The first one is an easy one, however the code still won't be platform
> independent due to the assembly code. For this simply add "{$asmmode
> intel}" at the top.
>
> The second solution is cross platform and with correct checks also
> Delphi compatible:
>
> === code begin ===
> raise EListError.CreateFmt(Msg, [Data]) at
> {$ifdef fpc}
> get_caller_addr(get_frame),
>     get_caller_frame(get_frame)
> {$else}
> ReturnAddr
> {$endif} ;
> === code end ===
>
> Disable the ReturnAddr function also with "{$ifndef fpc}...{$endif}"
> and you should be set.
>
> Regards,
> Sven
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to translate Delphi Assembly MOV EAX,[EBP+4]

Free Pascal - General mailing list
Dennis <[hidden email]> schrieb am Mi., 18. Juli 2018, 19:01:
Thanks.

So the following will give an address+frame of the calling routine ?
     get_caller_addr(get_frame),  get_caller_frame(get_frame)

As long as you pass it to the "raise ... at", yes. 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal