asm stackframe question

Stefan stefan at schuerger.com
Sat Apr 7 15:13:39 PDT 2012


As a little learning exercise for D I’m writing a fixed point 
library. Part of this is checking standard integer operations for 
overflows.

This is the code for adding 2 longs:

int64 add64ov(int64 a, int64 b) {
	int64 res;
	 asm {
		mov EAX,a    ;
		mov EDX,a+4  ;
		add EAX,b    ;
		adc EDX,b+4  ;
		jo  overflow ;
		mov res,EAX  ; // Not optimal: cannot do a ret here because of 
stack frame previously not correctly set
		mov res+4,EDX;
	}
	return res;
	overflow:
	throw new OverflowException("Overflow in 64 bit addition");
}

The detour via the res variable is costly; the standard epilogue
(I probably need a frame pointer for the exception throw to work):
   mov ESP, EBP
   pop EBP
   ret

creates an access violation.

Ideas, anyone?


More information about the Digitalmars-d-learn mailing list