|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||
|
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.
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Free Assembly Tutorials | Jordan | General Programming | 39 | 10-05-2008 05:40 PM |
| Assembly Applications | skilletsteve | General Programming | 8 | 08-25-2006 07:32 PM |
| Companies That Hire Assembly Programmers | encoder | General Programming | 14 | 08-01-2006 05:28 PM |
| Assembly usage | DevilsCharm | General Programming | 2 | 07-13-2006 01:54 PM |
| Assembly tutorials | Kaabi | General Programming | 1 | 07-05-2006 12:18 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |