3.25.2011

gcc, ld, as, g++

I found some nice documentation about the GNU Assembler ("as") and after some more links and articles I am now able to understand most of the commands and directives GCC generates when compiling a C program. But geez, it's a hell of specific stuff that'll be totally different if compile it for another platform. Fortunately, I can now see exactly see what's happening or you inline or not. Got to say that I that I misjudged GCC's smartness... So it turns out to be totally the same when writing an inline function using adresses or references. A small test program for changing a passed variable turned out to be completely identical in output and thus not worth seperating. So in summary, the only thing left that's in my case more useful in C++ than in C is the use of templates. And those templates are just a more strict way of inserting types and literals to me (though the template processor is able to calculate everything you can do run-time execution, too). Well, I kinda didn't expected it. I always assumed stuff's more complicated than what I had in mind and that it won't usually work that well. So I proved differently, hm...

Whatever, I learned a lot and am now interested in using this new knowledge for personal peace and later use. Whatever C-generated assembly code is popping up infront of me, I should now be able to understand the commands if supplied with an appropriate reference. Though I'm not quite sure whether I'll have to use it outside of debugging and optimization comparison in later life, it's probably improves my value as a developer. Not every programmer knows how this almost supidly simple stuff works (really, it takes you just a few hours to get comftable with understanding and reading it). Therefore you effectively level-up without much to do, even if you still need some millions of XP points to the next one. Oh and it makes me know that the resulting code is actually more advantageous than anything I'd write on my own. Yes, I could do that by myself, but I don't think it's useful in my case cause it's machine-dependant then. Take the Pandora for example. It's ARM, my laptop is x64. So in every case I'd need to rewrite the stuff if I want to port it to the Pandora. Also, everything I'd be able to do can also be done by the compiler and in a probably more intelligent context. It also comes a certain degree of computer engineering... The more you now about the inner works of your CPU, the better you can design your assembler code for it. The benefits are only marginal with hand-written code for me - there are more people with more experience in computer architecture than dirty thoughts in my head (and yes, there are many of them). So pew, I may consider using more C instead of C++ if ever want to make my own programming language real. Other than the game project, it's something with fixed alghorithmic and feature set, not a monolithic monster. I was also able to figure out the command syntax details I'd need to fill things with actions. It came quicker than I imaged, suddenly popping up during a train ride. Thinking about it, it's probably also possible to make the resulting code as quick as I'd write by myself in assembler. Looking up in what segment which C program data goes may also be valuable to know when designing the code generator.

No comments: