Trying to implement strlen in x86 GAS

笑着哭i 提交于 2019-12-02 03:56:52

There are two problems with this code.

First, the cmp instructions don’t specify a size, and neither operand is a register, so it's ambiguous. For most instructions (like mov $0, (%rdi)), GAS would refuse to assemble it, but cmp for some reason assembles to cmpl, comparing a dword. Change the mnemonic to cmpb explicitly.

Second, before the first ret, it doesn’t pop the registers that were pushed. It would be better to jump to the end (and have a single ret).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!