Hello,
I'm looking for a way of getting an assembly version of my programs. For example, I have the below (small) program called average.c:
Code:#include <stdio.h> float average(float x, float y); int main() { float a, b, c; a = 1; b = 3; c = average(a, b); printf("The average of %f and %f is %f.\n", a, b, c); } float average(float x, float y) { float z; z = (x + y) / 2; /* The average */ return z; }
I want to convert this to an assembly version, something like the following:
Code:0x08048390 <main+32>: sub $0x8,%esp 0x08048393 <main+35>: pushl 0xfffffff8(%ebp) 0x08048396 <main+38>: pushl 0xfffffffc(%ebp)
At the moment, I'm using the command 'gcc -S average.c', but it is only giving me the following type of assembly:
Code:main: pushl %ebp movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax
Does anyone know of a way to convert my C file to an assembly file that contains all the memory addresses, etc., as per the second piece of code above?
Thanks,
K
Assembly usually uses relocatable code so won't hard code addresses. It deals with symbolic addresses rather than actual addresses. You won't get addresses until the loader has got the program running.
Thanks for the reply!
When I run the program through GDB, I can type in, say, "main+52" and it comes up with some debugging information including the memory address of that piece of code.
Is there a way of doing something similar, but to all of the code at once? I don't want to have to type "main+1", "main+2", etc. all the way through the program as it'd just take forever...
Thanks again,
K
Sorry I don't know, I don't use GDB. I find unit testing to be far quicker and more effective than traditional debuggers.
I'll keep looking then. There must be a way of showing all the memory locations of pieces of code during run-time. Thanks for your replies anyway!
code might be like this--
for main function
for average functionCode:pushl %ebp movl %esp, %ebp subl $40, %esp movl $0x3f800000, %eax movl %eax, -4(%ebp) movl $0x40400000, %eax movl %eax, -8(%ebp) movl -8(%ebp), %eax movl %eax, 4(%esp) movl -4(%ebp), %eax movl %eax, (%esp) call _average fstps -12(%ebp) flds -12(%ebp) fstpl 20(%esp) flds -8(%ebp) fstpl 12(%esp) flds -4(%ebp) fstpl 4(%esp) movl $LC2, (%esp) call _printf leave ret
Code:LC1: .long 1073741824 pushl %ebp movl %esp, %ebp subl $8, %esp flds 8(%ebp) fadds 12(%ebp) flds LC1 fdivrp %st, %st(1) fstps -4(%ebp) movl -4(%ebp), %eax movl %eax, -8(%ebp) flds -8(%ebp) leave ret
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks