need help understanding the movzbl call in this function

随声附和 提交于 2020-12-01 07:35:25

问题


So I'm trying to write some C code by looking at the assembly here:

pushl   %ebp
movl    %esp, %ebp
movl    12(%ebp), %eax
addl    8(%ebp), %eax
movzbl  (%eax), %eax
movsbl  %al,%eax
popl    %ebp
ret

I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here?


回答1:


A corresponding C function would be something like

char fn(char * string, int index)
{
    return string[index];
}

Specifically, the movzbl instruction fetches the byte stored at the sum of the two parameters, zero pads it, and stores it into eax. The movsbl instruction takes the lowest byte of eax, sign extends it, and stores the result back in eax.



来源:https://stackoverflow.com/questions/24253314/need-help-understanding-the-movzbl-call-in-this-function

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