; call2.asm code loopint.c for nasm ; /* call2.c a very simple loop that will be coded for nasm */ ; #include ; static void call2(int *A, int start, int end, int value); ; int main() ; { ; int dd1[100]; ; int i; ; dd1[0]=5; /* be sure loop stays 1..98 */ ; dd1[99]=9; ; call2(dd1,1,98,7); /* fill dd1[1] thru dd1[98] with 7 */ ; printf("dd1[0]=%d, dd1[1]=%d, dd1[98]=%d, dd1[99]=%d\n", ; dd1[0], dd1[1], dd1[98],dd1[99]); ; return 0; ; } ; static void call2(int *A, int start, int end, int value) ; { ; int i; ; ; for(i=start; i<=end; i++) A[i]=value; ; } ; execution output is dd1[0]=5, dd1[1]=7, dd1[98]=7, dd1[99]=9 section .bss i: resd 1 ; actually unused, kept in register section .text global call2 ; linker must know name of subroutine call2: ; name must appear as a nasm label push ebp ; save ebp mov ebp, esp ; ebp is callers stack push ebx ; save registers push edi mov edi,[ebp+8] ; get address of A into edi mov eax,[ebp+12] ; get value of start mov ebx,[ebp+16] ; get value of end mov edx,[ebp+20] ; get value of value loop1: mov [4*eax+edi],edx ; A[i]=value; add eax,1 ; i++; cmp eax,ebx ; i<=end jle loop1 ; loop until i=9 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, an address. ; ebp+12 would is our second argument, start a value.