Thanks for the tips ... i'll have to see what i can do with them ... i have seen Tenenbaum's text before. I'll see if i can get hold of one. I really appreciate your taking the time to help. Thanks again for everything.
Arti
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes of course there is because Dev-C++ uses GCC! It is just an IDE not a compiler. The compiler itself is MinGW/GCC.
However, there is a catch, -S prevents genration of a .o file, which is the make target, so the build fails after 'compiling' the first module of a multi-file build, so you only get assembler for the first file.
I tried to compile this code : file name is : add.c
#include<stdio.h>
#include<conio.h>
int main()
{
int a = 10,b = 5, c = 0;
c=a+b;
return(0);
}
by giving the option: gcc -S add.c inside tools-compiler options -compiler - add the following commands when calling compiler ... the box in there
and got following error messages :
1 C:\Dev-Cpp\bin\add.c In file included from add.c
219 C:\Dev-Cpp\include\stdio.h redefinition of 'vsnprintf'
219 C:\Dev-Cpp\include\stdio.h redefinition of 'vsnprintf'
279 C:\Dev-Cpp\include\stdio.h redefinition of 'putchar'
279 C:\Dev-Cpp\include\stdio.h redefinition of 'putchar'
4 C:\Dev-Cpp\bin\add.c redefinition of global 'main'
4 C:\Dev-Cpp\bin\add.c 'main' previously defined here
and the compiler log showed the following :
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Dev-Cpp\bin\add.c" -o "C:\Dev-Cpp\bin\add.exe" gcc -S add.c -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from add.c:1:
C:/Dev-Cpp/include/stdio.h:219: error: redefinition of 'vsnprintf'
C:/Dev-Cpp/include/stdio.h:219: error: redefinition of 'vsnprintf'
C:/Dev-Cpp/include/stdio.h:279: error: redefinition of 'putchar'
C:/Dev-Cpp/include/stdio.h:279: error: redefinition of 'putchar'
C:\Dev-Cpp\bin\add.c:4: error: redefinition of global 'main'
add.c:4: error: 'main' previously defined here
gcc.exe: gcc: No such file or directory
Execution terminated
what did i do wrong? I mean i am trying to use the -S option for the first time and i just cant get the hang of it. I really am crying SOS .... please help out!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You only put the options you want to add in that box, not teh whole command line. Look at the gcc command line in the compile log to see what you have done; Dev-C++ invokes gcc for the projects source, and in that context "gcc" and "add.c" that you added make no sense at all.
Why did you not simply follow the instructions I posted? If you want to override the generated command line, that is not where to do it, and I also warned of the problems and inadequacy of using -S. If you choose to ignore my advice, it would be helpful to understand why it did not meet your needs.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am really sorry for bothering u so much and i did read the solution u send me ... i guess i didnt make my problem really clear .... i just dont know how to use the commandline arguments and in this case i dont know what i am supposed to give in that window ... i am just a beginner with this stuff and i really just need an assembly code for a single file at a time. So i thought the -S option would work .... but i never found any web page that tells me exactly how to go about using this option when compiling a file. I would be really thankful to you if you could tell me what i am supposed to type where and whether i need to make any other changes to any settings ... consider me a dummie ... i am sorry i am a real novice here. And didnt actually understand much about how to go about using the assembler option either. Maybe a bit of layman terms help would be good .... if u could spare me some time .... please help me if u can.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it will. But Dev-C++ controls invoking GCC so you only need the -S option. You tried to put in the whole command line. Where you put "gcc -S add.c" just put "-S". I thought that was clear from my earlier answer... I guess not.
>> but i never found any web page that tells me exactly
>> how to go about using this option
I would ask why you need the assembler output since that would determine the most appropriate method of getting it (if you subsequently want to assemble the code, then the -S output is better. If you merely want to read it to see how the compiler generates code the -Wa method is better. I'd rather not explain what you should do until I understand why you are doing it - that way you'll get the most appropriate solution, and I only have to do half the work!
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hey ... thanks a million ... I am not getting into wat a duffer I have been ... lets just say I was doing more than my share of dumb mistakes. I finally got the output I wanted using the -S option.
Since I have given u so much trouble, I guess I do owe u the answer to why i want the stuff done. Ok ... i am supposed to use this as a sample input file to generate some values for a Process Control Block. I havent still figured out how. I hadnt even a sample input till now. But thanks a million again. Its part of college project.
Arti
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You know you can always run the underlying compiler directly from the command line as perhaps you are used to. You will have to add c:\dev-cpp\bin to the PATH environment variable, and optionally other environment variable that control the tool-chain: http://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can write in-line assembler and get complete control of and access to registers, but it is awkward because the compiled C code will be using the same registers. The in-line assembler syntax allows the compiler to chose available registers rather than specifying specific ones. If you do specify specific registers you must create a 'clobber' list so that the compiler can save and restore the registers it needs before and after the assembler code.
If all you want to do is see how the compiled code uses registers, the only robust way of determining register content at a particular point in your code is to use a debugger. Dev-C++'s built in debugger can do this from the command with appropriate GDB commands, but the Insight debugger has a registers window. The debugger can also show assembly code and mixed source/assembly so it may be an easier way of doing what you originally wanted as well.
I would question your need to do any of this. To be honest I did not really understand your original explanation, or how it related to the original question.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
O.K ... i have got to design some parts of an API ... so i am asked to create a PCB for an API with as many general variables defined in it as possible like registers used in a given process, memory used, devices connected, process id, process state and so on. So i need an input file of any compiled program ... which was suggested to be used as input. This is to be an assembly file ... i think if i can get a link file and a dump file as well as spark assembler output i might get most of the necessary data. I got an additional suggestion that i use linux gcc and configure it to give spark output. But i am not familiar with linux environment. It would have been easier if there was some means of obtaining it using Dev. So i thought i wud ask. Dont ask me why the files are needed and whether this PCB is of a still active process or anything ... i still havent figured out things more than what i have written above, and am still just about getting the pieces together. So this is the summary of things i need to do as far as i understand them now. Any possible solutions of getting the necessary files?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Don't assume that we all know what your TLA means. I guess Process Control Block, but I actually have no idea what that is in this context, or in that context what "a PCB for an API" means, or why an assembler file might be required as "input".
Note that the compiler output is the assembler for an unlinked object file. It will include unresolved references. Perhaps a disassembly of the linked executable would be more useful? But since I have no idea what you are talking about I am probably totally wrong!
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well u r not totally wrong ... I am talking about Process Control Block, and sorry for not being clear and specific. A process control block is a data structure that has all details regarding an ongoing process. It has to do with development of an Operating System. My job is to first do the process creation part and I am also asked to start at the base level which is to create a PCB. A process control bBlock should contain the details of a Process such as which are the registers used by the process, what are its contents, which all memory locations are required that is details about memory management, device management ... that is ports used, process ID which is unique for each process, State of a process that is whetherit is "READY" to be processed,"WAIT" i.e waiting for I\O devices etc ... Anyway the process I have to first take as sample is any C program. So using its link files, dump files, ASM files, I can create a sample PCB( the spark ouput was said to have more details required for filling in the Process control Block). Anyway I need to get memory used, locations and stuffs for our linked program, and i guess disassembly might be the required option. But i dont know how to do that here either. If u need to know any more details do please ask. But if u do know how to help me with what i have described of my problem, please do help. And you have good perception anyway, but do tell me really like u would explain to someone who's never even seen the thing before ... coz i have more text book knowledge of softwares than practical. So i just have heard about these things.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is the target? x86 does not have that many registers, it is a fairly safe bet a process will use all of them!
I am confused as to how what you are doing is going to help - but don't let that stop you, I am not an OS expert, and do not have complete details of your project's requirements. All of by OS expertise if I have any is in the area of Real-time Operating Systems for embedded systems, and these are usually somewhat different to what you are are probably attempting.
Personally I would start by studying existing OS examples, especially perhaps Minix, an OS designed for teaching Operating Systems theory, and controversially the starting point for Linus Torvalds' Linux implementation.
Minix is the subject of the seminal work on the subject; "Operating Systems Design and Implementation" by Andrew S. Tanenbaum
If you are interested in RTOS design, then you should read "MicroC/OS-II: The Real-time Kernel" by Jean Labrosse. In a typical RTOS you would have a Task Control Block (TCB) since an embedded system is typically a collection of lightweight closely coupled threads rather than separate and independent processes.
I need to get the assembler program as output for a C program , is there any option like S-option available in GCC here to do the same?
Thanks for the tips ... i'll have to see what i can do with them ... i have seen Tenenbaum's text before. I'll see if i can get hold of one. I really appreciate your taking the time to help. Thanks again for everything.
Yes of course there is because Dev-C++ uses GCC! It is just an IDE not a compiler. The compiler itself is MinGW/GCC.
However, there is a catch, -S prevents genration of a .o file, which is the make target, so the build fails after 'compiling' the first module of a multi-file build, so you only get assembler for the first file.
Here is a solution: http://sourceforge.net/forum/forum.php?thread_id=1379841&forum_id=48211
Clifford
I tried to compile this code : file name is : add.c
#include<stdio.h>
#include<conio.h>
int main()
{
int a = 10,b = 5, c = 0;
c=a+b;
return(0);
}
by giving the option: gcc -S add.c inside tools-compiler options -compiler - add the following commands when calling compiler ... the box in there
and got following error messages :
1 C:\Dev-Cpp\bin\add.c In file included from add.c
219 C:\Dev-Cpp\include\stdio.h redefinition of 'vsnprintf'
219 C:\Dev-Cpp\include\stdio.h redefinition of 'vsnprintf'
279 C:\Dev-Cpp\include\stdio.h redefinition of 'putchar'
279 C:\Dev-Cpp\include\stdio.h redefinition of 'putchar'
4 C:\Dev-Cpp\bin\add.c redefinition of global 'main'
4 C:\Dev-Cpp\bin\add.c 'main' previously defined here
and the compiler log showed the following :
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Dev-Cpp\bin\add.c" -o "C:\Dev-Cpp\bin\add.exe" gcc -S add.c -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from add.c:1:
C:/Dev-Cpp/include/stdio.h:219: error: redefinition of 'vsnprintf'
C:/Dev-Cpp/include/stdio.h:219: error: redefinition of 'vsnprintf'
C:/Dev-Cpp/include/stdio.h:279: error: redefinition of 'putchar'
C:/Dev-Cpp/include/stdio.h:279: error: redefinition of 'putchar'
C:\Dev-Cpp\bin\add.c:4: error: redefinition of global 'main'
add.c:4: error: 'main' previously defined here
gcc.exe: gcc: No such file or directory
Execution terminated
what did i do wrong? I mean i am trying to use the -S option for the first time and i just cant get the hang of it. I really am crying SOS .... please help out!
You only put the options you want to add in that box, not teh whole command line. Look at the gcc command line in the compile log to see what you have done; Dev-C++ invokes gcc for the projects source, and in that context "gcc" and "add.c" that you added make no sense at all.
Why did you not simply follow the instructions I posted? If you want to override the generated command line, that is not where to do it, and I also warned of the problems and inadequacy of using -S. If you choose to ignore my advice, it would be helpful to understand why it did not meet your needs.
Clifford
I am really sorry for bothering u so much and i did read the solution u send me ... i guess i didnt make my problem really clear .... i just dont know how to use the commandline arguments and in this case i dont know what i am supposed to give in that window ... i am just a beginner with this stuff and i really just need an assembly code for a single file at a time. So i thought the -S option would work .... but i never found any web page that tells me exactly how to go about using this option when compiling a file. I would be really thankful to you if you could tell me what i am supposed to type where and whether i need to make any other changes to any settings ... consider me a dummie ... i am sorry i am a real novice here. And didnt actually understand much about how to go about using the assembler option either. Maybe a bit of layman terms help would be good .... if u could spare me some time .... please help me if u can.
>> So i thought the -S option would work
Yes, it will. But Dev-C++ controls invoking GCC so you only need the -S option. You tried to put in the whole command line. Where you put "gcc -S add.c" just put "-S". I thought that was clear from my earlier answer... I guess not.
>> but i never found any web page that tells me exactly
>> how to go about using this option
Uh.... the GCC manual perhaps? http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Overall-Options.html#index-S-72. As I suggested my way is 'better', since it allows mixed assembler and source code ad allows teh code to actually build.
I would ask why you need the assembler output since that would determine the most appropriate method of getting it (if you subsequently want to assemble the code, then the -S output is better. If you merely want to read it to see how the compiler generates code the -Wa method is better. I'd rather not explain what you should do until I understand why you are doing it - that way you'll get the most appropriate solution, and I only have to do half the work!
Clifford
hey ... thanks a million ... I am not getting into wat a duffer I have been ... lets just say I was doing more than my share of dumb mistakes. I finally got the output I wanted using the -S option.
Since I have given u so much trouble, I guess I do owe u the answer to why i want the stuff done. Ok ... i am supposed to use this as a sample input file to generate some values for a Process Control Block. I havent still figured out how. I hadnt even a sample input till now. But thanks a million again. Its part of college project.
No trouble, good luck.
You know you can always run the underlying compiler directly from the command line as perhaps you are used to. You will have to add c:\dev-cpp\bin to the PATH environment variable, and optionally other environment variable that control the tool-chain: http://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
Clifford
Thanks again ... u helped me a lot.
Can u do another favour please ... I need to know if there is any means of accessing the contents of registers through a program. could u help me out?
It depends on what kind of access you want.
You can write in-line assembler and get complete control of and access to registers, but it is awkward because the compiled C code will be using the same registers. The in-line assembler syntax allows the compiler to chose available registers rather than specifying specific ones. If you do specify specific registers you must create a 'clobber' list so that the compiler can save and restore the registers it needs before and after the assembler code.
If all you want to do is see how the compiled code uses registers, the only robust way of determining register content at a particular point in your code is to use a debugger. Dev-C++'s built in debugger can do this from the command with appropriate GDB commands, but the Insight debugger has a registers window. The debugger can also show assembly code and mixed source/assembly so it may be an easier way of doing what you originally wanted as well.
I would question your need to do any of this. To be honest I did not really understand your original explanation, or how it related to the original question.
Clifford
O.K ... i have got to design some parts of an API ... so i am asked to create a PCB for an API with as many general variables defined in it as possible like registers used in a given process, memory used, devices connected, process id, process state and so on. So i need an input file of any compiled program ... which was suggested to be used as input. This is to be an assembly file ... i think if i can get a link file and a dump file as well as spark assembler output i might get most of the necessary data. I got an additional suggestion that i use linux gcc and configure it to give spark output. But i am not familiar with linux environment. It would have been easier if there was some means of obtaining it using Dev. So i thought i wud ask. Dont ask me why the files are needed and whether this PCB is of a still active process or anything ... i still havent figured out things more than what i have written above, and am still just about getting the pieces together. So this is the summary of things i need to do as far as i understand them now. Any possible solutions of getting the necessary files?
PCB?
Printed Circuit Board?
Polychlorinated biphenyl?
Brazilian Communist Party?
Pakistan Cricket Board?
Don't assume that we all know what your TLA means. I guess Process Control Block, but I actually have no idea what that is in this context, or in that context what "a PCB for an API" means, or why an assembler file might be required as "input".
Note that the compiler output is the assembler for an unlinked object file. It will include unresolved references. Perhaps a disassembly of the linked executable would be more useful? But since I have no idea what you are talking about I am probably totally wrong!
Clifford
Well u r not totally wrong ... I am talking about Process Control Block, and sorry for not being clear and specific. A process control block is a data structure that has all details regarding an ongoing process. It has to do with development of an Operating System. My job is to first do the process creation part and I am also asked to start at the base level which is to create a PCB. A process control bBlock should contain the details of a Process such as which are the registers used by the process, what are its contents, which all memory locations are required that is details about memory management, device management ... that is ports used, process ID which is unique for each process, State of a process that is whetherit is "READY" to be processed,"WAIT" i.e waiting for I\O devices etc ... Anyway the process I have to first take as sample is any C program. So using its link files, dump files, ASM files, I can create a sample PCB( the spark ouput was said to have more details required for filling in the Process control Block). Anyway I need to get memory used, locations and stuffs for our linked program, and i guess disassembly might be the required option. But i dont know how to do that here either. If u need to know any more details do please ask. But if u do know how to help me with what i have described of my problem, please do help. And you have good perception anyway, but do tell me really like u would explain to someone who's never even seen the thing before ... coz i have more text book knowledge of softwares than practical. So i just have heard about these things.
What is the target? x86 does not have that many registers, it is a fairly safe bet a process will use all of them!
I am confused as to how what you are doing is going to help - but don't let that stop you, I am not an OS expert, and do not have complete details of your project's requirements. All of by OS expertise if I have any is in the area of Real-time Operating Systems for embedded systems, and these are usually somewhat different to what you are are probably attempting.
Personally I would start by studying existing OS examples, especially perhaps Minix, an OS designed for teaching Operating Systems theory, and controversially the starting point for Linus Torvalds' Linux implementation.
Minix is the subject of the seminal work on the subject; "Operating Systems Design and Implementation" by Andrew S. Tanenbaum
http://en.wikipedia.org/wiki/Minix
If you are interested in RTOS design, then you should read "MicroC/OS-II: The Real-time Kernel" by Jean Labrosse. In a typical RTOS you would have a Task Control Block (TCB) since an embedded system is typically a collection of lightweight closely coupled threads rather than separate and independent processes.
http://en.wikipedia.org/wiki/MicroC/OS-II
Clifford