digitalmars.D - asm trouble
- Vladimir A. Reznichenko (39/39) May 15 2009 Asm trouble, again. There is a function in a programm.
- Walter Bright (5/6) May 15 2009 The call instruction doesn't drop anything, it just does a call. What is...
- =?ISO-8859-1?Q?=22J=E9r=F4me_M=2E_Berger=22?= (13/20) May 16 2009 s=20
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).
May 15 2009
Vladimir A. Reznichenko wrote:So the question is why the call instruction drops register values?The call instruction doesn't drop anything, it just does a call. What is happening is the rotateLeft function is using ECX for something else. The EAX, ECX, and EDX registers are (by convention) not preserved across function calls.
May 15 2009
Walter Bright wrote:Vladimir A. Reznichenko wrote:s=20So the question is why the call instruction drops register values?=20 The call instruction doesn't drop anything, it just does a call. What i=happening is the rotateLeft function is using ECX for something else.=20 The EAX, ECX, and EDX registers are (by convention) not preserved acros=s=20function calls.AIUI, that would not cause an access violation, it would only cause=20 the returned value to be wrong. My question would be: does the=20 rotateLeft function pop its arguments from the stack? If it doesn't,=20 then "pop EDX" will actually put "sh" into EDX instead of the=20 address of "a"... Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
May 16 2009