| ??? 04/25/02 14:05 Read: times |
#22147 - RE: Assembly on C programm |
Andy Neil wrote: ------------------------------- "with C language but I'd like to know if it is possible to include assembly code" most 'C' compilers provide some means to mix assembler into 'C' source - this is all non-standard, so you'll have to read the manual for your particular compiler. As for calling between 'C' and assembler - of course you can! You can do anything in assembler, so all you need to find out is the Calling Convention of your 'C' compiler - read the manual - and implement that. The Keil C51 manual has a section specifically dedicated to this. As Andy said each compiler is pretty much free to implement inline assembly as they see fit. You will need to read their manual to find the method that your compiler has implemented this feature (if they have). The most common approch is the form #pragma SRC // TOP OF FILE C code ... ... ... #pragma ASM ASMEMBLY CODE .. .. .. #pragma ENDASM This will convert the complete C source file into an Assembly source file that you will then have to translate using the assembler. This method is fairly easy to implement but has the negative side effect of removing the C source level debugging from this module. If you are using the Raisonance tools you have and alternative, which is the asm {}; keyword With this form you can simply do the following C CODE ... ... asm {0x00}; MORE C CODE ... ... ... The compiler then translates the file and inserts the assembly opcode directly into the file at the appropriate location. Note that you use the opcode NOT the mnemonic for this method. That is the major negative about this form. I get around that by using simple MACROS like: #define NOP 0x00 Then I do: asm {NOP}; This is much more useful and readable. If what you want to do is call an assembly function you will need to read the chapters in the manuals on interfacing to assembly for register allocation. I hope this helps in your inline assembly. Bryan Whitton |



