title: How to call C++ functions in my assembly code
body: <p>I need to call PrintResult from my assembly to display the result. I know I have to use extrn _PrintResult somewhere, and I should call the function using call _PrintResult but I'm not sure quite sure how to use it. any suggestions</p>
  
  <pre><code>public _Square
  
  .386
  
  .model flat
  
  .code
  
  _Square proc
  
  mov eax, [esp+4]
  
  imul eax
  
  ret
  
  _Square endp
  </code></pre>
  
  <p>.............Here is my C++ code.........</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  enum ResultCode {ShowSquare};
  enum SuccessCode {Failure, Success};
  
  extern "C" long Square (long);
  
  void main ()
   {
   long Num1; 
           long Num2;
  
   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;
    } while (Result &gt; 0);
   }
  
  void PrintResult (ResultCode PrintCode, long Value) //PrintCode, long Value)
   {
   switch (PrintCode)
    {
    case ShowSquare:
      cout &lt;&lt; "Display of square is: " &lt;&lt; Value &lt;&lt; endl;
      break;
  
    default:
      cout &lt;&lt; "Error in assembly routines" &lt;&lt; endl;
    }
  }
  </code></pre>