Mail Archives: djgpp/1995/08/15/09:13:24
I quoted this:-
long _ax,_bx,_cx,_dx,_si,_di,_bp,_es; short _flags;
#define __SR() /* save the registers */ ({asm("xchgl %eax,__ax"); \
asm("xchgl %ebx,__bx"); asm("xchgl %ecx,__cx"); asm("xchgl %edx,__dx"); \
asm("xchgl %esi,__si"); asm("xchgl %edi,__di"); asm("xchgl %ebp,__bp"); })
#define __RR() /* restore the registers */ ({ \
asm("pushf"); asm("popw __flags"); __SR();})
mat AT ardi DOT com (Mat Hostetter) criticized it thus:-
> You must tell gcc about input and output values, and which registers get
> clobbered. ... This code hides from gcc the fact that __ax, etc. are really
> input and output parameters. gcc is free to assume that those variables do
> not get modified by this asm, and optimize accordingly.
I use these two macros as a pair thus, e.g.:-
_ax=0x1234; etc; __SR(); asm("this and that"); __RR(); use_value_of(_ax);
The original registers are saved by __SR() and restored by __RR(), and I do
explicitly alter _ax in C text.
> This code contains a sequence of contiguous asm statements, which is a bad
> idea if you really want the asms to be contiguous ...
Thankyou. Point taken.
> This code uses the hardcoded names "__ax", etc. for asm symbols, which
> aren't guaranteed to be correct; for example, on a Linux ELF ...
This code is intended for djgpp on PC only.
> xchgl is really slow, at least on the Pentium.
How many times slower than a `movl'?
- Raw text -