Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 420
Princi Avatar asked Nov 14 '22 04:11

Princi


1 Answers

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.

like image 99
snemarch Avatar answered Jan 10 '23 22:01

snemarch