asm trouble

Vladimir A. Reznichenko vladimir.a.reznichenko at
Fri May 15 18:41:45 PDT 2009

Asm trouble, again. There is a function in a programm.

void test (inout uint a, uint sh, uint b)
	version (X86)
	{asm {
		mov EAX, a;
		mov EBX, sh;
		mov ECX, b;
		push EAX; //a adress saved
		//EAX = rotateLeft (a, sh) + b 
		push [EAX];
		push EBX;
		call rotateLeft;
		add EAX, ECX;

		pop EDX; //a adress restored
		mov [EDX], EAX;

void main ()
	uint a = 1;
	test (a, 5, 25);
	writeln (a);

When launched the executable,got this: Error: Access Violation

What's intresting, if i change asm code to
(save a address in the stack removed, forcing register values after the call instraction), it works just fine

	call rotateLeft;
	//force registers values
	mov EDX, a;
	mov ECX, b;

So the question is why the call instruction drops register values?
It have to save registers state and restore it after the rotateLeft finished (EAX of course will store a function call result).

More information about the Digitalmars-d mailing list