'Compile C++ and MASM together
I'm doing an exercise of an online course about MASM, specifically a project that use both C++ and MASM. The code of the C++ file is this:
#include <stdlib.h>
#include <iostream>
extern "C" void reverser(int *y, const int *x,int n);
int main(){
using std::cout;
using std::endl;
const int n = 10;
int x[n], y[n];
for(int i = 0; i < n; i++)
x[i] = i;
reverser(y, x, n);
for(int i = 0x0 ; i < n; i++){
printf("x: %5d y: %5d", x[i], y[i]);
}
return 0;
}
The code of the MASM file is this:
.386
.model flat, c
.code
reverser proc
push ebp
mov ebp,esp
push esi
push edi ; Function Prologue
xor eax,eax
mov edi,[ebp+8]
mov esi,[ebp+12]
mov ecx,[ebp+16]
test ecx,ecx
lea esi,[esi+ecx*4-4]
pushfd
std
@@: lodsd
mov [edi], eax
add edi,4
dec ecx
jnz @B
popfd
mov eax,1
pop edi
pop esi
pop ebp
ret
reverser endp
end
On the online course the person speaking compile it with no problem using Visual Studio but if I try to compile the cpp file using gcc I get an error:
undefined reference to 'reverser'
So I tryed to add
#include "reverser.asm"
to the code but then I get the errors:
reverser.asm:1:error: expected unqualified-id before numeric constant
reverser.asm:1:error: expected ',' or ';' before numeric constant
reverser.asm:9:error: 'Prologo' does not name a type
reverser.asm:21:error: stray '@' in program
So I have the following questions:
- How can I fix this?
- How I can compile on Windows the 2 files together using the command-line? Like using masm.exe and gcc.exe to compile.
- Why on the course it compiled without any problem?
Thank you so much, have a nice day! :D
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
