Reputation: 319
The file in which there is inline asm code is of the form xyz.c I'm using Visual C++ 2010 Express IDE. I get the error mentioned in the title. Any help is appreciated! Thanks!
My code roughly looks like this.
#include "xyz.h"
/*
; Multi-line comments
;
*/
__asm{
Assembly code
}
/*
; Multi-line comments
;
*/
.
.
.
__asm{
Assembly code
}
/*
; Multi-line comments
;
*/
__asm{
Assembly code
}
Upvotes: 0
Views: 2602
Reputation: 4041
This example works for me :
#include <windows.h>
#include <iostream>
using namespace std;
int Add(int x, int y){
asm(
"addl %1, %0"
: "=r"(x)
: "m"(y), "0"(x)
);
return x;
}
int main ()
{
int x,y;
cout<<"Enter first number\n";
cin>>x; //enter first number
cout<<"Enter second number\n";
cin>>y; //enter second number
cout<<Add(x,y)<<endl;
return 0;
}
You can see the different syntax. But the asm{} or __asm__{} or whatever with {} does not work with minGW, only with visual studio apparently.
Upvotes: 0
Reputation: 92261
You can not put the asm code (or any other code) directly into the global scope. You have to put it inside a function.
void f()
{
__asm {
Some code
}
}
Upvotes: 2