博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Glibc中strlen的汇编实现
阅读量:2234 次
发布时间:2019-05-09

本文共 875 字,大约阅读时间需要 2 分钟。

strlen.c文件中的内联汇编代码如下:

#include 
size_tstrlen (const char *str){ int cnt; asm("cld\n" /* Search forward. */ /* Some old versions of gas need `repne' instead of `repnz'. */ "repnz\n" /* Look for a zero byte. */ "scasb" /* %0, %1, %3 */ : "=c" (cnt) : "D" (str), "0" (-1), "a" (0)); return -2 - cnt;}
经过gcc编译之后形成的汇编代码如下:

Disassembly of section .text:00000000 
: 0: 57 push %edi 1: b9 ff ff ff ff mov $0xffffffff,%ecx 6: b8 00 00 00 00 mov $0x0,%eax b: 8b 7c 24 08 mov 0x8(%esp),%edi f: fc cld 10: f2 ae repnz scas %es:(%edi),%al 12: b8 fe ff ff ff mov $0xfffffffe,%eax 17: 29 c8 sub %ecx,%eax 19: 5f pop %edi 1a: c3 ret

转载地址:http://oxnbb.baihongyu.com/

你可能感兴趣的文章
【算法】对于大数的操作
查看>>
【操作系统】系统调用的概念
查看>>
【计算机网络】cookie和session的区别
查看>>
【C++】构造函数、析构函数抛出异常的问题
查看>>
【C++】关于vector<bool>
查看>>
【操作系统】内存碎片产生原因及终极解决办法
查看>>
幂等性验证思想
查看>>
DB理论--数据存储方式
查看>>
PB协议的说明与使用
查看>>
什么是TPS,什么是QPS,区别是什么?
查看>>
git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:
查看>>
arraylist扩容时机java8
查看>>
logback中additivity的理解
查看>>
一篇文章搞懂hash,hashcode,equals,==的用法
查看>>
mysql数据库,悲观锁。for update 的用法。
查看>>
springboot+jta+atomikos多数据源和 springboot+mybatisplus+aop实现数据库读写分离而引发的一些思考
查看>>
java面试中常考的一些面试sql语句
查看>>
一个字节等于多少位?
查看>>
帧框架frameset的用法总结
查看>>
java1.8中创建hashmap的初始化大小设置标准
查看>>