Date: Tue, 05 Aug 1997 10:55:13 +1100 From: Bill Currie Subject: Re: Strange loop with optimize In-reply-to: To: Georg DOT Kolling AT t-online DOT de (Georg Kolling), djgpp AT delorie DOT com Message-id: <199708042259.KAA19700@teleng1.tait.co.nz gatekeeper.tait.co.nz> Organization: Tait Electronics Limited MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Comments: Authenticated sender is Precedence: bulk On 4 Aug 97 at 23:30, Georg Kolling wrote: > I have a strange problem with a loop that calls a NASM function > Here's the NASM code first: > > BITS 32 > GLOBAL _ppix > EXTERN _mouse_x > EXTERN _mouse_y > SECTION .text > _ppix: mov eax, [_mouse_y] > mov ebx, [_mouse_x] ^^^ here's your problem > shl eax, 5 ; mouse_y * 32 > lea eax, [eax + 4*eax] ; mouse_y * 5 > lea eax, [eax + 4*eax] ; mouse_y * 5, altogether: > mouse_y * 800 add eax, ebx fs mov BYTE > [eax], 11 ; put color 11 on screen ret > ebx, edi, esi, esp, ds and es must be preserved. eax, ecx, edx, fs and gs are free for you to use, but libc uses gs, so stick to fs. To fix your problem, just put a `push ebx' at the beginning of your function and `pop ebx' at the end. Also, as I have an allergy to global variables :), the function call protocol for gcc is (in nasm, sortof (haven't used it much yet)): push ebp mov ebp,esp [sub esp, local_var_space] [save required registers (ebx,esi,edi)] [parameters are: ebp+8,ebp+12,ebp+16...] [ (left most C parameter being ebp+8] [restore registers] leave ; cheaper or as cheap as mov esp,ebp pop ebp ret Hope this helps Bill -- Leave others their otherness.