-asm att problems

General FreeBASIC programming questions.
Post Reply
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

-asm att problems

Post by srvaldez »

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

Code: Select all

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

Code: Select all

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.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: -asm att problems

Post by srvaldez »

the solution for the time being is to use line continuation _
this works
compile: fbc -gen gcc -asm att example3.bas
example3.bas

Code: Select all

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)
the following also works

Code: Select all

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
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: -asm att problems

Post by dodicat »

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

Code: Select all


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 
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: -asm att problems

Post by dodicat »

Oops srvaldez, I see you are using it.
But note the little bug anyway.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: -asm att problems

Post by srvaldez »

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.
Post Reply