Yes, it is okay to mix C and assembly, just be sure to know what you are doing...Hello,
I'm a micro-newbie. I have few questions please!
Is it preferable to write C instead of Assembly for such a newbie or pure Assembly/C?
Is it Ok to mix C and Assembly in 1 source code?
Thank you!
C on purpose is designed to give 95% the freedom of assembler once you properly understand pointer arithmetic. It however isolates such arithmetic from the hardware implementation (that is, various addressing modes).C is obtuse enough all by itself, though it so useful that can be overlooked.
It makes no difference. The C compiler will emit assembler in the end anyway. Each time you use assembler, you tie that source to a specific MCU (except trivial stuff that you could code in C easily).Hello,
I'm a micro-newbie. I have few questions please!
Is it preferable to write C instead of Assembly for such a newbie or pure Assembly/C?
Is it Ok to mix C and Assembly in 1 source code?
Thank you!
While you may have needed that once as a work around for some well known errors in one version of one compiler, generally (and even with the C8 compiler under version 1.10) you no longer need such dramatic work-arounds and can write statements such as:If you copy using a pointer and an index plus postincrement, to a structure with an index as well, you need quite a number of assembler instructions, not to speak of register reloading, and what is worse, register backup.
char Source[] = "Hello World";
char Dest[12];
...
while (*Dest++ = *Source++);
How about a timing requirement? no reason..... ever!? Well, you've officially deemed a RISC processor pointless...There is absolutely no compelling reason to ever learn assembly, no less learn it before any other programming language.
If I have a timing requirement (and I frequently do) I use a hardware timer, and an interrupt handler, all in C.How about a timing requirement? no reason..... ever!? Well, you've officially deemed a RISC processor pointless...
And you lose the advantage of knowing exactly how long each instruction takes. What if you have 20 instruction cycles to process an interrupt in your ISR? Do you simply hope your compiler will give it to you?If I have a timing requirement (and I frequently do) I use a hardware timer, and an interrupt handler, all in C.
As we discussed in a previous threadCounting up instruction execution times isn't so much done professionally these days I think.
Solutions for that could for instance to buffer the waveform in RAM, and then clock it out. Or to use a small CPLD.
I looked at the assembler source for USB stack, and I would not want to program things like that. I would not even want to run such a code.
I agree to that actually, yes for the ISR, sometimes assembler is used.As we discussed in a previous thread, yes, a FPGA would probably used in a professional setting, however, even if you are using an ARM processor and your ISR has to be as fast as possible, you will be expected to optimize your code in assembly.
Didn't think it would happen!I agree to that actually, yes for the ISR, sometimes assembler is used.
If you squeese a device for the max. possible in terms of optimizing instructions to use the least of clock cycles, ask yourself if you are really on the right track.Didn't think it would happen!![]()
Well, that didn't last longIf you squeese a device for the max. possible in terms of optimizing instructions to use the least of clock cycles, ask yourself if you are really on the right track.
I mean I'd rather discourage people from establishing larger assembly language constructs. http://www.dcee.net/Files/Programm/Sound/Well, that didn't last long
If your system is already in place and you are issuing a new firmware upgrade that has to support a new feature, this very well may become an issue...
It really depends at which stage in development you discover the timing requirements...
I agree wholeheartedly, don't use assembly unless you really are going to benefit from it.I mean I'd rather discourage people from establishing larger assembly language constructs. http://www.dcee.net/Files/Programm/Sound/
Most of the programs I write don't really need optimization. Also C code can be optimized. I mean download some of the zip's from that site, and examine it.I agree wholeheartedly, don't use assembly unless you really are going to benefit from it.
Use C when it doesn't matter if your switch statement is 10 clock cycles vs 15 clock cycles...
Use assembly if you're masochistic and don't want help from anyone else...