$ fpc -h
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 3.1.1 [2015/03/12] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
/mnt/LinuxShared/fpc/fpc [options] <inputfile> [options]
Only options valid for the default or selected platform are listed.
Put + after a boolean switch option to enable it, - to disable it.
...
-P<x> Target CPU / compiler related options:
-PB Show default compiler binary
-PP Show default target cpu
-P<x> Set target CPU (arm,avr,i386,jvm,m68k,mips,mipsel,powerpc,powerpc64,sparc,x86_64)
...
My "fpc -h" does not list -P, yet -P definitely works for me. This seems like a documentation error. Also notice I am executing "fpc" but my 3rd line says "ppc386.exe". This also seems like a documentation error. Here is my "fpc -h" output, just for interest:
C> fpc -h
Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
C:\FPC\2.6.4\bin\i386-Win32\ppc386.exe [options] <inputfile> [options]
Put + after a boolean switch option to enable it, - to disable it
...
-O<x> Optimizations:
-O- Disable optimizations
-O1 Level 1 optimizations (quick and debugger friendly)
-O2 Level 2 optimizations (-O1 + quick optimizations)
-O3 Level 3 optimizations (-O2 + slow optimizations)
-Oa<x>=<y> Set alignment
-Oo[NO]<x> Enable or disable optimizations, see fpc -i for possible values
-Op<x> Set target cpu for optimizing, see fpc -i for possible values
-OW<x> Generate whole-program optimization feedback for optimization <x>, see fpc -i for possible values
-Ow<x> Perform whole-program optimization <x>, see fpc -i for possible values
-Os Optimize for size rather than speed
-pg Generate profile code for gprof (defines FPC_PROFILE)
-R<x> Assembler reading style:
-Rdefault Use default assembler for target
-Ratt Read AT&T style assembler
-Rintel Read Intel style assembler
...
But I want to focus on the needs expressed in my original post.
I'm a bit lost with that. If you add: uses SysUtils; and -gl compiler option when compiling, what's the output?
I noticed the code you provided flipped Quotient (RAX) with Remainder (RDX) so I fixed that. I also changed the Dividend so it has a non-0 remainder, added "uses SysUtils;", and saved in file asm64test2.pas:
{$asmmode intel}
uses
SysUtils;
var
HiDividend,LoDividend,Divisor,Quotient,Remainder: Int64;
begin
HiDividend := $0000000000000001;
LoDividend := $1100000000000017;
Divisor := $10;
asm
MOV RDX,HiDividend
MOV RAX,LoDividend
DIV Divisor
MOV Quotient,RAX
MOV Remainder,RDX
end ['RAX','RDX'];
WriteLn(HexStr(Quotient,16)); { 1110000000000001 expected }
WriteLn(HexStr(Remainder,16)); { 0000000000000007 expected }
end.
C> fpc -Px86_64 asm64test2
Free Pascal Compiler version 2.6.4 [2014/03/06] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling asm64test2.pas
Linking asm64test2.exe
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_hidividend".
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_divisor".
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_remainder".
19 lines compiled, 0.1 sec , 73104 bytes code, 19268 bytes data
3 warning(s) issued
C> asm64test2
An unhandled exception occurred at $0000000100001553 :EDivByZero : Division by zero
$0000000100001553
Using -gl:
C> fpc -Px86_64 -gl asm64test2
Free Pascal Compiler version 2.6.4 [2014/03/06] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling asm64test2.pas
Linking asm64test2.exe
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_hidividend".
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_divisor".
asm64test2.pas(19,1) Warning: Object file "asm64test2.o" contains 32-bit absolute relocation to symbol ".bss.n_u_p$program_remainder".
19 lines compiled, 0.10 sec , 81360 bytes code, 19444 bytes data
3 warning(s) issued
C> asm64test2
1110000000000001
0000000000000007
It works! But I am very confused and not done. The -gl option (generate debug information, use line info unit) changes execution from divide by zero (?!) to no runtime errors?! Why is "uses SysUtils;" required? How do I get rid of the 3 warnings? What does "you should load them over %RIP" from marcov mean?