; call1.asm a basic structure for a subroutine to be called from "C" ; ; This saves more registers than used here ; Parameters: int L[] or int *L ; Result: L[0]=0 L[1]=0 global call1 ; linker must know name of subroutine call1: ; name must appear as a nasm label push ebp ; save ebp mov ebp, esp ; ebp is callers stack push ebx ; save registers push edi push esi mov edi,[ebp+8] ; get address of L into edi mov eax,0 ; get a 32-bit zero mov [edi],eax ; L[0]=0 add edi,4 ; add one dword=32-bit int mov [edi],eax ; L[1]=0 pop esi ; restore registers pop edi ; in reverse order pop ebx mov esp,ebp ; restore callers stack frame pop ebp ret ; return ; ; Notes about the callers stack, ebp in our code: ; ebp+8 is the last argument passed to us by the caller, ; this is our first argument ; ebp+12 would be our second argument, etc. +4 each ; the arguments can be values or addresses, ; as defined by the "C" function prototypes ; ebp+4 is the return address in the caller, used by 'ret' ; ebp which is our starting esp, is the next available stack space