King Harold wrote:you can inc bc, dec de, dec hl and only lose A. you can never save B that way you do it.
That’s already considerably longer and slower, and it would still affect some flags thanks to LDI, which you’d need a push-pop for. But then you could as well do that for BC instead of going through all that...
King Harold wrote:which does not mean we can go around writing bad code..
Depends on your criteria as to what bad code means. Readability and maintainability are many orders of magnitude more important than performance.
When performance is an issue, you have to take your favourite profiler, find the bottleneck, crazily optimise the critical portions and provide enough documentation/comments to keep it understandable for those who come back to the code later.
King Harold wrote:How much C is not compiled for x86? surely a bit, but it won't be much, seeing as most computers have a x86 compitable cpu.
Most CPUs are in embedded systems, and many of them are 16 or even 32-bit, where C is used quite often, so we’re talking about quite a lot of code.
King Harold wrote:anyway. according to some teacher, the standard way to make a local variable is to allocate space on the stack.
As long as there’s no optimisation involved, yes.
King Harold wrote:That is going to take more time then then doing 3 xors, 3 mem reads, and 3 mem writes, since it'd be calculating offsets etc and remembering a stackframe to push as well and only after that doing a few read/writes.
Well, in many cases stack space is allocated statically, during compile time, so it has zero runtime overhead.
King Harold wrote:how many compilers are going to use a non-standard way? not many of the often used ones I'd guess.
Any sensible C compiler you’ll come across will do extensive optimisation, be it VC, Borland or gcc, and they’ll shamelessly inline code and put local variables into registers. Old ones couldn’t do that efficiently, hence the ‘register’ keyword in the language!
King Harold wrote:you can not, you can only pass parameters in eax and ebx, you don't know where to write them to, but you can pass them back out exchanged
Well, that’s most likely compiler dependent (frankly, I never bothered using inline assembly since I moved on from Pascal, i.e. the good old BP7), and who’d go through a call-ret for single exchange anyway?