title: Assembly language multiplication problems
body: <p>So i have a problem running a homework assignment for assembly code. The code is supposed to just do simple multiplication but it can't use the imul function or anything simple like that, it has to use shifts. </p>
  
  <p>There must be something wrong with the assembly code because when I have emacs compile and run main.c and multiply.s, without having main.c actually call the multiply function, it outputs just fine. On the other hand, when I have it call the multiply function, it forces it not to have output</p>
  
  <p>INPUT I HAVE:</p>
  
  <p>I'm expecting my c file, with the following code, to call multiply on x and y, which are defined as 34 and 47 respectively.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  extern int multiply();
  extern int x, y;
  
  int main()
  {
    x = 34;
    y = 47;
    printf("%d * %d = %d\n", x, y, multiply());
  }
  </code></pre>
  
  <p>OUTPUT I EXPECT:
  I expect it to run multiply, which should correctly calculate the product of the two, and then print out the following</p>
  
  <pre><code>34 * 47 = 1598
  </code></pre>
  
  <p>OUTPUT I GET:</p>
  
  <p>None. I get a message when I run it from the shell command saying </p>
  
  <pre><code>Shell command executed with no output
  </code></pre>
  
  <p>MY PROBLEM:</p>
  
  <p>I keep getting an error when I run <code>gcc -m32 main.c multiply.s</code> that says</p>
  
  <pre><code>gcc -m32 multiply.s main.c
  ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _multiply from /var/folders/ct/6_dmqq_11s9951v72wbcx06m0000gn/T//cc9DcDxr.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
  </code></pre>
  
  <p>It generates an a.out file, and when I run the a.out file from the shell it gives me this</p>
  
  <pre><code>(Shell Command succeeded with no output)
  </code></pre>
  
  <p>Ideas?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>.globl _multiply
  _multiply:
  .data
      .globl _x
      .globl _y
  
  _prod:  .long   0
  _x: .long 0
  _y: .long 0
  
  pushl %ebp
  movl %ebp,%esp
  
  
  movl _x,%eax
  movl _y,%edx
      movl $1,%ecx
  
  LOOP:
  cmpl $0,%eax
  je DONE
  
  and %eax,%ecx
  cmp $0,%ecx
  je CONTINUE
  add %edx,_prod
  
  CONTINUE:
  shrl $1,%eax
  shll $1,%edx
  jmp LOOP
  
  DONE:
      movl _prod,%eax
  popl %ebp
  ret
  </code></pre>