AT&T汇编处理字符串
注:以下内容为学习笔记,多数是从书本、资料中得来,只为加深印象,及日后参考。然而本人表达能力较差,写的不好。因非翻译、非转载,只好选原创,但多数乃摘抄,实为惭愧。但若能帮助一二访客,幸甚!
一.传送字符串把字符串从一个内存位置复制到另一个内存位置。
# Finding the len of a string useing the SCAS instruction.section .dataoutput:.asciz"The len of the str is : %d.\n"str:.asciz"I am learning AT&T assembly language."len:.int. - str - 1# 减一表示去掉最后的'0'.section .text.global _start_start:noppushllenpushl$outputcallprintfaddl$8,%esplealstr,%edimovl$0xffff,%ecx# 支持的最大长度0xfffff = 65535movb$0,%alcldrepnescasb# 每次迭代ECX递减jnenotfoundsubw$0xffff,%cx# %cx-0xffff为进行了多少次迭代的负数neg%cx# 求补,即负数变整数dec%cx# 减去‘0’,即字符串长度不包含最后的‘0’movl$1,%eaxmovl%ecx,%ebxint$0x80notfound:movl$1,%eaxmovl$0,%ebxint$0x80运行:
用两种方法求得字符串的长度,两者相等。