Princi
Princi

Reputation: 76

Converting GNU asm calls to VC++

I have been porting a linux application to windows platform.

Here is the linux code,

 __asm__ __volatile__ ("lock; cmpxchgl %1, %2"
                      : "=a" (prev)
                      : "q" (new_value), "m" (*ptr), "0" (old_value)
                     : "memory");

I tried using _asm volatile but I get an error saying "inline assembler syntax error in 'opcode'; found 'data type'" in Visual studio 2012.

I need something windows equivalent code. Any info/suggestion please.

Upvotes: 4

Views: 1748

Answers (2)

gilgamash
gilgamash

Reputation: 902

I think the main problem here is that Visual Studio uses Intel style inline assembly language, which you are not using.

Check this out: http://msdn.microsoft.com/en-us/library/4ks26t93%28v=vs.80%29.aspx

Concerning the volatile specifier and reordering, even using o2 optimization I have not yet seen VS 2010 or 2012 reordering __asm blocks.

Greetings, Andy

Upvotes: 0

snemarch
snemarch

Reputation: 5018

In general, I prefer external assembly modules to inline assembly - it's more portable (yeah, portable and assembly used in the same sentence). Assemblers like nasm and yasm are available for multiple platforms, and can produce multiple object file formats.

External assembly modules aren't good for really performance-critical one-liners like your code - consider using compiler intrinsics instead of inline assembly. You might want to check out Portable Compare And Swap.

Upvotes: 1

Related Questions