fahothew
asked on
how can translate from assembly to C
I need to translate the following into C :
secondly what is the best way to learn what each line means ?
thank you
0x080483d4 <foo+0>: push %ebp
0x080483d5 <foo+1>: mov %esp,%ebp
0x080483d7 <foo+3>: sub $0x4,%esp
0x080483da <foo+6>: cmpl $0x0,0x8(%ebp)
0x080483de <foo+10>: jg 0x80483e9 <foo+21>
0x080483e0 <foo+12>: movl $0x1,-0x4(%ebp)
0x080483e7 <foo+19>: jmp 0x80483fd <foo+41>
0x080483e9 <foo+21>: mov 0x8(%ebp),%eax
0x080483ec <foo+24>: dec %eax
0x080483ed <foo+25>: push %eax
0x080483ee <foo+26>: call 0x80483d4 <foo>
0x080483f3 <foo+31>: add $0x4,%esp
0x080483f6 <foo+34>: imul 0x8(%ebp),%eax
0x080483fa <foo+38>: mov %eax,-0x4(%ebp)
0x080483fd <foo+41>: mov -0x4(%ebp),%eax
0x08048400 <foo+44>: leave
0x08048401 <foo+45>: re
secondly what is the best way to learn what each line means ?
thank you
0x080483d4 <foo+0>: push %ebp
0x080483d5 <foo+1>: mov %esp,%ebp
0x080483d7 <foo+3>: sub $0x4,%esp
0x080483da <foo+6>: cmpl $0x0,0x8(%ebp)
0x080483de <foo+10>: jg 0x80483e9 <foo+21>
0x080483e0 <foo+12>: movl $0x1,-0x4(%ebp)
0x080483e7 <foo+19>: jmp 0x80483fd <foo+41>
0x080483e9 <foo+21>: mov 0x8(%ebp),%eax
0x080483ec <foo+24>: dec %eax
0x080483ed <foo+25>: push %eax
0x080483ee <foo+26>: call 0x80483d4 <foo>
0x080483f3 <foo+31>: add $0x4,%esp
0x080483f6 <foo+34>: imul 0x8(%ebp),%eax
0x080483fa <foo+38>: mov %eax,-0x4(%ebp)
0x080483fd <foo+41>: mov -0x4(%ebp),%eax
0x08048400 <foo+44>: leave
0x08048401 <foo+45>: re
I assume this is an academic assignment ?
Where is it that you are stuck understanding this ? Do you understand what each of the lines does on its own ? Do you know x86 call conventions ? That's pretty much all the information you need to understand what this code does.
As a hint : this function performs a certain simple mathematical operation on a number.
Where is it that you are stuck understanding this ? Do you understand what each of the lines does on its own ? Do you know x86 call conventions ? That's pretty much all the information you need to understand what this code does.
As a hint : this function performs a certain simple mathematical operation on a number.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> I need to translate the following into C :
it's clear to me what this code does, but I fear I can't tell you more than Infinity08 already said unless you confirm this is NOT an academic assignment.
>> secondly what is the best way to learn what each line means ?
this is a good starting point: http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
this is another good resource: http://www.amazon.com/Professional-Assembly-Language-Programmer/dp/0764579010
it assumes you are working on Linux; anyway most concepts related to assembly language are shared among all OS's
it's clear to me what this code does, but I fear I can't tell you more than Infinity08 already said unless you confirm this is NOT an academic assignment.
>> secondly what is the best way to learn what each line means ?
this is a good starting point: http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
this is another good resource: http://www.amazon.com/Professional-Assembly-Language-Programmer/dp/0764579010
it assumes you are working on Linux; anyway most concepts related to assembly language are shared among all OS's
ASKER
hi guys
well it is not an assignment it is only an academic question I've seen it in my final exam and i'm worry about it . Is there any rules for if it is assignment?
i'll share with you what i know so far for example the fallowing cose is disassemble of main function which declare 3 int , add two 1st to the 2nd and store it in the 3rd and return the sum
#include<stdio.h>
main()
{
int x,y,sum;
sum=x+y;
return sum;
}
0x08048244 <+0>: push %ebp
0x08048245 <+1>: mov %esp,%ebp
0x08048247 <+3>: sub $0xc,%esp
0x0804824a <+6>: mov -0x8(%ebp),%eax
0x0804824d <+9>: add -0x4(%ebp),%eax
0x08048250 <+12>: mov %eax,-0xc(%ebp)
0x08048253 <+15>: mov -0xc(%ebp),%eax
0x08048256 <+18>: leave
0x08048257 <+19>: ret
.......................... .......... .......... .
In my question i am stuck in the 4,5,7,9,13 lines
what coml jg jmp dec imul do ?
thank you again
well it is not an assignment it is only an academic question I've seen it in my final exam and i'm worry about it . Is there any rules for if it is assignment?
i'll share with you what i know so far for example the fallowing cose is disassemble of main function which declare 3 int , add two 1st to the 2nd and store it in the 3rd and return the sum
#include<stdio.h>
main()
{
int x,y,sum;
sum=x+y;
return sum;
}
0x08048244 <+0>: push %ebp
0x08048245 <+1>: mov %esp,%ebp
0x08048247 <+3>: sub $0xc,%esp
0x0804824a <+6>: mov -0x8(%ebp),%eax
0x0804824d <+9>: add -0x4(%ebp),%eax
0x08048250 <+12>: mov %eax,-0xc(%ebp)
0x08048253 <+15>: mov -0xc(%ebp),%eax
0x08048256 <+18>: leave
0x08048257 <+19>: ret
..........................
In my question i am stuck in the 4,5,7,9,13 lines
what coml jg jmp dec imul do ?
thank you again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmccurdy, Infinity08 and lomo74
thank you all guys your answer was really helpful
and it was my first question here on e-e
thank you all guys your answer was really helpful
and it was my first question here on e-e
Glad to have been of assistance :) And welcome to EE !
:-)
BTW did you finally understand what's the overall meaning of the code?
BTW did you finally understand what's the overall meaning of the code?
ASKER
well i need to rebuild it on c and disassemble it again , to c if i got a similar code I'll try it and tell what i found .
push will push something onto the stack.
move moves information from one memory location to another.
sub does subtraction
Telling you this is unlikely to really help you (so I'll stop).
Do you know what that code is trying to do? (What is the purpose of the code?)