title: Calling C++ Functions Inside an Assembly File
body: <p>This is my first time asking so I am going to do my best here, but I am having trouble on an assembly assignment in which I am given a .cpp file (below) and have to make an .asm file that contains a Multiply, Square, and Divide functions. The part I am having an issue with is that after the Square and Multiply functions are done, I have to call PrintResult to display the answer. For the Division, a successful divide returns a 1, and an unsuccessful one returns a 0 and call PrintResult to display the failure message. I am not allowed to edit his .cpp file, but I don't know how to successfully call PrintResult. I keep getting an error that says that there is an undefined symbol. </p>
  
  <p>Here is the .cpp given: </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  enum ResultCode { ShowSquare, ShowMultiply, ShowDivide, ShowRemainder, ShowDivideFailure };
  enum SuccessCode { Failure, Success };
  
  extern "C" SuccessCode Divide(long, long, long &amp;, long &amp;);
  extern "C" long Multiply(long, long);
  extern "C" void PrintResult(ResultCode, long);
  extern "C" long Square(long);
  
  void main()
  {
      long Num1;
      long Num2;
      long Result;
      long Remainder;
      do
      {
          cout &lt;&lt; "Enter Number to Square" &lt;&lt; endl;
          cin &gt;&gt; Num1;
          Result = Square(Num1);
          cout &lt;&lt; "Square is: " &lt;&lt; Result &lt;&lt; endl;
          cout &lt;&lt; "Enter two numbers to multiply" &lt;&lt; endl;
          cin &gt;&gt; Num1 &gt;&gt; Num2;
          Result = Multiply(Num1, Num2);
          cout &lt;&lt; "Result of multiply is: " &lt;&lt; Result &lt;&lt; endl;
          cout &lt;&lt; "Enter mumber to divide into then number to divide by" &lt;&lt; endl;
          cin &gt;&gt; Num1 &gt;&gt; Num2;
          if (Divide(Num1, Num2, Result, Remainder) == Success)
              cout &lt;&lt; "Result is " &lt;&lt; Result &lt;&lt; " and remainder is " &lt;&lt; Remainder &lt;&lt; endl;
          else
              cout &lt;&lt; "Attempted division by zero";
      } while (Result &gt; 0);
  }
  
  void PrintResult(ResultCode PrintCode, long Value)
  {
      switch (PrintCode)
      {
      case ShowSquare:
          cout &lt;&lt; "Display of square is: " &lt;&lt; Value &lt;&lt; endl;
          break;
      case ShowMultiply:
          cout &lt;&lt; "Display of multiply is: " &lt;&lt; Value &lt;&lt; endl;
          break;
      case ShowDivide:
          cout &lt;&lt; "Display of divide is " &lt;&lt; Value &lt;&lt; endl;
          break;
      case ShowRemainder:
          cout &lt;&lt; "Display of remainder is " &lt;&lt; Value &lt;&lt; endl;
          break;
      case ShowDivideFailure:
          cout &lt;&lt; "Display of Division by zero" &lt;&lt; endl;
          break;
      default:
          cout &lt;&lt; "Error in assembly routines" &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>And here is what I have so far as an .asm file:</p>
  
  <pre><code>.386
  .model flat
  .code
  
  public  _Square
  public  _Multiply
  public  _Divide
  
  
  _Square     proc
              mov     eax, [esp + 4]
              imul    eax, eax
              push    eax
  
              push    eax
              push    0
              call    _PrintResult
              add     esp, 8
  
              pop     eax
  
              ret
  _Square     endp
  
  _Multiply   proc
              mov     eax, [esp + 8]
              mov     ebx, [esp + 4]
              imul    eax, ebx
  
  
              ret
  _Multiply   endp
  
  _Divide     proc
  
  
              ret
  _Divide     endp
  
  
  end
  </code></pre>
  
  <p>Currently my _Square function has what I pulled from another answer on here, but does not work. It tells me that PrintResult is undefined. I have my _Multiply written out but it does not have the call of course and I can write in the _Divide as soon as I know how formatting something like that would look..</p>
  
  <p>Any help is more than appreciated!</p>