Compiler BUG inline assembly intel immediate 64-bit load to register when requesting 64-bit nasm -compatible output
Original Reporter info from Mantis: ahi
-
Reporter name: Antero Hiismäki
Original Reporter info from Mantis: ahi
- Reporter name: Antero Hiismäki
Description:
for example:
{$ASMMODE INTEL}
function Test:Int64;
asm
mov RAX, $1234567898765432
end;
the compiler loads only the LOW32 bits of the immediate parameter into RAX, ignoring the HIGH32 bits.
Steps to reproduce:
How to reproduce:
{$ASMMODE INTEL}
function Test:Int64;
asm
mov RAX, $1234567898765432
end;
- Put the Test function above in a program, and compile using the following command line:
ppcrossx64 -Anasmwin64 Test1
- Look at the generated Test1.s:
SECTION .text
ALIGN 16
GLOBAL P$TEST1__TEST
QWORD
P$TEST1__TEST
QWORD:
..@c1:
lea rsp,[rsp-8]
..@c3:
CPU x64
mov rax,-1737075662
CPU x64
lea rsp,[rsp+8]
ret
..@c2:
; End asmlist al_pure_assembler
The compiler-generated constant -1737075662 converted to HEX is $98765432, totally ignoring the HIGH 32 bits.
The odd thing is that IF you compile direct-to-EXE (bypassing the assembly language output meant for 64-bit nasm assembly),
then the compiler will produce the correct code to load the full 64-bit constant.
But I wanted to write part of my code in objectpascal, and convert that to nasm source code, write more code directly in assembly language and use nasm to combine both into one single 64-bit executable code.
also:
I get the following error message:
"Assembling test1
Test1.pas(98,60) Error: Assembler x86_64-win64-nasm.exe not found, switching to
external assembling"
does that mean I should copy the nasm.exe as "x86_64-win64-nasm.exe" and put that in the same directory where "ppcrossx64" already exists ?
Not that it really matters in this case, because I don't want to directly compile to EXE anyway, but instead use the freepascal assembly language output as part of input to nasm, and write some other code directly in assembly language and feed the comination to nasm.
Mantis conversion info:
- Mantis ID: 38074
- Build: [2020/06/04] for x86_64
- Version: 3.2.0
- Fixed in version: 3.3.1
- Fixed in revision: 47413 (#bf7961a9)