We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I'm an mixing assembly with C code using Keil uV 4.6 When I have optimization Level 3 (-O3) turned on, the compiler skips alot of assembly function memory reads & writes. I need every line to be executed for this particular function.
__asm { MOV r1,#0x0041000 MOV r2,#0x0040000 ... }
I have tried intrinsic commands like __nop(), __force_store(), __schedule_barrier, etc, and have tried to make variables volatile. I know i must be missing something... Any suggestions
Use an assembler file. Then you own the code, and it will not go through the optimizer.
You can lower optimization level just for this one function:
www.keil.com/.../armccref_bcfjfgaa.htm
This might make your code work, but you still have the fundamental problem: your code is so fragile that simply tuning optimization level breaks it. As Per noted, the rock-solid approach is to have your assembly code in a separate file to be processed by the assembler rather than the compiler.
You can use "embedded assembly" instead of "inline assembly". Embedded asm doesn't have the same easy access to variables that inline asm has and it can't be used in the middle of a function -- it's basically a way of writing a whole function in asm without using a separate .s file and you get access to preprocessing and C constant expressions [via __cpp()].
Thanks for the great suggestions. #pragma O0 (letter O, zero) did fix it.
I would like to learn how to do an separate asm function call. I have been doing a little searching and haven't found any good examples how to call a function in a separate asm file from C. I've looked in the dissassembly and its pretty easy to pass the variable back through R0. I just don't know what the file header or other steps to take to make it work.
Thanks, Ben
Using -O0 may work "by accident" with your current code and current compiler, but it's not guaranteed to leave inline asm alone.
There are examples of mixing C and asm in the documentation: infocenter.arm.com/.../Babjhjbd.html