Lennyk <lennyk430@xxxxxxxxx> writes: > According to the guide - the corresponding GCC translation - should > look like this: > > void bswap(int* n) > { > asm("movl %0, %%eax" : : "g" (*n)); > asm("bswap %eax"); > asm("movl %%eax, %0" : "=g" (*n)); > } > > But, for some reason, the result is not a "bswapped" n. > Why? * What does the generated code look like? * You shouldn't break up the asm statements like that--write one asm with three assembler statements. * Let the compiler do the data movement for you; it's good at it. * If you're going to clobber %eax in an asm, you need to say so explicitly; that's probably why this code sequence is breaking. asm("bswap %%eax" : : : "eax"); Anyhow, I would write it like this: void bswap(int* n) { asm("bswap %0" : "=r" (*n) : "0" (*n)); } Ian