Page 1 of 2
What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 7:15 am
by moricode
What is the difference between ASM backend vs C backend ?
Hi, could be curious to know what is the difference between ASM back end and C backend ?
features ? performance ? accuracy ? code size ? effort of coding ? any idea ?
since we all code in PB language and get the final .exe and run our projects , dose it matter much to make us choose one over another back end ?
since PB was compile to ASM initially an natively for a long long time , what motivate him to develop another back end ?
it clearly will have more benefits then the old one ? or else why ?
seems i miss many things , thanks if someone could enlighten me for some points.
thanks guy
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 7:22 am
by Kuron
C backend allows for easy porting to new and emerging platforms. C backend is also able to be optimized more and often produces faster code.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 7:41 am
by moricode
Kuron wrote: Fri Nov 10, 2023 7:22 am
C backend allows for easy porting to new and emerging platforms. C backend is also able to be optimized more and often produces faster code.
if so this two reason , doesn't it to code in C make more sense ?
or it must have more other reasons ?
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 7:48 am
by Kuron
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:11 am
by moricode
ok, like so the three post above , C is the way to the future .
we then see that the ASM backend will be drop soon or later.
look like learning C is a lot easier then learning asm for regular programmer .
dose it better if we code in pure C language directly instead of coding in PB and output to C and port to other platform ?
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:20 am
by BarryG
In my experience, the C backend produces less (sometimes none) anti-virus false-positives compared to compiling with ASM. My take on this is that the malware written by PureBasic in the past (PureLocker) was done with the ASM backend, so certain code pattern triggers are now forever tied to it.
My main app is still ASM because it uses inline assembler that I need, but all my new apps use the C backend to avoid triggering false-positives now.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:23 am
by Kuron
moricode wrote: Fri Nov 10, 2023 8:11 am
look like learning C is a lot easier then learning asm for regular programmer .
I would generally agree, but Ethan Winer (who was quite the BASIC and ASM guru) said "C has all of the difficulty of dealing with assembly language, but none of the benefits."
Personally, I will always code in PB, and use ASM backend for testing, and use C backend for releases. This is what Fred recommended to me.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:28 am
by moricode
Kuron wrote: Fri Nov 10, 2023 8:23 am
moricode wrote: Fri Nov 10, 2023 8:11 am
look like learning C is a lot easier then learning asm for regular programmer .
Personally, I will always code in PB, and use ASM backend for testing, and use C backend for releases. This is what Fred recommended to me.
how about if you don't get bug in ASM backend when testing , but there is a new bug when release (using C backend)?
dose this two in equivalent in testing or release ?
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:29 am
by infratec
Yes, C is portable and you can code for every platform in C if you like.
But ...
if it comes to any other 'feature' than pure logic code, like GUI, databases, web ...
You need to do your on stuff (libraries, frameworks, ...) for each platform.
It is much more comfortable to use PB
As you have written: you code in PB and get an executable
Unfortunately I still have many codes which does not work with the C backend.
But it is the future.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 8:34 am
by Kuron
For me, when I say testing, I mean in-house testing. For releases, this would also include alpha and beta versions to get any of the C bugs ironed out. For me a release is alpha, demo or final, simply for people other than myself.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 10:11 am
by Fred
You shouldn't worry about the final backend, unless you are wanting to write specific ASM or C inline code (which is not that often). The C backend offer faster final code when optimization is on if your program relies on CPU heavy algorithm.
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 12:08 pm
by threedslider
Can I create from scratch a app for C Backend as PB normal but without PB in which speed mean to that ? Better Can I mix with PB and C backend codes and to exchange between to variables or function ?
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 1:28 pm
by mk-soft
Inline C is possible.
Example ...
Code: Select all
Procedure bswap32(value.l)
CompilerIf #PB_Compiler_Backend = #PB_Backend_C
!return __builtin_bswap32(v_value);
CompilerElse
!mov eax, dword [p.v_value]
!bswap eax
ProcedureReturn
CompilerEndIf
EndProcedure
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 2:06 pm
by threedslider
mk-soft wrote: Fri Nov 10, 2023 1:28 pm
Inline C is possible.
Example ...
Code: Select all
Procedure bswap32(value.l)
CompilerIf #PB_Compiler_Backend = #PB_Backend_C
!return __builtin_bswap32(v_value);
CompilerElse
!mov eax, dword [p.v_value]
!bswap eax
ProcedureReturn
CompilerEndIf
EndProcedure
Nice !
Ok I try this code for testing to Lua in Purebasic but there is missing some header :
Code: Select all
CompilerIf Not Defined(PB_Compiler_Backend,#PB_Constant)
CompilerError "Please use PureBasic Version 6.02 LTS"
CompilerElseIf #PB_Compiler_Backend<>#PB_Backend_C
CompilerError "Please use Compiler-Option C Backend."
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ImportC "lua5.4.6.lib" : EndImport
!#include "C:\Lua\lua-5.4.6\lua.h";
CompilerEndIf
Global lua
!g_lua = luaL_newstate();
!luaL_openlibs(g_lua);
*code = UTF8("print('Hello, World from Lua')")
!if (luaL_loadstring(g_lua, p_code) == LUA_OK (0)) {
! if (lua_pcall(g_lua, 0, 0, 0) == LUA_OK) {
! lua_pop(g_lua, lua_gettop(g_lua));
! }
! }
FreeMemory(*code)
!lua_close(g_lua);
It is based from Idle on this forum :
viewtopic.php?t=78472
Re: What is the difference between ASM backend vs C backend ?
Posted: Fri Nov 10, 2023 3:41 pm
by juergenkulow
Code: Select all
124 | if (luaL_loadstring(g_lua, p_code) == LUA_OK (0)) {
| ^^^
Lua Download area for the headers.
Code: Select all
$ /tmp/lua.out
Hello, World from Lua
Embedding C code in PB source need to be described