S
S
sham632018-01-24 18:55:03
C++ / C#
sham63, 2018-01-24 18:55:03

How to solve problem with inserting asm in c++ code blocks?

I'm trying to build a program in Code Blocks (17.12) , it gives an error error: '_asm' was not declared in this scope
The program code itself

#include <iostream>
using namespace std;
 
int main()
{
    setlocale(0,"RUS");
 
    char b[] = {"abcdef"};
_asm
{
mov ecx,6
lea edx,b[0]
oncemore:
add [edx],3
add edx,1
loop oncemore
}
 
cout<<b<<endl;
 
 
    system("pause");
    return 0;
}

How can the problem be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sakhno, 2018-01-24
@Punk_Joker

asm and not _asm
_asm seems to be in VS, but here is GCC

M
MiiNiPaa, 2018-01-24
@MiiNiPaa

Correct syntax:

asm( // Внимание на скобку!
   "Строка, содержащая твой код"
);

In order not to suffer with escaping characters, starting with C ++ 11, you can use raw literals:
asm(R"(
mov ecx,6
lea edx,b[0]
oncemore:
add [edx],3
add edx,1
loop oncemore
)");

Oh yes, I forgot to mention: GCCC uses AT&T assembler by default. To switch it to Intel syntax, you need to pass the appropriate switch to the compiler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question