r/Assembly_language • u/Key-Kangaroo3336 • 14d ago
Help C to ASM
Hello everyone!
I am currently working on a side project where a python script takes a C source file and converts it into ASMx86_64 (Intel syntax) and I am just trying to find resources for type conversions without making some kind of script where I automate generating a program and compiling it for ASM in GCC.
Does a list like this exist? And if so, are there separate ones for Windows and Linux? (As I think there’s a difference, not completely sure)
Thanks, have a good one frens
6
u/Odd_Psychology3622 14d ago
think gcc does this pass the -S flag instead of the -o it will create a .s file which is the asm conversion
2
u/Key-Kangaroo3336 14d ago
Yes it is, however I am needing a very stripped version of its output for direct syscalls instead of one that would import libraries and such.
2
4
u/VancouverVentilator 13d ago
Lol this is just gcc with the S flag... Basically you're rewriting gcc with the S flag
2
u/Kadabrium 13d ago
Now when i think about it, how performance critical are compilers really? Why don't we see compilers written in higher languages more often? Interpreters i understand but i've always thought of compilers as just text processors. They are probably like video encoders in that regard as end users don't often see them running but the data they process can still get big.
3
u/ComprehensiveBig6215 13d ago
My guess is that most C/C++ compilers are very, very old....llvm is the baby and is 26 years old. GCC and MSVC go back to the 1980s...
3
u/VancouverVentilator 13d ago
Because modern gcc is the cumulative efforts of decades of experience, thousands of people collaborating on features, etc.; It is easier to make an entirely new systems programming language from scratch than it is to beat gcc on any metric.
1
u/B3d3vtvng69 12d ago
well clang is pretty close, aren’t they equal when looking at multiple metrics?
1
u/Rararror 11d ago
Compilers are often written in the same language they compile. It is called bootstrapping.
1
1
u/FluffusMaximus 12d ago
You know GCC already does this, right?
1
u/Key-Kangaroo3336 12d ago
Yes however I am wanting an extremely stripped version, and making it myself and actually understanding the process is more valuable than “just use / do X” in my opinion
2
u/potato-master369 8d ago
Honestly best approach for now is to define the stdlib in assembly first (with rhe functions you want since C std library is written in C, provide a simple header file, and rip the functions directly into your assembly. As for linux syscalls, they are not API stable (I think), so fix a version or set up a table system. You would find some good resources in man7’s man 2 syscalls.
For windows, not sure. I don’t think the syscalls are public. You could sniff yourself, but windows depends a lot on kernel32.dll not raw syscalls.
This isn’t really gcc -S tho as people are saying since you’re implementing libc yourself and not linking to system libc… which is very hard in assembly so uh good luck…
1
u/potato-master369 8d ago
I assume here you’re implementing your own libc since if not you can just link sys libc at the linker stage with extern in the generated assembly, which would not need syscalls other than the exit syscall which is just 1 google search…
32
u/[deleted] 14d ago
So actually you are writing a compiler.