embedding C code
Posted: Tue Jun 06, 2023 10:50 pm
With the C backend, is it possible to embed C code like you can with ASM?
http://www.purebasic.com
https://www.purebasic.fr/english/
Yes.jassing wrote: Tue Jun 06, 2023 10:50 pm With the C backend, is it possible to embed C code like you can with ASM?
The same as described in the help file under 'Inline x86 ASM'.
Code: Select all
- The used variables or pointers must be declared before to use them in an assembler keyword. Their names in assembler are 'v_variablename' and 'p_pointername', and in a procedure their names are 'p.v_variablename' and 'p.p_pointername'.
- Labels: The labels need to be referenced in lowercase when using the in-line ASM. When you reference a label, you must put the prefix 'l_' before the name.
If the label is defined in a procedure, then its prefix is 'll_procedurename_', in lowercase.
When you reference a module item, you must put the prefix 'module_name.l_' all in lowercase before the item.
If the label is defined in a procedure inside a module, then its prefix is 'module_name.ll_procedurename_', in lowercase.
well that explains why I couldn't find it - I was searching for "C" in help, not asm.Demivec wrote: Wed Jun 07, 2023 2:15 am The same as described in the help file under 'Inline x86 ASM'.
Code: Select all
Global iVal.i
Define lVal.l
!g_ival = 100;
!v_lval = 200;
Debug iVal
Debug lVal
Procedure foo(p1, p2)
Protected r1
;r1 = p1 + p2
!v_r1 = v_p1 + v_p2;
ProcedureReturn r1
EndProcedure
iVal = foo(1, 2)
Debug iVal
that will make things a bit harder, I was quite happily abusing it to get unsigned types and now it probably won't work.mk-soft wrote: Wed Jun 07, 2023 8:16 am Global vars was change from v_xxx to g_xxx
Best way is is show "--commented" c-codeCode: Select all
Global iVal.i Define lVal.l !g_ival = 100; !v_lval = 200; Debug iVal Debug lVal Procedure foo(p1, p2) Protected r1 ;r1 = p1 + p2 !v_r1 = v_p1 + v_p2; ProcedureReturn r1 EndProcedure iVal = foo(1, 2) Debug iVal
Code: Select all
Global iVal.i
Procedure foo(p1.l, p2.l)
Protected r1
;r1 = p1 + p2
!v_r1 = (unsigned long)((unsigned long)v_p1 + (unsigned long)v_p2);
ProcedureReturn r1
EndProcedure
iVal = foo(1, -2)
Debug iVal
Code: Select all
t=-3
! v_t = (unsigned int) v_t;
Code: Select all
Global a.l
Global b.l
!unsigned long g_a;
a = -1
b = -1
Debug a
Debug b
Code: Select all
Global a.l : !unsigned long g_a;
Code: Select all
Global myval1=4096
DeclareModule abc
Declare test()
EndDeclareModule
Module abc
Procedure test()
! int test1 = g_myval1;
EndProcedure
EndModule
abc::test()
Code: Select all
DeclareModule xyz
Declare test()
EndDeclareModule
Module xyz
Global myval2=1024
Procedure test()
! int test2 = g_myval2;
EndProcedure
EndModule
xyz::test()
Code: Select all
Global myval1 = 2048
DeclareModule xyz
Declare test()
EndDeclareModule
Module xyz
Procedure test()
Protected size
!v_size = g_myval1;
Debug size
EndProcedure
EndModule
xyz::test()
Code: Select all
Define myval1 = 2048
DeclareModule xyz
Declare test()
EndDeclareModule
Module xyz
Procedure test()
Protected size
!v_size = v_myval1;
Debug size
EndProcedure
EndModule
xyz::test()