Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-07

fpc-2.1.4.x86_64-win64.exe: Hello World program with ASM, compilation aborted ? Error: Unknown identifier "EAX" ???

16 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Skybuck Flying

Hello,

I downloaded and installed:

fpc-2.1.4.x86_64-win64.exe (beta)

I wrote a little Hello World program to test the compiler:

var
 test : int64;
begin
 writeln('Hello Free Pascal World !');

asm
mov eax, ecx

 end;
 writeln('Test: ', test );
 readln;
end.

I get these errors:

Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld
HelloWorld.pas(7,10) Error: Unknown identifier "EAX"
HelloWorld.pas(7,12) Error: Unknown identifier "ECX"
HelloWorld.pas(7,12) Error: Asm: [mov ???,???] invalid combination of opcode
and
 operands
HelloWorld.pas(14,4) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted

Surely it's possible to write assembler code in free pascal ?

Is it a bug/beta issue ?

Can I use win32 download to compile to 64 bit programs ?

I'll try another version.

Bye,
Skybuck.

Reply by email

Jonas Maebe
to Skybuck Flying
Skybuck Flying wrote 11 lines
Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld HelloWorld.pas(7,10) Error: Unknown identifier "EAX" HelloWorld.pas(7,12) Error: Unknown identifier "ECX" HelloWorld.pas(7,12) Error: Asm: [mov ???,???] invalid combination of opcode and operands HelloWorld.pas(14,4) Fatal: There were 3 errors compiling module, stopping Fatal: Compilation aborted Surely it's possible to write assembler code in free pascal ?

Yes, but the default syntax is AT&T, not Intel. I assume you are coming from a Delphi background, so you can probably best solve this and many future issues you would otherwise encounter by adding {$mode delphi} at the top of all of your source files (or compile with - Mdelphi).

Jonas

Reply by email

Skybuck Flying
to Jonas Maebe
Show quoted text 11 lines
Yes, but the default syntax is AT&T, not Intel. I assume you are coming from a Delphi background, so you can probably best solve this and many future issues you would otherwise encounter by adding {$mode delphi} at the top of all of your source files (or compile with - Mdelphi). Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ah, thanks a lot:

I downloaded and installed fpc-2.0.4.i386-win32.exe and was having the same problems:

Y:\Free Pascal\Tests\Hello World>fpc HelloWorld.pas -delphi Free Pascal Compiler version 2.0.4 [2006/08/21] for i386 Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Win32 for i386
Compiling HelloWorld.pas
HelloWorld.pas(9,10) Error: Unknown identifier "EAX" HelloWorld.pas(9,12) Error: Unknown identifier "ECX" HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of opcode and
operands
HelloWorld.pas(13,2) Warning: Variable "test" does not seem to be initialized
HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, stopping HelloWorld.pas(16,4) Fatal: Compilation aborted
Error: C:\Tools\Compilers\Free Pascal\2.0.4 Stable for Win32\bin\i386-Win32\ppc3
86.exe returned an error exitcode (normal if you did not specify a source file t
o be compiled)

Then I was about to make a post about this and read your tips and now it compiles just fine ;)

Y:\Free Pascal\Tests\Hello World>fpc HelloWorld.pas -Mdelphi Free Pascal Compiler version 2.0.4 [2006/08/21] for i386 Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Win32 for i386
Compiling HelloWorld.pas
HelloWorld.pas(13,2) Warning: Variable "test" does not seem to be initialized
Linking HelloWorld.exe
15 Lines compiled, 0.1 sec

I also tried cross compiling with stable version 2.0.4 to Win64:

Y:\Free Pascal\Tests\Hello World>fpc HelloWorld.pas -Mdelphi -Twin64 Error: Illegal parameter: -Twin64

Y:\Free Pascal\Tests\Hello World>fpc HelloWorld.pas -Mdelphi -Tx64 Error: Illegal parameter: -Tx64

So I guess I'll have to reinstall the fpc-2.1.4.x86_64-win64.exe to compile to win64 and test out the new assembler syntax which I hope is in there !? ;)

Fingers crossed ;)

I will install them side by side:

C:\Tools\Compilers\Free Pascal\2.0.4 Stable for Win32 C:\Tools\Compilers\Free Pascal\2.1.4 Beta for Win64

I will also add both to the user path.

Hopefully that won't give problems ;)

If it does give problems I'll remove the stable version and try the beta only ;)

Bye,
Skybuck.

Reply by email

Skybuck Flying
to Jonas Maebe: Yes, but the default syntax is AT&T, not Intel. I assume you are coming from a Delphi…

Ok,

I just reinstalled fpc-2.1.4.x86_64-win64.exe:

And this time I used the -Mdelphi compiler switch but it still gives problems:

Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi
HelloWorld.pas(9,10) Error: Unknown identifier "EAX"
HelloWorld.pas(9,12) Error: Unknown identifier "ECX"
HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of opcode
and
 operands
HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted

I also tried adding:

{$mode delphi}

Nothing is working :((((((((( (Just like the transformers soundtrack song ;) :))

Bye,
Skybuck.

Reply by email

Jonas Maebe
to Skybuck Flying
Skybuck Flying wrote 14 lines
I just reinstalled fpc-2.1.4.x86_64-win64.exe: And this time I used the -Mdelphi compiler switch but it still gives problems: Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi HelloWorld.pas(9,10) Error: Unknown identifier "EAX" HelloWorld.pas(9,12) Error: Unknown identifier "ECX" HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of opcode and operands HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, stopping Fatal: Compilation aborted

I guess the Intel assembler syntax is simply not supported for x86-64. You will have to use AT&T syntax instead. Here are some google links to tutorials and overview documents:
http://www.google.com/search?rls=en&q=at%26t+assembler+syntax

Jonas

Reply by email

Marco van de Voort
to Jonas Maebe
Show quoted text 8 lines
On 26 Jul 2007, at 10:44, Skybuck Flying wrote: > stopping > Fatal: Compilation aborted I guess the Intel assembler syntax is simply not supported for x86-64. You will have to use AT&T syntax instead. Here are some google links to tutorials and overview documents: http://www.google.com/search?rls=en&q=at%26t+assembler+syntax

You might also want to look at the source code in rtl/x86_64 in the FPC repository.

Reply by email

Skybuck Flying
to Michael Van Canneyt: Obviously it does not work: the assembler you use is for 32-bit platforms, and that will…

----- Original Message -----

Earlier message 56 lines
From: "Michael Van Canneyt" To: "FPC-Pascal users discussions" Sent: Thursday, July 26, 2007 11:50 AM Subject: Re: [fpc-pascal] fpc-2.1.4.x86_64-win64.exe: -Mdelphi not working ? > > > On Thu, 26 Jul 2007, Skybuck Flying wrote: > >> Ok, >> >> I just reinstalled fpc-2.1.4.x86_64-win64.exe: >> >> And this time I used the -Mdelphi compiler switch but it still gives >> problems: >> >> Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi >> HelloWorld.pas(9,10) Error: Unknown identifier "EAX" >> HelloWorld.pas(9,12) Error: Unknown identifier "ECX" >> HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of >> opcode >> and >> operands >> HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, >> stopping >> Fatal: Compilation aborted >> >> I also tried adding: >> >> {$mode delphi} >> >> Nothing is working :((((((((( (Just like the transformers soundtrack >> song >> ;) :) ) > > Obviously it does not work: the assembler you use is for 32-bit platforms, > and that will not work if you cross-compile to 64-bit ! Using 32 bit registers in 64 bit mode should be perfectly valid. It's just like using 16 bit registers or 8 bit registers in 32 bit mode, that's perfectly valid too. So simply put: you are wrong about that, I am 99.99% sure about that ;) > The mode statement only applies to pascal syntax, never to assembler. Again, you wrong, me thinks. It does work for asm too. Get your facts straight ;) :) Bye, Skybuck.

Reply by email

Skybuck Flying
to Jonas Maebe: I guess the Intel assembler syntax is simply not supported for x86-64. You will have to…

Hello,

This is my first attempt at writing AT&T asm code and also 64 bit asm code:

The output is supposed to be 2^64 - 1 but it displays 2^32-1.

Did I program a bug ?

Or is the compiler bugged ?

Maybe writeln bugged ?

What's wrong ?

// *** Begin of Code ***
program HelloWorld;
{$mode delphi}
var
 test : int64;
begin
 writeln('Hello Free Pascal World !');

asm
mov $10, %eax
mov %eax, test // no size warnings, kinda nice ;) or could it hide bugs in the future ?
end;

 writeln('Test: ', test );

asm
mov $100, %eax
mov %eax, test
end;

 writeln('Test: ', test );
 // $7FFFFFFFFFFFFFFF not recognized.
 // bug: only lower bits moved ?
 // $100 is this hexadecimal 100 or decimal 100 ?
 // the test above shows 100.. I guess 100 decimal then...
 // somewhere below is a bug: 4294967295
 // maybe move instruction is only 32 bits ?
 // maybe rax is only 32 bits.. but isn't it 64 bits ?
 asm
  mov $9223372036854775807, %rax
  mov %rax, test
 end;
 writeln('Test: ', test );
 readln;
end.
// *** End of Code ***

Bye,
Skybuck.

Reply by email

Skybuck Flying
to Marco van de Voort: You might also want to look at the source code in rtl/x86_64 in the FPC repository.

Hello,

I found this link explaining some difference between AT&T and intel asm syntax:

http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/gnu-assembler/i386-syntax.html

So I tried to add q behind mov maybe that was the problem...

Kinda strange that mov is allowed to compile.

Anyway it's still not working.

However assigning directly to test via pascal code does work:

Examples:

<begin of snippet>

asm
movq $9223372036854775807, %rax // problem ?
movq %rax, test // problem ?
end;

 writeln('Test: ', test ); // still 4294967295, problem.
 Test := 9223372036854775807;
 writeln('Test: ', test ); // displays 9223372036854775807, ok.

<end of snippet>

Bye,
Skybuck.

Reply by email

Michael Van Canneyt
to Skybuck Flying: I just reinstalled fpc-2.1.4.x86_64-win64.exe: And this time I used the -Mdelphi compiler…
Skybuck Flying wrote 21 lines
Ok, I just reinstalled fpc-2.1.4.x86_64-win64.exe: And this time I used the -Mdelphi compiler switch but it still gives problems: Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi HelloWorld.pas(9,10) Error: Unknown identifier "EAX" HelloWorld.pas(9,12) Error: Unknown identifier "ECX" HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of opcode and operands HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, stopping Fatal: Compilation aborted I also tried adding: {$mode delphi} Nothing is working :((((((((( (Just like the transformers soundtrack song ;) :) )

Obviously it does not work: the assembler you use is for 32-bit platforms, and that will not work if you cross-compile to 64-bit !

The mode statement only applies to pascal syntax, never to assembler.

Michael.

Reply by email

Skybuck Flying
to Jonas Maebe: I guess the Intel assembler syntax is simply not supported for x86-64. You will have to…

Hello,

I like free pascal compiler to generate an assembler listing of HelloWorld.pas and fortunately it can do that which is really cool !

I simply type:

ppcrossx64 HelloWorld.pas -default

It then generates a HelloWorld.S file:

Here is a snipper from it ;)

<Begin of Snippet>

; Begin asmlist al_procedures

_TEXT SEGMENT
ALIGN 16
PUBLIC PASCALMAIN
PASCALMAIN:
PUBLIC main
main:
push rbp
mov rbp,rsp
sub rsp,96
mov qword ptr [rbp-8],rbx
call FPC_INITIALIZEUNITS
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,24
mov r8,offset _$HELLOWORLD$_Ld1
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov eax,10
mov qword ptr [U_P$HELLOWORLD_TEST],eax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov eax,100
mov qword ptr [U_P$HELLOWORLD_TEST],eax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov rax,-1
mov qword ptr [U_P$HELLOWORLD_TEST],rax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov dword ptr [U_P$HELLOWORLD_TEST],-1
mov dword ptr [U_P$HELLOWORLD_TEST+4],2147483647
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
call fpc_get_input
mov rbx,rax
mov rcx,rbx
call fpc_readln_end
call FPC_IOCHECK
call FPC_DO_EXIT
mov rbx,qword ptr [rbp-8]
leave
ret
; End asmlist al_procedures
; Begin asmlist al_globals

<End of Snippet>

Pretty cool.

Kinda ironic how it can generate it, but not interpret it ? ;)

For me it doesn't matter that much, I would like to give AT&T asm a try... though it might not be smart because Visual Studio 2005, Intel, probably AMD too, and Delphi 2007 all use intel syntax.

So for future compatibility using AT&T asm syntax might not be too smart.

But maybe I will like AT&T syntax... I never liked intel syntax that much... kinda stupid and crazy but ok ;) :)

I wonder what free pascal can do more ?

Can it reverse engineer executables and dll's and produce asm listings ?

Bye,
Skybuck.

Earlier message 36 lines
----- Original Message ----- From: "Jonas Maebe" To: "FPC-Pascal users discussions" Sent: Thursday, July 26, 2007 10:51 AM Subject: Re: [fpc-pascal] fpc-2.1.4.x86_64-win64.exe: -Mdelphi not working ? > > On 26 Jul 2007, at 10:44, Skybuck Flying wrote: > >> I just reinstalled fpc-2.1.4.x86_64-win64.exe: >> >> And this time I used the -Mdelphi compiler switch but it still gives >> problems: >> >> Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi >> HelloWorld.pas(9,10) Error: Unknown identifier "EAX" >> HelloWorld.pas(9,12) Error: Unknown identifier "ECX" >> HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of >> opcode and >> operands >> HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module, >> stopping >> Fatal: Compilation aborted > > I guess the Intel assembler syntax is simply not supported for x86-64. > You will have to use AT&T syntax instead. Here are some google links to > tutorials and overview documents: > http://www.google.com/search?rls=en&q=at%26t+assembler+syntax > > > Jonas > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >

Reply by email

Graeme Geldenhuys
to Skybuck Flying

[... not really Free Pascal related...]

Seeing that it sounds like you enjoy assembly language. Maybe you would like the following assembly framework created by Gibson Research Corporation.

Homepage with loads of utility apps for Windows.
http://www.grc.com/default.htm

Most popular freeware on GRC.com
http://www.grc.com/freepopular.htm
Scroll down until you find: Small Is Beautiful (SIB)

It's a Windows assembly language starter kit.
Quote from the author:
"I write all of my Windows and other utilities in 100% pure assembly language. This results in the smallest, fastest, and most efficient programs possible. I created the "Small is Beautiful" kit to help interested assembly language programmers get started writing Windows programs in pure assembly language."

It is very impressive what the author managed to do and his utilities are really small! Around 10-20k, yet does an amazing amount.

Where are the days I used to understand assembly language. :-) I wonder if one can do something like that for Linux or the Mac?

Regards,
- Graeme -

Skybuck Flying wrote 7 lines
Hello, I like free pascal compiler to generate an assembler listing of HelloWorld.pas and fortunately it can do that which is really cool ! I simply type:

Reply by email

Skybuck Flying
to Graeme Geldenhuys

Maybe I do enjoy it, however the small is beautifull kit is for 32 bit windows programming.

I really want 64 bit windows programming.

So I guess it's not for me ;)

Bye,
Skybuck.

Earlier message 25 lines
----- Original Message ----- From: "Graeme Geldenhuys" To: "FPC-Pascal users discussions" Sent: Thursday, July 26, 2007 1:06 PM Subject: Re: [fpc-pascal] fpc-2.1.4.x86_64-win64.exe: default switch generatesintel asm,ironic ? Can free pascal reverse engineer executables and dll's ? > [... not really Free Pascal related...] > > Seeing that it sounds like you enjoy assembly language. Maybe you > would like the following assembly framework created by Gibson Research > Corporation. > > Homepage with loads of utility apps for Windows. > http://www.grc.com/default.htm > > Most popular freeware on GRC.com > http://www.grc.com/freepopular.htm > Scroll down until you find: Small Is Beautiful (SIB) > > It's a Windows assembly language starter kit. <snipped to reduce message size>

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: [... not really Free Pascal related...] Seeing that it sounds like you enjoy assembly…
Graeme Geldenhuys wrote 27 lines
[... not really Free Pascal related...] Seeing that it sounds like you enjoy assembly language. Maybe you would like the following assembly framework created by Gibson Research Corporation. Homepage with loads of utility apps for Windows. http://www.grc.com/default.htm Most popular freeware on GRC.com http://www.grc.com/freepopular.htm Scroll down until you find: Small Is Beautiful (SIB) It's a Windows assembly language starter kit. Quote from the author: "I write all of my Windows and other utilities in 100% pure assembly language. This results in the smallest, fastest, and most efficient programs possible. I created the "Small is Beautiful" kit to help interested assembly language programmers get started writing Windows programs in pure assembly language." It is very impressive what the author managed to do and his utilities are really small! Around 10-20k, yet does an amazing amount. Where are the days I used to understand assembly language. :-) I wonder if one can do something like that for Linux or the Mac?

For linux I wouldn't recommend it. The API is not stable enough on a binary level. The kernel API is (and even then...), but as soon as you want to access the C or third party libraries, (mysql comes to mind) good luck to you :/

Michael.

Reply by email