My professor posed a 'challenge' question to us in lecture on Friday. He gave us the assembly for a C program, then removed two constants from the C code. The Assembly:
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
And then the C code:
#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];
}
He then asked us what the values of M and N were.
What I've done so far:
movl %esp,%ebp ( This moves the esp register into the ebp register)
movl 8(%ebp),%eax (This moves the contents of 8 off of the ebp register into the eax register)
movl 12(%ebp),%ecx ( This moves the contents of 12 off of the ebp register into the ecx register)
sall $2,%ecx( This is shifting the number stored at the ecx left by 2 bits, so divide by 4)
leal 0(,%eax,8),%edx(I'm not sure what the 0 in front of the expression is doing, otherise it's loading eax*8 into the edx)
subl %eax,%edx (edx = edx - eax)
leal (%eax,%eax,4),%eax (eax = eax^2*4)
movl mat2(%ecx,%eax,4),%eax (eax = whatever mat2(ecx, eax, 4) is)
addl mat1(%ecx,%edx,4),%eax (eax = eax + whatever mat1(ecx, edx, 4) is)
The parts I don't understand are the mat1, mat2, and the leal with the 0 in front.
Thanks!
Edit: To sum up what I have so far:
ecx=ecx/4
edx=eax*8-eax
eax=eax*4+eax
I thought I'd be able to calculate the values of M and N after knowing what mat1 and mat2, were, but I'm either missing the obvious or there is a tad bit more to do. Any direction would be great.
Would ecx be j and eax be i?
Thanks again!
eax=eax^2*4? it's wrong... - Wagner Patriotaeax = eax + eax*4is NOTeax=eax^2*4- Wagner Patriota