long strlength(unsigned char *string) { asm ( "xorl %%eax, %%eax \n\t" "cmpl $0, %%edi \n\t" "je Strlength_Zero \n\t" "repne \n\t" "scasb \n\t" "negl %%ecx \n\t" "subl $2, %%ecx \n\t" "movl %%ecx, %%eax \n\t" "Strlength_Zero: \n\t" : :"D"(string), "c"(0xFFFFFFFF) :"%eax" ); }; #define memset8(where, what, howmuch) asm ("repnz \n\t""stosb \n\t"::"D"(where), "a"(what), "c"(howmuch)) void memset32(void *where, unsigned char what, unsigned long howmuch) { asm ( "movb %%al,%%ah \n\t" "movl %%eax,%%edx \n\t" "sall $16,%%eax \n\t" "movw %%dx,%%ax \n\t" "pushl %%ecx \n\t" "shrl $2, %%ecx \n\t" "rep \n\t" "stosl \n\t" "popl %%ecx \n\t" "andl $3, %%ecx \n\t" "rep \n\t" "stosb \n\t" : :"D"(where), "a"(what), "c"(howmuch) :"%edx" ); } void memsets(void *where, const void *what, unsigned long howmuch) { asm ( "pushl %%ecx \n\t" "shrl $2, %%ecx \n\t" "rep \n\t" "stosl \n\t" "popl %%ecx \n\t" "andl $3, %%ecx \n\t" "rep \n\t" "stosb \n\t" : :"D"(where), "a"(*(unsigned long *)what), "c"(howmuch) ); } void memcpyf(void *dest, void *src, unsigned long count) { asm ( "std \n\t" "addl %%ecx, %%edi \n\t" "addl %%ecx, %%esi \n\t" "decl %%esi \n\t" "decl %%edi \n\t" "movb %%cl, %%al \n\t" "shrl $2, %%ecx \n\t" "andb $3, %%al \n\t" "subl $3, %%edi \n\t" "subl $3, %%esi \n\t" "rep \n\t" "movsl \n\t" "movb %%al, %%cl \n\t" "addl $3,%%edi \n\t" "addl $3,%%esi \n\t" "rep \n\t" "movsb \n\t" "cld \n\t" : :"D"(dest), "S"(src), "c"(count) :"%eax" ); } void memcpyb(void *dest,void *src,unsigned long count) { asm ( "push %%ecx \n\t" "shrl $2, %%ecx \n\t" "rep \n\t" "movsl \n\t" "popl %%ecx \n\t" "andl $3, %%ecx \n\t" "rep \n\t" "movsb \n\t" : :"D"(dest),"S"(src),"c"(count) ); } #define memcpy(dest,src,count) memcpyb(dest,src,count) void puttxt(const char *text) { asm( /* if (text!=NULL) { */ "cmpl %%eax, %%esi \n\t""je Puttxt_End \n\t" /* while (*text!=0) { */ "Puttxt_WhileStart: \n\t""movb (%%esi), %%cl \n\t""jecxz Puttxt_End \n\t" /* putc (*text, stdout); */ "subl $8, %%esp \n\t""pushl $___dj_stdout \n\t""pushl %%ecx \n\t""call _putc \n\t""addl $16, %%esp \n\t" /* text++; */ "incl %%esi \n\t" /* } */ /* } */ "jmp Puttxt_WhileStart \n\t""Puttxt_End: \n\t" ::"S"(text), "a"(NULL), "c"(0) ); } #define printc(char) putc(char, stdout)