This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C and Assembly

I want to know how to write assmebly code and c code in same program.... i mean i need to write some function in assembly and some in C code.. i should be able to call both of them from either codes.. how to do this.. help me out..

Parents
  • Just as a follow up on this subject.

    If you wanted to create a 'main' in assembler, the first thing you would have to do is look at the startup code. It doesn't call main, it calls an external function called ?C_START.

    I think you would find that ?C_START is a run-time library function that (in turn) calls the traditional C function main. Almost certainly, the purpose of this mechanism would be to ensure that the critical parts of the run-time library are pulled into the executable.

    So ... As a simple exercise, you can modify the startup code and replace/change the references to ?C_STARTUP to main and hey presto, you can call an assembler version of main.

Reply
  • Just as a follow up on this subject.

    If you wanted to create a 'main' in assembler, the first thing you would have to do is look at the startup code. It doesn't call main, it calls an external function called ?C_START.

    I think you would find that ?C_START is a run-time library function that (in turn) calls the traditional C function main. Almost certainly, the purpose of this mechanism would be to ensure that the critical parts of the run-time library are pulled into the executable.

    So ... As a simple exercise, you can modify the startup code and replace/change the references to ?C_STARTUP to main and hey presto, you can call an assembler version of main.

Children
  • I think you would find that ?C_START is a run-time library function that (in turn) calls the traditional C function main. Almost certainly, the purpose of this mechanism would be to ensure that the critical parts of the run-time library are pulled into the executable

    I 'know' (because there is no other place) that ?C_START (also) initializes all global values that are to be initialized to other than zero.

    Erik

  • Follow up to the follow up ...

    If you don't want to modify the startup code, then just be explicit and include the run-time library into the project (or, for the non-ide fraternity, the linker command line).

    Again, hey presto, main in assembler.