When run my assembly program keeps producing segmentation faults at the end. The program is suppose to print out the numbers from 1-100 and replace all numbers divisible by 5 and fifties by the word "Fizz". I have tried various options but I still keep getting segmentation fault. Can anyone look at my code and give me some pointers?
;program
extern printf
SECTION .bss
storage resd 1 ; reserve 1 dword
SECTION .data
fmt db "%d", 0dh,0ah,0 ; newline in formate now
fm1 db "%s", 10,0 ; newline in formate now
hello db "FiZZ", 0 ; the string
count equ 0 ; output ten times
SECTION .text
global main
main:
push ebp
mov ebp, esp ; stack related
mov eax, count
mov ecx, 0
mov ebx, 5
mov dword[storage], eax ; store eax's current value
nLoop:
mov eax, dword[storage] ; grab current count
add eax, 1
mov dword[storage], eax ; store new value for later
cmp eax, 5 ; check ecx equal to 5
je printFizz ; jump to printfizz if equal to 5
cmp eax, 10 ;
je printFizz ;
cmp eax, 15 ;
je printFizz ;
cmp eax, 20 ;
je printFizz ;
cmp eax, 25 ;
je printFizz ;
cmp eax, 30 ;
je printFizz ;
cmp eax, 35 ;
je printFizz ;
cmp eax, 40 ;
je printFizz ;
cmp eax, 45 ;
je printFizz ;
cmp eax, 50 ;
je printFizz ;
cmp eax, 51 ;
je printFizz ;
cmp eax, 52 ;
je printFizz ;
cmp eax, 53 ;
je printFizz ;
cmp eax, 54 ;
je printFizz ;
cmp eax, 55 ;
je printFizz ;
cmp eax, 56 ;
je printFizz ;
cmp eax, 57 ;
je printFizz ;
cmp eax, 58 ;
je printFizz ;
cmp eax, 59 ;
je printFizz ;
cmp eax, 60 ;
je printFizz ;
cmp eax, 65 ;
je printFizz ;
cmp eax, 70 ;
je printFizz ;
cmp eax, 75 ;
je printFizz ;
cmp eax, 80 ;
je printFizz ;
cmp eax, 85 ;
je printFizz ;
cmp eax, 90 ;
je printFizz ;
cmp eax, 95 ;
je printFizz ;
cmp eax, 100 ;
je EndFizz ;
push eax
push fmt
call printf
add esp, 12 ; clean 3 args (4 * 3)
mov eax, dword[storage] ; grab current count
cmp eax, 100
jne nLoop ; jum to the loop
leave ; also stack related
ret
printFizz:
push hello ; address of ctrl string
push fm1 ;
call printf ; Call C function
jmp nLoop
EndFizz:
push hello ; address of ctrl string
push fm1 ;
call printf ; Call C function
leave ; also stack related
ret