正解:
1. 5040 (7!)
2. Factorial N (N!)
//
// Detailed explanation(s)
//
// Function: demo2!DoTheWork: (In assembly)
//
// Save the Prior Frame Pointer to the stack
//
0040101c 55 push ebp
//
// Set the Frame pointer to the current Stack pointer
//
0040101d 8bec mov ebp,esp
//
// Right at this point, the stack looks like:
// EBP = ESP
//
// EPB - N -- Local variables, if any (here there aren't)
// EBP -- Old EBP
// EBP + 4 -- Return Address back to calling function
// EBP + 8 -- First function Arg
//
//
// Put Arg1 into ECX
//
0040101f 8b4d08 mov ecx,dword ptr [ebp+8]
//
// Copy ECX into EAX
//
00401022 8bc1 mov eax,ecx
//
// LOOP: ECX--
//
00401024 49 dec ecx
//
// EAX = EAX * ECX
//
00401025 0fafc1 imul eax,ecx
//
// If EXC is greater than 2, goto LOOP:
//
00401028 83f902 cmp ecx,2
0040102b 7ff7 jg demo2!DoTheWork+0x8 (00401024)
//
// Else it wasn't, so replace the Old Frame Pointer
//
0040102d 5d pop ebp
//
// Return back to the calling function.
// Whatever is in EAX is effectively returned.
//
0040102e c3 ret
// Function: demo2!DoTheWork: (In C)
int DoTheWork(int Number)
{
int WorkingValue = Number;
int Factorial = WorkingValue;
do {
WorkingValue--;
Factorial *= WorkingValue;
}while (WorkingValue > 2);
return(Factorial);
}
0012fe9c 00406717 demo2!main+0x27 // Return address for DoTheWork
0012fea0 00000007 // Arg1 "7"
0012fea4 82059a87
备注:此处需要提示一下,因为当前的esp已经指向了返回地址,所以输入的参数应该是当前的esp+4
即:0012fea0其值为7,而不是由ebp+8进而得到的是esp+8,因为此时在ret之后,esp已经指向了函数的返回地址了。
3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.com/exam/