title: Translate pseudo code to assembly
body: <p>I'm trying to translate some <em>C</em> pseudo code to i386 assembly code but never get it right. </p>
  
  <pre><code>n=1;
  s=50;
  a=0;  
  while(n &gt; 0) {
     a=s/n;
     n=n-1;
  }
  print a;
  </code></pre>
  
  <p>The code above is to be translated to assembly code through a compiler resulting in:</p>
  
  <pre><code>.data
  variables: .space 104
  msg: .asciz "Message %d\n"
  .text
  .global main
  main:
      push    $1
      pop variables+52
      push    $50
      pop variables+72
      push    $0
      pop variables+0
  L000:
      push    variables+52
      push    $0
      pop %ebx
      pop %eax
      cmp %ebx,%eax
      jl  L001
      push    variables+72
      push    variables+52
      pop %ebx
      pop %eax
      xor %edx,%edx
      idivl   %ebx
      push    %eax
      pop variables+0
      push    variables+52
      push    $1
      pop %ebx
      pop %eax
      sub %ebx,%eax
      push    %eax
      pop variables+52
      jmp L000
  L001:
      push    variables+0
      push    $msg
      call    printf
      add $8,%esp
  leave
  ret
  </code></pre>
  
  <p>I can't get the code to run correctly. It results in a segmentation fault. The output I get is:</p>
  
  <pre><code>Message 0
  Segmentation fault (core dumped)
  </code></pre>