Ask HN: what happens between assembly and c?

2 points by ktran03 ↗ HN
Hi,

so in my undergrad, I've done some low level assembly programming I've also done quite a bit of c, and all the higher languages above that.

so my question is, what goes on between assembly and c?

HN please help me fill this gap, as it currently stands to be a mystery to me.

Thanks

4 comments

[ 5.3 ms ] story [ 27.8 ms ] thread
Are you asking what languages fill that gap, or how C programs interface with assembler libraries and OS interfaces?
Are you asking how C gets turned into Assembly or how does C interact with the machine? A compiler will compile your C code into assembly and an assembler will produce machine code from your assembly. Everything, no matter how high level it is, eventually is a series of instructions on some physical processor. C is basically just a higher level of representation of the assembly code the machine runs. Since you have experience in both, I'm sure you can see how C constructs translate into assembly code. Example how a while or for loop uses conditional branching or how local variables are allocated on the stack. Operating systems are written in a mix of C and assembly, as some things are specific to the machine you are running on. For instance, switching between Protected mode and 32e mode on an x86-64 processor. If you're also wondering how your code calls into operating system calls, it depends on both the processor and the operating system. For example on x86/linux, some arguments are passed via registers and on the stack and a software interrupt is called to transfer control to the OS and have the OS service the request on your behalf, such as file I/O or memory allocation. The more you study both of them, the more apparent it becomes how easily linked they are. I think what most people like about C is that its higher level than assembly but still gives you enough constructs that are close to the machine.
"A compiler will compile your C code into assembly"

basically what I was looking for. I have to look more into gnu gcc etc.

Thanks

checker659, actually mechatronics/software engineering