用匯編寫特殊要求的strlen
題目:不允許調用庫函數,也不允許使用任何全局或局部變量編寫 int strlen(char *strDest);
用匯編的實現:
- int strlen(const char *s)
- {
- __asm__ __volatile__("movl %%esi,%%eax;0:testb $0xFF,(%%eax);"
- "jz 1f;inc %%eax;jmp 0b;"
- "1:subl %%esi,%%eax;"::"S"(s));
- }
最後更新:2017-04-02 00:06:38