Mail Archives: djgpp/1999/06/28/22:09:28
Christopher Nelson wrote:
> > 2) what are registers that i can safely change in
> >my assembler function without having to push its
> >values?
>
> there are no "safe" registers to manipulate. the compiler uses all the
> registers available for it in an optimized register allocation algorithm.
> if you mess with the registers in an unexpected way, you should save them,
> then restore them. if you are using inline assembly, you can do this after
> the third ':' so that the compiler knows not to expect anything in the
> registers that you thrash. finally, if you write a function in assembly
> that's prototyped as returning an int or an unsigned int, you may usually do
> anything you want with EAX because the compiler will expect the return value
> to be passed in that register. of course, if your program doesn't use the
> return value you can't assume what the compiler will do with the register.
> (most often it will just mark it dirty and reload it with whatever value it
> needs for the next expression resolution.)
When calling a standalone function, eax, ecx and edx are expected to be
changed. The compiler knows this. (Ref line 490 or so of
gcc-2.81/config/i386/i386.h (#define CALL_USED_REGISTERS)). Therefore,
these are safe to change in a pure asm function.
> > 3) in djgpp progs, does djgpp make the register es
> >equal to ds?? ALWAYS??
>
> no. DJGPP usually ignores the segment registers. after the initial
> initialization code, it never addresses the segment registers again, unless
> you do it in assembler -- or use the "farptr" routines.
Except that it's done implicitly by GCC. Obviously ds must be correct,
and since GCC does generate things like `rep movsl' sometimes, es needs
to be the same.
I guess that could be a semantic confusion. DJGPP *requires* that they
be the same, but it does not *make* that the case under all
circumstances (it won't fix it if you break it).
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -