Mail Archives: djgpp/1998/08/11/03:45:57
In <6qntq4$bl1$1 AT bw107zhb DOT bluewin DOT ch> "R. Brenner" <rene DOT brenner AT NO_SPAM_PLZbluewin DOT ch> writes:
>I'm using NASM with DJGPP together.
>When I want to use an ASM routine, I wrote, in my C program,
>it works fine until I want to use it in a loop, like (for i=0; i<100; i++)
>routine().
>Then some really strange things happen like crashing or
>rebooting my computer...what helps?
>An example of an asm routine I use:
>(which doesnt work in a loop)
>_xcopy:
> push ebp
> mov ebp,esp
> mov esi,[ebp+8] ; param1 = source
> mov edi,[ebp+12] ; param2 = destination
> mov ecx,[ebp+16] ; param3 = length
> rep stosd
> mov esp,ebp
> pop ebp
> ret
Your problem is that you're trashing the values in esi and edi. DJGPP
assumes that eax, ecx and edx will be trashed by any function call, while
ebx, esi and edi will be preserved. The solution is simple: before you
write stuff to any of { ebx, esi, edi }, push them on the stack and pop
them off before you return.
BTW: ebp and esp are in the same category as ebx, esi and edi!
Hope that helps
Fabian
PS: you normally want to either cld or std before using a rep prefix
--
Fabian Nunez, MSc student Collaborative Visual Computing Laboratory,
fabian AT cs DOT uct DOT ac DOT za University of Cape Town
"Ram Disk" is NOT an installation procedure!
- Raw text -