I am working with HEW4 and GNUH8 5.03 targeted at the H8/3664 and H8/3687 and I can write C programs with only moderate difficulty. I seem to have no problem writing code in .src files and calling it from C. What I seem unable to find out is how to write functions in assembler and then either access the arguments that are passed in, or how to return values to the calling function.
Also, how can I know what registers it is safe to use in my assembler functions?
At the moment, all I want to do is to give a function an integer and possibly return an integer. Am I going to have to learn the arcane ways of the inline assembly stuff? An example project would be good.
FWIW, the exact need just now is a soft time delay. These are short delays of a few tens of microseconds I appreciate these are less than ideal in many ways. I can write one in C - as appears in any number of example projects. However, I am nervous about how the optimizer might treat my code. In other systems, it is not uncommon for the optimization to completely remove apparently inactive code fragments. I am running with -Os normally and tests seem to show that GCC will not remove lines like this:
int temp = 1000; while(temp--);
under any optimization but that the generated code (and thus the delay) may change between no optimization and any level of optimization. I do understand that that is exactly why soft delays are dodgy. Thus I figure that, if I must have a soft delay, it should really be in assembler so that I know what code is generated. Would I be better staying in C? Can I ever guarantee that code will not be removed if I change the optimization level?
Pete Harrison