//------------------------------------------------------------------- // repmovsl.cpp // // This file shows the inline assembly language syntax needed // for implementing a memory-to-memory copying operation with // the Pentium processor's special 'move-string' instruction. // // compile using: $ g++ -c -O repmovsl.cpp // examine using: $ objdump -d repmovsl.o // // Generic format of the 'asm' construct: // __asm__ __volatile__ ( // assembler instruction strings \ // : output operands (optional) \ // : input operands (optional) \ // : clobbered registers (optional) // ); // // Reference: // Rodriguez, Fischer and Smolski, "The Linux Kernel Primer," // Pearson Education, Inc. (2006), pages 55-57 (but note that // we had to omit all semicolons inside the 'asm' construct). // // programmer: ALLAN CRUSE // written on: 12 NOV 2005 //------------------------------------------------------------------- unsigned char *vram = (unsigned char*)0xA0000000; int hres = 1024, vres = 768; void copy_page( int src, int dst ) { int page_size = hres * vres; int long_count = page_size / 4; unsigned long *srcp = (unsigned long*)vram + long_count * src; unsigned long *dstp = (unsigned long*)vram + long_count * dst; __asm__ __volatile__ ( "movl %0, %%edi \n" \ "movl %1, %%esi \n" \ "movl %2, %%ecx \n" \ "cld \n" \ "rep movsl \n" : : "m" (dstp), "m" (srcp), "m" (long_count) : "ecx", "edi", "esi" ); }