What in this code is causing a Seg fault? <p>I am very new to Assembly programming and to learn NASM I decided to try and write a prime number testing. I wrote the code for the <code>is_prime</code> function in 32-bit elf NASM and wrote a wrapper in c++ that uses externs the NASM function. When I compiled both programs to <code>.o</code> files there were no errors, and when I linked the object files to make an executable it linked correctly. However when I try to run it I keep getting a <code>Segmentation Fault</code> error and I have no idea what this actually means or how to correct it. The code that I wrote in NASM looks like this:</p> <pre><code>section .bss n: resb 1 i: resb 1 m: resb 1 section .text global is_prime is_prime: push ebp mov ebp,esp mov eax,[ebp + 8] jmp main main: mov [n],eax mov byte [i],2 mov eax,[i] mov ebx,[n] cmp eax,ebx jge prime mov eax,[i] mov ebx,[n] call mod cmp byte [m],0 je comp jmp main mod: mov ecx,ebx xor edx,edx div ecx mov [m],edx ret comp: mov eax,0 jmp kill prime: mov eax,1 jmp kill kill: ret leave </code></pre> <p>My main question is, am I doing something wrong in my assembly program that is causing this error and if so, how do I fix this? Or is there something wrong in the way I am linking/compiling it? I am using a 64-bit Ubuntu but I used the <code>-m32</code> and <code>-f elf32</code> options while compiling. </p>