//------------------------------------------------------------------- // trybswap.cpp // // This is the code we wrote quickly during class to answer the // question, asked by Zahara Docena, about whether 'bswap' will // operate as we expect when it's used with a 64-bit register. // Of course we could have looked up the 'bswap' instruction in // Volume 2A of the Intel Software Developer's Manual (online), // but this was a good opportunity to employ 'inline' assembly // language within a 'high-level' programming language example. // // to compile: $ g++ trybswap.cpp -o trybswap // to execute: $ ./trybswap // // programmer: ALLAN CRUSE // written on: 20 APR 2009 //------------------------------------------------------------------- #include // for printf() unsigned long long x; int main( int argc, char **argv ) { x = 0x0123456789ABCDEF; printf( "\n x = %016llX \n", x ); asm(" mov x, %rax "); asm(" bswap %rax "); asm(" mov %rax, x "); printf( "\n x = %016llX \n", x ); }