| New Reply |
x86 Assembly Calling Another Function |
Share Thread | Thread Tools |
| Nov25-12, 03:44 PM | #1 |
|
|
x86 Assembly Calling Another Function
1.
firstFunction (parameters has an input and an output){ (ebx holds the input, ecx holds the output) ........... mov eax, 1 push ebx call factorial pop ebx ....... } factorial(unsigned int n){ push ebx mul ebx } 3. I understand that you push ebx in the first function because you want to pass the input number to the factorial function. However, why does factorial function need to push ebx again? In addition, the line mul ebx (multiplies with eax) how does it know to multiply with eax. I thought I had to do something like mul ebx, eax yet that causes the build to fail. |
| Nov25-12, 06:58 PM | #2 |
|
Recognitions:
|
Seems like there's missing code from this. It appears the goal is a recursive version of factorial, but the factorial fucntion is not calling itself. The destination for mul is always edx:eax, so the destination operand is not specified. The operation is edx:eax = eax x (source operand), where edx receives the upper 32 bits of the product, and eax receives the lower 32 bits of the product. There are other instructions where the register used is fixed, such as div, or the scan instructions such as scasb.
|
| Nov25-12, 08:27 PM | #3 |
|
|
Sorry about the missing code! After the multiply stuff it calls the function again but before it calls the function it pushes ebx again. Why does it do that? |
| Nov25-12, 08:42 PM | #4 |
|
Recognitions:
|
x86 Assembly Calling Another FunctionI'm going to assume that you were supposed to have already been given an example of how to do recursive factorial in C, and the point of this exercise is to implement the same function in assembly. Here is an example written in C: Code:
unsigned int factorial(unsigned int n)
{
if(n == 0)
return(1);
else
return n * factorial(n-1);
}
int main()
{
unsigned int result;
result = factorial(12);
/* ... */
return(0);
}
|
| Nov26-12, 01:49 AM | #5 |
|
|
I was wondering what is the difference between imul and mul? |
| Nov26-12, 05:07 AM | #6 |
|
Recognitions:
|
|
| Nov27-12, 12:30 AM | #7 |
|
|
|
| New Reply |
| Thread Tools | |
Similar Threads for: x86 Assembly Calling Another Function
|
||||
| Thread | Forum | Replies | ||
| Calling function im matlab? | Engineering, Comp Sci, & Technology Homework | 4 | ||
| C++ Function Calling Help | Engineering, Comp Sci, & Technology Homework | 4 | ||
| Beginner Function Calling Question | Programming & Comp Sci | 2 | ||
| C++ Function Calling | Programming & Comp Sci | 7 | ||
| Problems With Calling A Function | Engineering, Comp Sci, & Technology Homework | 2 | ||