What is the difference between ASM backend vs C backend ?

Just starting out? Need help? Post your questions and find answers here.
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

What is the difference between ASM backend vs C backend ?

Post 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
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: What is the difference between ASM backend vs C backend ?

Post 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.
Best wishes to the PB community. Thank you for the memories. ♥️
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: What is the difference between ASM backend vs C backend ?

Post 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 ?
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: What is the difference between ASM backend vs C backend ?

Post by Kuron »

Best wishes to the PB community. Thank you for the memories. ♥️
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: What is the difference between ASM backend vs C backend ?

Post 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 ?
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: What is the difference between ASM backend vs C backend ?

Post 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.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: What is the difference between ASM backend vs C backend ?

Post 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.
Best wishes to the PB community. Thank you for the memories. ♥️
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: What is the difference between ASM backend vs C backend ?

Post 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 ?
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: What is the difference between ASM backend vs C backend ?

Post 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 :wink:

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.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: What is the difference between ASM backend vs C backend ?

Post 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.
Best wishes to the PB community. Thank you for the memories. ♥️
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: What is the difference between ASM backend vs C backend ?

Post 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.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: What is the difference between ASM backend vs C backend ?

Post 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 ?
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: What is the difference between ASM backend vs C backend ?

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: What is the difference between ASM backend vs C backend ?

Post 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
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: What is the difference between ASM backend vs C backend ?

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