【发布时间】:2014-06-13 11:07:08
【问题描述】:
我的教授在周五的讲座中向我们提出了一个“挑战”问题。他给了我们一个 C 程序的程序集,然后从 C 代码中删除了两个常量。 大会:
sum_element:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl 12(%ebp),%ecx
sall $2,%ecx
leal 0(,%eax,8),%edx
subl %eax,%edx
leal (%eax,%eax,4),%eax
movl mat2(%ecx,%eax,4),%eax
addl mat1(%ecx,%edx,4),%eax
movl %ebp,%esp
popl %ebp
ret
然后是C代码:
#define M ____
#define N ____
int mat1[M][N];
int mat2[N][M];
int sum_element(int i, int j)
{
return mat1[i][j] + mat2[i][j];
}
然后他问我们 M 和 N 的值是多少。
到目前为止我做了什么:
movl %esp,%ebp(这会将 esp 寄存器移动到 ebp 寄存器中)
movl 8(%ebp),%eax(这会将 8 的内容从 ebp 寄存器移到 eax 寄存器中)
movl 12(%ebp),%ecx(这会将 12 的内容从 ebp 寄存器移到 ecx 寄存器中)
sall $2,%ecx(这是将存储在ecx中的数字左移2位,因此除以4)
leal 0(,%eax,8),%edx(我不确定表达式前面的 0 是做什么的,否则它会将 eax*8 加载到 edx 中)
subl %eax,%edx (edx = edx - eax)
leal (%eax,%eax,4),%eax (eax = eax^2*4)
movl mat2(%ecx,%eax,4),%eax(eax = mat2(ecx, eax, 4) 是什么)
addl mat1(%ecx,%edx,4),%eax(eax = eax + mat1(ecx, edx, 4) 是什么)
我不明白的部分是mat1、mat2和前面有0的leal。
谢谢!
编辑:总结一下我目前的情况:
ecx=ecx/4
edx=eax*8-eax
eax=eax*4+eax
我想在知道 mat1 和 mat2 是什么之后,我可以计算 M 和 N 的值,但我要么错过了明显的东西,要么还有更多工作要做。任何方向都会很棒。
ecx 是 j,eax 是 i 吗?
再次感谢!
【问题讨论】:
-
你从哪里得到
eax=eax^2*4?错了…… -
from leal (%eax,%eax,4),%eax 实际上是 eax = eax + eax*4?
-
eax = eax + eax*4不是eax=eax^2*4