Pelles C forum

Pelles C => Bug reports => Topic started by: frankie on February 22, 2005, 01:12:40 PM

Title: Compiler problems with registers when quadwords involved
Post by: frankie on February 22, 2005, 01:12:40 PM
Hello Pelle,
here a little problem with pocc. Consider this simple source
Code: [Select]
struct _ls {int a; int b;};

struct _ls __fastcall func1(int m1, int m2);

void __stdcall TstFunc(int k)
{
int l;
struct _ls ls;

l=k;
ls=func1((k*3)/2, l);
}

If you compile with
Quote
pocc /Ze /Zl /Os file.c

Some problems come, look at the disassembly:
Code: [Select]
_TstFunc@4:
  [00000000] 55                   push      ebp
  [00000001] 89E5                 mov       ebp,esp
  [00000003] 83EC0C               sub       esp,+C
  [00000006] 8B4508               mov       eax,dword ptr [ebp+8] ;k
  [00000009] 8945FC               mov       dword ptr [ebp-4],eax ;k->l
  [0000000C] 8B55FC               mov       edx,dword ptr [ebp-4] ;load edx with 'l'
  [0000000F] 8D0440               lea       eax,[eax+eax*2]  ;k*3
  [00000012] B902000000           mov       ecx,00000002  ;prepare for divide for 2
  [00000017] 99                   cdq        ; this trashes edx
  [00000018] F7F9                 idiv      eax,ecx  ;this too trashes edx
  [0000001A] 89C1                 mov       ecx,eax  ;result in ecx
  [0000001C] E800000000           call      @func1@8  ;call the function
  ;BUT what holds EDX?????
  [00000021] 8945F4               mov       dword ptr [ebp-C],eax
  [00000024] 8955F8               mov       dword ptr [ebp-8],edx

@1:
  [00000027] 89EC                 mov       esp,ebp
  [00000029] 5D                   pop       ebp
  [0000002A] C20400               ret       4


Got it  :wink: ?
the assignement of edx is done too early, do it just before calling the function.
Cheers F.
Title: Compiler problems with registers when quadwords involved
Post by: Pelle on February 23, 2005, 12:39:00 AM
Got it. The __fastcall calling convention really don't go very well with the LCC framework. I will see what I can do...

Pelle