需要帮助理解此函数中的 movzbl 调用 [英] need help understanding the movzbl call in this function

查看:44
本文介绍了需要帮助理解此函数中的 movzbl 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图通过查看这里的程序集来编写一些 C 代码:

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

我看到我有两个变量,它们被加在一起,然后在查看函数何时开始调用 movzbl 和 movebl 时我迷路了.这是怎么回事?

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?

推荐答案

一个对应的 C 函数应该是这样的

A corresponding C function would be something like

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

具体来说,movzbl 指令提取存储在两个参数总和中的字节,将其补零,然后将其存储到 eax 中.movsbl 指令获取 eax 的最低字节,对其进行符号扩展,并将结果存储回 eax.

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.

这篇关于需要帮助理解此函数中的 movzbl 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆