rswier / c4

C in four functions
GNU General Public License v2.0
9.63k stars 1.42k forks source link

C to assembly issue #34

Closed shashikant-wagh closed 6 years ago

shashikant-wagh commented 7 years ago

Why you have converted sample program in assembly when it execution is using C functions ( like printf ), I haven't seen any place where assembly is executing. Is there any significance for it or just demo purpose. Don't get me wrong, I haven't get my head around it.

nubok commented 6 years ago

Why you have converted sample program in assembly when it execution is using C functions ( like printf )

The assembly code that is generated is for the virtual machine that c4 implements. The only functions from the C standard library/system that are used are open, read, close, printf, malloc, free, memsetand memcmp(cf. https://github.com/rswier/c4/blob/6884cb4de9659895dc1ae4f0196899d3cbfdc6e2/c4.c#L516-L523). Even if c4 were creating native assembly code for the respective architecture that c4 runs on (in the branch c5-AST such an experiment is done: https://github.com/rswier/c4/tree/c5-AST), the linker would link the generated program against the C standard library. If you want to free yourself from the C standard library that your OS provides, you can write your own implementations of these functions.