Mail Archives: djgpp/1997/08/04/18:55:31

Date: Tue, 05 Aug 1997 10:55:13 +1100
From: Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz>
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: <>
Organization: Tait Electronics Limited
MIME-version: 1.0
Comments: Authenticated sender is <billc AT blackmagic DOT tait DOT co DOT nz>

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

Hope this helps
Leave others their otherness.

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019