This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

locating arguments

Hello,


I would like to know how the keil compiler locate the arguments of a function.

1) it pass it via the stack?
2) it declares a places in the memory space, and in this case how he choose the memory space that it will use?


Thank You
Kaoru

  • Read the Manual - particularly the section about interfacing to assembler, and the description of the Memory Model.
    It's all there.

  • I have red the manual. I am in the large model, so i have to have all my arguments in the external memory. But there is something that i do not understand. This is correct for lots of function that i declared.
    But i have noticed that if we used the variable immediately (see the declaration below), keil will put the local variable in the data segment and not in the xdata.

    void function (unsigned char output_char)
    {
    SMB0DAT = output_char; /**** + other code ****/
    }

    Why it does not put the variable output_char in the LARGE model?

  • Is it just using Registers?

  • no, it places the variable in the data segment.

  • Can you show us the assembler output in the listing file?

    Jon

  • no you are rigth, he pass it from the register, below is the assembly

    ; FUNCTION _i2c_start_and_write (BEGIN)
    ; SOURCE LINE # 169
    ;---- Variable 'output_char' assigned to Register 'R7' ----
    ; SOURCE LINE # 170
    ; SOURCE LINE # 172
    0000 8FC2 MOV SMB0DAT,R7
    ; SOURCE LINE # 174
    0002 43C904 ORL T4CON,#04H
    0005 900000 E MOV DPTR,#counts+01H
    0008 E0 MOVX A,@DPTR


    Is there a mean to put it to the xdata?

    Why he put it in the register?

    Thank you
    Kaoru

  • It's called "Optimisation"

    Why don't you want this to happem?

  • I understand but i want to be sure that from a compilation to another, we will have exactly the same type of passing parameter.
    that he will not put it to the xdata because he need R7 (the register that is used rigth now) or that he will change the register.

    Do you have an idea to solve my problem?

  • The NOREGPARMS compiler directive disables parameter passing in registers.

    However, it doesn't disable the use of registers.

    Not using registers would be silly.

    Jon

  • "i want to be sure that from a compilation to another, we will have exactly the same type of passing parameter."

    Of course it will!
    The compiler has to stick to its own calling convention (that's why it's called a "convention"), otherwise it would never know how to handle a given function call!

    The calling convention is described in the Manual

  • I have 4 function of the type

    void funct(unsigned char)

    three of them are not optimized and the compiler put the parameters in the external memory. And only one of them is optimized by passing parameter in the register.
    For the three first functions, at the compilation, it will change the place of the parameter.
    Am i correct?
    Is there a mean to locate the parameter somewhere in the xdata?

    As those four functions are a part of a same level. i want them to be similar in the way of passing parameters. Like this i will have the same technology use for a same level.

    Do you think it is possible to do that by passing parameters in those functions?

    thank you
    Kaoru

  • Are some of them "leaf" functions, and some not?

  • Use NOREGPARMS and the compiler puts ALL ARGUMENTS IN MEMORY and NONE IN REGISTERS.

    Jon

  • I am sorry I don't understand what is "leaf"...
    The only difference between the function is the moment that i use the parameter. In the function that is compiled by passing parameter in the register, the variable is used just after the declarations. But for the other the variable is used in the middle of the function.

    the NOREGPARAMS is a good idea but as i want that the compilation is always the same, i have to locate those arguments. Can you tell me if it is possible? I tried to do it without success.

    Thank you
    Kaoru

  • i have to locate those arguments. Can you tell me if it is possible?

    If I understand you, you want to locate the arguments to several functions to the same address. For example:

    int func_a (int arg_a, int arg_b, int arg_c);
    int func_b (int arg_a, int arg_b, int arg_c);
    int func_c (int arg_a, int arg_b, int arg_c);
    

    func_a, func_b, and func_c should all have their arguments stored at the same address x.

    If that's the case, there is no way to automatically do that with the compiler.

    You can, however, do it manually with little or no overhead. Simply declare global variables that represent the function arguments. For example:

    int arg_a, arg_b, arg_c;
    
    int func_a (void);
    int func_b (void);
    int func_c (void);
    

    Then, you can "load" the arguments externally and you can access the arguments inside func_a, func_b, and func_c.

    Jon