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

Probs using C params with inline assembly

Is there a method for using inline assembly AND the variables passed to it? I understand the requirement for using SRC, but it makes things a wee bit unmaintainable.

For example:

void test(char value)
{
    char dummy;
 
#pragma asm
        mov a,value
        mov dummy,a
#pragma endasm
}

Generates the following code:

?_test?BYTE:
      value?040:   DS   1
    ORG  1
      dummy?041:   DS   1


    RSEG  ?PR?_test?CREDMSGS
    USING   0
_test:
    MOV     value?040,R7
                     ; SOURCE LINE # 172
; {
                     ; SOURCE LINE # 173
;    char dummy;
;    
; #pragma asm
;     mov a,value
      mov a,value
;     mov dummy,a
      mov dummy,a
; #pragma endasm
; }
                     ; SOURCE LINE # 180
    RET     
; END OF _test

The unfortunate part about this is that should someone need to modify this source, what was value?040 could be something like value?140.

This is a small function to merely illustrate a problem I am having with a much larger function (with many more parameters). Is there a way out of this maintenance nightmare (other than moving a SINGLE function to an asm source file)? I would rather like to use the parameter and local variable without having to worry that future changes are going to muck up naming.

Cheers,

Lloyd

Parents
  • Hi Lloyd,

    Can you tell the compiler to push parameters on the stack and reserve space for locals on the stack for the duration of your asm function with a pragma? It looks like it is reserving space in ram. Maybe the compiler is set to make auto variables static. If the stack isn't too much of an issue you ought to be able to keep the code the same by referring to a local stack frame.

    Also, as long as you are only changing code between the #pragma ASM/ENDASM, shouldn't the compiler work out the symbol name changes?

    Doug Moore

Reply
  • Hi Lloyd,

    Can you tell the compiler to push parameters on the stack and reserve space for locals on the stack for the duration of your asm function with a pragma? It looks like it is reserving space in ram. Maybe the compiler is set to make auto variables static. If the stack isn't too much of an issue you ought to be able to keep the code the same by referring to a local stack frame.

    Also, as long as you are only changing code between the #pragma ASM/ENDASM, shouldn't the compiler work out the symbol name changes?

    Doug Moore

Children
  • Timing is of high importance (only reason I dropped into ASM in the first place), so no, using the stack is not an option. I need to refer to the params quickly.

    The compiler doesn't work out the name changes because (my guess at it), the designer opt'ed for a method that reduced the development of the compiler. For the compiler to work things out it has to understand 8051 assembly and THAT makes things more difficult on the compiler writer (otherwise it would just output an OBJ and I would be done!).

    Thanks for the input,

    Cheers,

    Lloyd