阅读:1351回复:2
高手救急,AT&T转为X86方式?
/**
42 | * ip_fast_csum - Compute the IPv4 header checksum efficiently. 43 | * iph: ipv4 header 44 | * ihl: length of header / 4 45 | */ 46 | static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) 47 | { 48 | unsigned int sum; 49 | 50 | asm( " movl (%1), %0\n" 51 | " subl $4, %2\n" 52 | " jbe 2f\n" 53 | " addl 4(%1), %0\n" 54 | " adcl 8(%1), %0\n" 55 | " adcl 12(%1), %0\n" 56 | "1: adcl 16(%1), %0\n" 57 | " lea 4(%1), %1\n" 58 | " decl %2\n" 59 | " jne 1b\n" 60 | " adcl $0, %0\n" 61 | " movl %0, %2\n" 62 | " shrl $16, %0\n" 63 | " addw %w2, %w0\n" 64 | " adcl $0, %0\n" 65 | " notl %0\n" 66 | "2:" 67 | /* Since the input registers which are loaded with iph and ipl 68 | are modified, we must also specify them as outputs, or gcc 69 | will assume they contain their original values. */ 70 | : "=r" (sum), "=r" (iph), "=r" (ihl) 71 | : "1" (iph), "2" (ihl) 72 | : "memory"); 73 | return(sum); 74 | } 我不懂At&t格式的汇编,高手帮我把他转为x86格式的!谢谢! |
|
|
沙发#
发布于:2005-07-08 11:51
static _inline unsigned short ip_fast_csum(unsigned char* iph, unsigned int ihl)
{ unsigned int cksum = 0; __asm { push eax push ebx push ecx mov ebx , dword ptr [iph] mov edx, dword ptr [ihl] mov eax, dword ptr [ebx] sub edx, 0x04 jbe EXIT add eax, dword ptr [ebx + 4] adc eax, dword ptr [ebx + 8] adc eax, dword ptr [ebx + 12] BEGIN: adc eax, dword ptr [ebx + 16] lea ebx, dword ptr [ebx + 4] dec edx jne BEGIN adc eax, 0x00 mov edx, eax shr eax, 0x0f add ax, dx adc eax, 0x00 not eax EXIT: mov dword ptr [cksum] , eax pop ecx pop ebx pop eax } return cksum; } 高手看看错在哪里啊? |
|
|
板凳#
发布于:2005-07-11 09:48
完成转换,结帖
|
|
|