Date: Fri, 18 Sep 92 19:03:24 CDT From: "George Jetson" To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Problems with multiplication inside a loop inside a function, ... I have found what I believe to be a compiler bug, relating to doing multiplication inside a loop inside a function. The code fragment given below may or may not be helpful to anyone. I shall probably end up spending some time trying to isolate the problem later on. Anyway, the code frag below is inside a function. The function is nested in my main() function. ('i' is declared inside the function, at the top) ----- int i; for (i=0; i textlen[ln] > off ? t1 -> text[ln] + off : ""; char *s2 = t2 -> textlen[ln] > off ? t2 -> text[ln] + off : ""; int w = keys[i].width; if (res = keys[i].direction * (keys[i].lexical ? (Strnicmp(s1,s2,w) ? : strncmp(s1,s2,w)) strncmp(s1,s2,w))) return (res); } ----- nkeys is the number of keys and if it is one, then this works fine. But if nkeys > 1, then I get an Exception 13. Tracing it through with DEBUG32 reveals that the start of the for loop gets implemented as something like: mov ebx,[eax-16] (Watch this space) cmp [ebp-8],ebx jge _big_cmp.13+384 (0x184c ) mov edx,[eax-44] I think that eax-16 is the address of 'i', and ebp-8 is nkeys. Anyway, what happens is that the first time through, this works fine, but in the second iteration, eax is 0, and, obviously, [eax-16] is a bogus address. Stepping the loop through all the way shows that eax gets trashed by an imul, and does not get restored. Also, if I make a slight source code modification, this ends up using edi instead of eax, but edi is also trashed by the multiplication routine. Also, a couple of related questions about DEBUG32: 1) How do I make the source code available to the debugger? (DEBUG32.DOC implies that it is possible - I assume it is some option on the compilation) Yes, I know I am being lazy and could certainly look it up... 2) In the above frag, when I do a g to the "mov ebx,[eax-16]", I should be able to do a "d %eax-16" and get the result that is about to be loaded into ebx, right? Unfortunately, I can't get this to work. "d %eax-16" gives me an unrelated value. (I.e., when I single step it, ebx gets the correct value)