"volvox" <pi********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
hi, is it possible to access protected mode registers (EAX ,
EBX,ECX...) via assembly in C .
Yes, you can. But, not with standard C.
Also, it's not wise to do so unless you know assembly. And, you know
'intimate' details of how the compiler generates code.
DJGPP has the C '__asm__()' directive for assembly. OpenWatcom has the C
'_asm{}' directive and '#pragma aux' for assembly.
An example of an 'intimate' details you may need to know, most C routines
have a prolog and epilog that does things which are hidden from C
programmers.
Prolog:
1) saves the current stack frame
2) creates a new stack frame
3) push the passed parameters onto a local stack
Epilog:
1) removes current stack frame
2) restores the prior stack frame
3) assembly return statement
The implementation of these routines vary from compiler to compiler and even
within the same compiler. GCC based compilers use the ESP and EBP registers
to do stackframes. DJGPP generates (at least) four different prolog and
epilog sequences. OpenWatcom doesn't use an ESP/EBP stackframe at all. OW
uses the Intel assembly 'ret imm16' instruction to adjust ESP.
Also, many compilers dedicate certain registers for their own use. They are
called: 'callee-savee registers'. The values of these registers must be
preserved. For OW, the registers change for different options.
DJGPP ebx,edi,exi,ebp,ds,es,ss
OW -3s ebx,edi,esi,ebp
OW -3r ebx,edi,esi,ebp,ecx,edx
Another hurdle is this: it's very difficult to outperform the optimization
of a C compiler. Why? Because,
1) the C compiler optimizes the code it produces.
2) the C compiler won't optimize your "optimized" assembly code to work with
it's code.
This creates a conflict in the way the registers, stack, etc., are used by
your code and the compilers code. This introduces many wasteful
instructions into the equation to get the two code pieces working together.
In the cases I've seen, the compiler only needed to change an offset or two,
and perhaps reorder an instruction to do the same thing in C as my very
efficient hand coded routines...
Rod Pemberton