5

I am trying to compile an old C++ software project in Code::Blocks using the gcc compiler, and after fixing a few other issues, I've hit a wall: the project has a file with Intel-style inline ASM written as

_asm {
  code here
}

and the compiler refuses to compile it with "error: '_asm' was not declared in this scope".

I've spent a while Googling around looking for solutions, but the only ones I can find are to add -masm=intel to the build options (which I've tried and can't get to work), or to convert the code to asm ("code here"); (which isn't feasible because of the sheer amount of ASM). Does anyone know how I can get gcc to compile this code as-is, or should I give up and use a different compiler?

4
  • How about generating a macro, and then using a script to replace the _asm lines with the macro. Then you get better compiler independence.
    – daramarak
    Jun 28, 2012 at 11:16
  • A macro would be an idea, though I've never used one before so I'd have to figure that out too (despite what my question made it sound, I'm actually pretty much a complete noob with this stuff =/ ). In addition, asm routines are linked together with labels or something (_asm {\n code here\n } L01: __asm ...), and I'm not sure how to handle that. Jun 28, 2012 at 11:25
  • The code will not compile as-is, you will need to change it to get it to compile with gcc (or use MSVC instead).
    – Jesse Good
    Jun 28, 2012 at 11:26
  • Recently Clang added support for MS-style inline assembly. Sep 27, 2016 at 2:28

2 Answers 2

2

GCC uses a very different syntax for inline assembler, so you won't be able to handle it with trivial changes. I see the following options:

  1. Rewrite everything in GCC syntax or as C code
  2. Make some script to translate to GCC syntax (non-trivial task)
  3. Compile the code with whatever compiler it was written for (MSVC?)
3
  • Option 2 is insanely optimistic. Forget it!
    – TonyK
    Jun 28, 2012 at 14:08
  • Option 1 is not an option; the file in question consists entirely of asm and weighs in at 83 kb, with several hundred functions. It's looking like I'll just have to switch compilers, then. Jun 28, 2012 at 17:51
  • 1
    Someone actually did Option 2, it's called intel2gas, I've used it in similar porting efforts. Sep 27, 2016 at 1:39
0

You simply can't get gcc to compile the code 'as is'. If you need to compile this thing using gcc, you have to rewrite the code, in C++ or gcc-compatible asm. If there really is a lot of assembly code -- say, 200 instructions or more -- it might be worthwhile learning the gcc assembler syntax; if not, code it in C++.

1
  • See my comment on Igor's answer; rewriting isn't an option in this case because there are thousands of instructions (200 would be a pretty nice step down!). Jun 28, 2012 at 17:56

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.