Docu about inline assembler 64-bit ?

Forum for discussion about the documentation project.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Docu about inline assembler 64-bit ?

Post by D.J.Peters »

I can only find the old 32-bit only inline assembler page http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAsm or i'm blind ?

Joshy
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Docu about inline assembler 64-bit ?

Post by dkl »

No, there's nothing. I suppose we could add some links. x86-64.org seems to be down at the moment; it used to have some details.

Inline asm with fbc's C backend is still tricky though, it doesn't fully work in all cases due to the need to translate to gcc's format...
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Docu about inline assembler 64-bit ?

Post by srvaldez »

hello dkl and D.J.Peters
I hope you don't mind chiming in, as it is a bit off topic, I found I can use inline asm in my Mac version of FB x64
but have found no way to access the variables, if you set the optimization to zero then you can access the variables
using the rbp register but there doesn't seem to be a method to calculate the correct offset making it unusable
below is an illustration

Code: Select all

function mytest(byref x as double, byref y as double) as double
	dim as double z
	
	asm
		".intel_syntax noprefix"
		"fldpi"
		"fstp qword ptr [rbp-16]"
		".att_syntax prefix"
	end asm
	return z
end function

dim as double a,b,c
c=mytest(1,2)
? a,b,c
I could never understand how to use the gcc inline asm, don't have a high enough IQ
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Docu about inline assembler 64-bit ?

Post by SARG »

Parameters are stored in registers and also on the stack.
BUT there are differences on how Windows and Linux are managing them.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Docu about inline assembler 64-bit ?

Post by dkl »

Check out the -asm intel example for accessing parameters here: CompilerOptasm
It also works on 64bit (C backend), with fbc 1.05.0 at least.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Docu about inline assembler 64-bit ?

Post by srvaldez »

@SARG
yes I can access the arguments from registers but I must compile with zero optimization or it won't work and there's no sure way to access local variables because of the unknown offset, I am guessing that gcc aligns the memory for the local vars.
@dkl
I can't figure that out, it's a completely alien language to me.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Docu about inline assembler 64-bit ?

Post by dkl »

I'm confused; what's so alien about this?

Code: Select all

Dim a As Long = 1
Print a
Asm
    inc dword ptr [a]
End Asm
Print a
It's normal FB inline ASM.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Docu about inline assembler 64-bit ?

Post by srvaldez »

I apologize for having intruded this thread with off-topic posts so I will stop after this post, you are of course right dkl, for Windows x64 and Linux x64 normal intel asm works ok, it's on the Mac that I am unable to use normal asm, but that's ok with me.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Docu about inline assembler 64-bit ?

Post by marcov »

I do have the MSDN link for win64 calling conventions handy: https://msdn.microsoft.com/en-us/library/ms235286.aspx

Summary:

// Integer arguments are passed in registers RCX, RDX, R8, and R9.
// Floating point arguments are passed in XMM0L, XMM1L, XMM2L, and XMM3L.
// volatile: RAX, RCX, RDX, R8, R9, R10, R11
// nonvolatile RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 are considered nonvolatile
// no red zone
// keep stack 16-byte aligned.

I believe the sysv ABI puts the parameters in RDI,RSI,RDX
Post Reply