Okay, for a lab assignment, I need to construct a C++ program that will call an Assembly Language procedure. The provided code is not what I am going to turn in. It is just a dummy program which is to help me get a better understanding on how to do it. Unfortunately, I cannot get the C++ program to call the assembly language program. It assembles and builds fine, but it just does not call the ASM program. I was wondering if anyone here could help me out?
Here is the header file (called Solution.h):
Code:
//
//
extern "C"
{
int AsmTest(float* a, float* b, float* c);
}
Here is the ASM code (called AsmTest):
Code:
TITLE
; Author:
; Class:
; Date:
;
.586
.model flat,C
AsmTest PROTO,
aVal:PTR REAL8, bVal:PTR REAL8, cVal:PTR REAL8
.data
value REAL8 3.5
answer INT 1
.code
AsmTest PROC,
aVal:PTR REAL8, bVal:PTR REAL8, cVal:PTR REAL8
FINIT
FLD aVal
FMUL bVal
FSTP aVal
FLD value
FSTP cVal
int 3
mov EAX, answer
ret
AsmTest ENDP
;------------------------------------------------------------------------------
END
Here is the main procedure:
Code:
//
//
#include <iostream>
#include "Solution.h"
using namespace std;
int main()
{
float a;
float b;
float c;
int x;
cout << "Enter the first decimal number (if it does not have a decimal number," << '\n'
<< "then put a .0 at the end of the number): ";
cin >> a;
cout << "Enter the second decimal number (if it does not have a decimal number," << '\n'
<< "then put a .0 at the end of the number): ";
cin >> b;
cout << "Enter the third decimal number (if it does not have a decimal number," << '\n'
<< "then put a .0 at the end of the number): ";
cin >> c;
float* a2 = &a;
float* b2 = &b;
float* c2 = &c;
x = AsmTest(a2, b2, c2);
cout << a << '\n' << b << '\n' << c << '\n' << x << endl;
system("Pause");
return 0;
}
Just FYI, I made these using Microsoft Visual Studio 2010, and I placed the ASM file in the Source Files of the Visual Studio Solution Explorer.