1 ; loopint2.asm code loopint2.c for nasm 2 ; /* loopint2.c another simple loop that will be coded for nasm */ 3 ; #include 4 ; int main() 5 ; { 6 ; int dd1[100]; 7 ; int i; 8 ; dd1[0]=5; /* be sure loop stays 1..98 */ 9 ; dd1[99]=9; 10 ; for(i=98; i>0; i--) dd1[i]=7; /* ONLY CHANGE !! */ 11 ; printf("dd1[0]=%d, dd1[1]=%d, dd1[98]=%d, dd1[99]=%d\n", 12 ; dd1[0], dd1[1], dd1[98],dd1[99]); 13 ; return 0; 14 ;} 15 section .bss 16 00000000 dd1: resd 100 17 00000190 i: resd 1 ; actually unused, kept in register 18 19 section .text 20 global main 21 00000000 C705[00000000]0500- main: mov dword [dd1],5 ; dd1[0]=5; 22 00000008 0000 23 0000000A C705[8C010000]0900- mov dword [dd1+99*4],9 ; dd1[99]=9; 24 00000012 0000 25 26 00000014 B962000000 mov ecx,98 ; i=98; ecx is special for 'loop' instruction 27 00000019 C7048D[00000000]07- loop1: mov dword [dd1+4*ecx],7 ; dd1[i]=7; 28 00000021 000000 29 00000024 E2F3 loop loop1 ; loop while i>0, decrements ecx 30 31 extern printf ; the C function, to be called 32 section .data ; Data section, initialized variables 33 00000000 6464315B305D3D2564- fmt: db "dd1[0]=%d, dd1[1]=%d, dd1[98]=%d, dd1[99]=%d",10,0 34 00000009 2C206464315B315D3D- 35 00000012 25642C206464315B39- 36 0000001B 385D3D25642C206464- 37 00000024 315B39395D3D25640A- 38 0000002D 00 39 40 section .text ; Code section, continued 41 00000026 FF35[8C010000] push dword [dd1+99*4] ; dd1[99] 42 0000002C FF35[88010000] push dword [dd1+98*4] ; dd1[98] 43 00000032 FF35[04000000] push dword [dd1+4] ; dd1[1] 44 00000038 FF35[00000000] push dword [dd1] ; dd1[0] 45 0000003E 68[00000000] push dword fmt ; address of format string 46 00000043 E8(00000000) call printf ; Call C function 47 00000048 83C414 add esp, 20 ; pop stack 5 push times 4 bytes 48 49 0000004B B800000000 mov eax,0 ; normal, no error, return value 50 00000050 C3 ret ; return 0; 51 ; no registers needed to be saved