Mixed C++ and ASM


/*
Identification C. S.
   Assignment: Funcs.cpp
   Due Date:
   Class:      CIS 253 01
   Purpose: Demonstrate assembly call from C++
   Steps:   get value from user
            double value
            print value
*/

#include <iostream>

int Func1(int);

using namespace std;
int main( )
{
   int first;

   //prompt for and accept  value from the user
   cout << "Enter a number & hit enter: ";
   cin >> first;

   // Call Func1 which will (in assembly) double the value
   answer = Func1(first);

   //Print the result on the screen in a message
   cout << first << " after it was doubled, is "
        << answer << endl << endl;

   return 0;
}

int Func1(int num1) // pass in the number by value
{
   // double it
       
   __asm // NOTE: TWO underscores - this is ASSEMBLY code
   {
      ;moves value to be added to eax 32 bit REGISTER in CPU
      mov eax, num1 
      
      ;add the value in memory to REgISTER value and store back in REG
      add eax, num1 
      
      ;move the value to num1 to return
      mov num1, eax 
   }

   return num1;
}