I am trying to learn the gcc inline asm but there's a problem, the first example works but not the second, I tried enclosing in quotes in as many different ways as possible but to no avail
compile: fbc -gen gcc -asm att example1.bas
example1.bas
function sqRoot(byval a as double) as double
dim as double root
asm
"fldl %1\n" "fsqrt\n" : "=t"(root) : "m"(a) :
end asm
return root
end function
Print sqRoot(2)
compile: fbc -gen gcc -asm att example2.bas
example2.bas
function sqRoot(byval a as double) as double
dim as double root
asm
"fldl %1\n" "fsqrt\n"
: "=t"(root) : "m"(a) :
end asm
return root
end function
Print sqRoot(2)
Last edited by srvaldez on Feb 21, 2018 12:55, edited 1 time in total.
function sqRoot(byval a as double) as double
dim as double root
asm
"fldl %1\n" _
"fsqrt\n" _
: "=t"(root) _
: "m"(a) _
:
end asm
return root
end function
Print sqRoot(2)
function sqRoot(byval a as double) as double
dim as double root
asm
"fldl %[A$1]\n" _ 'note the decorated name usage
"fsqrt\n" _
:"=t"(root) _
:[a] "m"(a) _ 'note the [a], it's needed to be able to use the decorated name
:
end asm
return root
end function
An observation!
The asm block is for machine code instructions (according to the help file)
However the underscore seems to work inside it (including that little bug where you can write things after it)
-gen gcc -asm att
32 and 64 bit
Tested Win 10
function sqRoot(byval a as double) as double
dim as double root
asm
"fldl %1\n" "fsqrt\n" _ using an underscore
: "=t"(root) : "m"(a) :
end asm
return root
end function
Print sqRoot(2)
sleep
thanks dodicat, learning gcc extended asm is not as difficult as I once thought and you don't have to worry about optimization problems.
the problem I run into in my previous tries was that I didn't know about the need for line continuation and all my attempts failed and therefore came to the conclusion that it was impossible to learn.