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

how do I check #pragma directives

Hello ! I have a some quetions.
I my project i write some math(on Assembler) library for using in C and Assembler.
I have some function, in C this function can be defined:

extern signed long add32(signed long var1, signed long var2)


of course, this mean I have to respectively describe the function in assembler:

;---------- Object name ---------------
NAME ADD32                                                                      ; Obj. name

;---------- Segment declaration -------
?PR?_add32?ADD32 SEGMENT CODE                   ; Segment defenition
?DT?_add32?ADD32 SEGMENT DATA OVERLAYABLE       ; Segment defenition for long var's.

;---------- Public symbols ------------
PUBLIC ?_add32?BYTE                             ; Public symbol for long var's
PUBLIC _add32                                   ; Public function symbol

;---------- Vars defenition -----------
RSEG ?DT?_add32?ADD32
?_add32?BYTE:
ORG 04H
OP_BYTE:                 ds 04H                 ; Second operand memory allocate

;---------- Function code  ------------
RSEG ?PR?_add32?ADD32
_add32:
                clr C                           ; clr Carry

                mov  A,R7                       ; load ACC with LSB first op.
                ADD  A,OP_BYTE +03H             ; ADD LSB second op.
                mov  R7,A                       ; save result to R7

                mov  A,R6                       ; load ACC with next byte first op.
                ADDC A,OP_BYTE +02H             ; ADD next byte second op. + Carry
                mov  R6,A                       ; save result to R7

                mov  A,R5                       ; load ACC with next byte first op.
                ADDC A,OP_BYTE +01H             ; ADD next byte second op. + Carry
                mov  R5,A                       ; save result to R7

                mov  A,R4                       ; load ACC with MSB first op.
                ADDC A,OP_BYTE +00H             ; ADDC MSB second op. + Carry
                mov  R4,A                       ; save result to R6
end_add32:
                ret
;--------------------------------------
END

and

;---------- Segment declaration -------
...
?DT?_add32?ADD32 SEGMENT DATA OVERLAYABLE
...
;---------- Public symbols ------------
PUBLIC ?_add32?BYTE                             ; Public symbol for long var's
...


;---------- Vars defenition ----------- RSEG ?DT?_add32?ADD32 ?_add32?BYTE: ORG 04H OP_BYTE: ds 04H ; Second operand memory allocate


this segment must be declared for passing variable in function with type long.

When i define ,example:

#pragma REGPARMS


this function working normaly, first long var placed to R4& R5& R6& R7, second lond var placed direc to memory segment ?DT?_add32?ADD32 with offset four bytes.
BUT when I want to like don't use register and pass all parametrs in memory, if i define

#pragma NOREGPARMS


first long var placed to ?DT?_add32?ADD32 without offset , second lond var placed direc to memory segment ?DT?_add32?ADD32 with offset four bytes, and my function don't work.

Quetions:
Possible to determine at compile time which #pragma directives are set, and on this corect source code.

This function only example, of course no need use this function in C.

Sorry for my english.:)
With best regards Artem Gusev.
Thanks for all.

  • It's quite clearly impossible for an assembly source file to check for compiler #pragma you wrote somewhere in a completely unrelated C source file --- those don't even exist in the world as known to the assembly.

    The short answer is, therefore: forget about it.

    The longer answer is: mixing different settings of the REGPARMS option in a single project is quite a bad idea. You would get the drawbacks of both, and lose most of the benefits of each. If you really need to do it, you'll end up writing two copies of each of your assembly functions, one for REGPARMS, the other for NOREGPARMS mode, and then you'll have to switch between those in parallel to switching options for the C compiler.

  • Thanks for answer!.
    You say:

    mixing different settings of the REGPARMS option in a single project is quite a bad idea. You would get the drawbacks of both, and lose most of the benefits of each. If you really need to do it, you'll end up writing two copies of each of your assembly functions, one for REGPARMS, the other for NOREGPARMS mode, and then you'll have to switch between those in parallel to switching options for the C compiler
    


    Or couse i understand that, but i wrote library for using by other users and in diferent project.
    I wonder how the library, such as example math(built in keil). Function from this library functions can be called with diferent (REGPARMS or NOREGPARMS) settings, and work normaly.
    Maybe you know how this is done there ??
    In any case, thanks for the reply.

    Sorry for my english.:)
    With best regards Artem Gusev.

  • The name of functions, at the assembler level, is different between REGPARMS and NOREGPARMS mode. That's how you would distinguish them.

    But the issue really doesn't exist. You can decide on one mode, and wrap your prototypes in

    #pragma save
    #pragma noregparms
    /*...*/
    #pragma restore
    

    to tell the compiler which one you used.

  • When I define
    this indicates that this is for your use only.
    in that case there is a possibilty of the following
    in the C
    #define ....
    ..
    #if .... bit ...._is_defined

    in asm
    extern bit ....is_defined

    ..
    jb ....is_defined

    Erik

  • Thanks for help!.
    I think that discussion of this topic is enough, thanks again.

    With best regard Artem Gusev.