- 论坛徽章:
- 0
|
- unsigned int ihl)
- {
- unsigned int sum;
- //(%1)就是iph数据包首地址,%0就是sum, %2数据包长度
- //11-14行都是进行32位的加法运算
- __asm__ __volatile__(
- "movl (%1), %0 ;\n"
- "subl $4, %2 ;\n"
- [color=Red]"jbe 2f ;\n"[/color]
- "addl 4(%1), %0 ;\n"
- "adcl 8(%1), %0 ;\n"
- "adcl 12(%1), %0 ;\n"
- "1: adcl 16(%1), %0 ;\n"
- [color=Red]"lea 4(%1), %1 ;\n" //没看懂[/color]
- "decl %2 ;\n"
- [color=Red]"jne 1b ;\n"[/color]
- "adcl $0, %0 ;\n"
- "movl %0, %2 ;\n" //保存sum的值到%2
- "shrl $16, %0 ;\n" //右移16位(读取高16位)到%0
- "addw %w2, %w0 ;\n" //%0的16位加%2的16位
- "adcl $0, %0 ;\n" //若进位加上进位
- "notl %0 ;\n" //取反
- "2: ;\n"
- /* Since the input registers which are loaded with iph and ihl
- are modified, we must also specify them as outputs, or gcc
- will assume they contain their original values. */
- : "=r" (sum), "=r" (iph), "=r" (ihl)
- : "1" (iph), "2" (ihl)
- : "memory");
- return(sum);
- }
复制代码 代码中有几句没看明白:
"jbe 2f ;\n"
"jne 1b ;\n"
2f和1b是怎么计算出来的? |
|