Calling NASM function in C
<p>I'm trying to learn x86 assembler, and I want to call a <em>NASM</em> function in <em>C</em>. When i run my program I get this error: </p>

<blockquote>
  <p>Segmentation fault (Core dumped) </p>
</blockquote>

<p>I've tried dozens of variations of my simple test function but it stops every time at the same position.</p>

<p>Here are my <code>asm</code> and <code>c</code> files:</p>

<p>div.asm:</p>

<pre><code>global _test

_test:
    push    ebp
    mov     ebp, esp
    push    ebx
    mov     eax, [ebp+8]
    mov     ebx, [ebp+12]
    div     ebx
    pop     ebp
    ret
</code></pre>

<p>main.c:</p>

<pre><code>#include &lt;stdio.h&gt;

extern unsigned int test (unsigned int, unsigned int);

int main(void)
{
    printf("%d\n", div(85,5));
    return 0;
}
</code></pre>

<p>I compile &amp; link the files with:</p>

<pre><code>nasm -f elf -o div.o div.asm
gcc -m32 -c -o main.o main.c
gcc -m32 -o run div.o main.o
</code></pre>

<p>I use a <code>64 Bit Linux</code> in a <code>Virtual Machine</code>.</p>

<p>What is my mistake here, and how can I fix it?</p>