BASM
Dec 19, 2014 19:59:12 GMT 1
Post by vovchik on Dec 19, 2014 19:59:12 GMT 1
Dear all,
It is possible to use ASM in BaCon, too, and it is easy.
Here is a little working example:
Or do it in a SUB:
Or do it as a function:
With kind regards,
vovchik
PS. BACASM might even deserve a separate thread. What do you think?
It is possible to use ASM in BaCon, too, and it is easy.
Here is a little working example:
' declare some integers to use in assembly
DECLARE foo=20, bar=50 TYPE int
PRINT "foo = ", foo
PRINT "bar = ", bar
' prep defines assembly to Basic type
USEC
#define ASM asm(
#define GAS );
END USEC
' add two numbers foo and bar
USEC
ASM
"addl %%ebx,%%eax"
:"=a"(foo)
:"a"(foo), "b"(bar)
GAS
END USEC
' Show vars and result of ASM additon
PRINT "ASM routine foo + bar = ", foo
PRINT "Brought to you courtesy of BaCon ASM. :)"
Or do it in a SUB:
' declare some integers to use in assembly
DECLARE foo=20, bar=50 TYPE int
' prep defines assembly to Basic type
SUB ASM_ADD()
' add two numbers foo and bar
USEC
#define ASM asm(
#define GAS );
ASM
"addl %%ebx,%%eax"
:"=a"(foo)
:"a"(foo), "b"(bar)
GAS
END USEC
END SUB
PRINT "foo = ", foo
PRINT "bar = ", bar
ASM_ADD()
' Show vars and result of ASM additon
PRINT "ASM routine foo + bar = ", foo
PRINT "Brought to you courtesy of BaCon ASM."
Or do it as a function:
DECLARE foo1=50, bar1=20 TYPE int
FUNCTION ASM_ADD(int foo, int bar)
' add two numbers foo and bar
USEC
' prep defines assembly to Basic type
#define ASM asm(
#define GAS );
ASM
"addl %%ebx,%%eax"
:"=a"(foo)
:"a"(foo), "b"(bar)
GAS
END USEC
RETURN foo
END FUNCTION
PRINT "foo = ", foo1
PRINT "bar = ", bar1
' Show vars and result of ASM additon
PRINT "ASM routine foo + bar = ", ASM_ADD(foo1, bar1)
PRINT "Brought to you courtesy of BaCon ASM."
With kind regards,
vovchik
PS. BACASM might even deserve a separate thread. What do you think?