Re: GNUH8 mixed C and assembly




Peter Harrison wrote:
> 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

Soft delays are never fixed if they can be interupted, if you need a
fixed delay use a timer. There are different ways of including assembly
into your programs. Inline lines or blocks of assy instructions, C
functions who's code is written in assembler or pure assy routines
called directly. You need to look at the compiler docs for the syntax.
You can usually get to a C value from assember by putting an underbar
in front of the variable name but the H8 instructions mostly work only
with registers so this method is very limited. The other way is to use
the frame pointer to acces the stack directly but this requires you to
fully understand how your compiler works. The H8 also has complex assy
intructions best avoided if humanly possible.

.



Relevant Pages

  • Re: GNUH8 mixed C and assembly
    ... >What I seem unable to find out is how to write functions in assembler ... the exact need just now is a soft time delay. ... it is not uncommon for the optimization ... >understand that that is exactly why soft delays are dodgy. ...
    (comp.arch.embedded)
  • Re: GNUH8 mixed C and assembly
    ... 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. ... the exact need just now is a soft time delay. ... it is not uncommon for the optimization to completely remove apparently inactive code fragments. ...
    (comp.arch.embedded)
  • GNUH8 mixed C and assembly
    ... 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. ... the exact need just now is a soft time delay. ... it is not uncommon for the optimization to completely remove apparently inactive code fragments. ...
    (comp.arch.embedded)
  • The Case Against RosAsm (#7) (LONG)
    ... "Branch Displacement Optimization" is one of these ... The first assembler I recall that provided ... when a wanted short jump was longer than required, ...
    (alt.lang.asm)
  • Re: HLA v1.93 is now available
    ... Optimization is Strategy Optimization. ... You're claiming that an assembly language programmer using HLA ... Only in *your* assembler. ... FASM does branch displacement optimization. ...
    (alt.lang.asm)