Mail Archives: djgpp/1997/08/04/18:55:31
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.
- Raw text -