编译C++和乳胶在一起
我正在进行有关 masm ,特别是使用C +++++的项目,和玛斯。
C ++文件的代码是:
#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;
}
MASM文件的代码是:
.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
在在线课程中,使用Visual Studio的人会毫无问题地对其进行编译,但是如果我尝试使用GCC编译.CPP文件,我会得到错误:
未定义的引用'Reverser'
因此我尝试添加
#include "reverser.asm"
到代码中,但是后来我得到了错误:
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
所以我有以下问题:
- 如何解决此问题?
- 如何使用命令行在Windows上将两个文件一起编译在一起?喜欢使用 masm.exe 和 gcc.exe 进行编译。
- 为什么在课程中没有任何问题进行编译?
I'm doing an exercise of an online course about MASM, specifically a project that uses 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
In the online course, the person speaking compiles it without any 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 tried 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 the two files together on Windows using the command-line? Like using masm.exe and gcc.exe to compile.
- Why did it compile without any problem in the course?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论