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

Use MACRO C "#define value" in MACRO ASM

I use KeilC uVision4 for 89C51 MCU.
I use "Inline ASM Code", like this :

    void main() {
        #pragma ASM
            MOV R7, #(80000/40000)
        #pragma ENDASM
    }


-> When COMPILE, ASM result file give a wrong value to R7

        MOV R7, #0x00


But when i change like this :

    void main() {
        #pragma ASM
            MOV R7, #(60000/30000)
        #pragma ENDASM
    }


-> The COMPILER give correct value to R7

        MOV R7, #0x02


=> Seem, there must be a restriction when the ASM Compiler calculate (80000/40000) ?
=> And is there any way to pass this restriction. Please help me !
Regards !

Parents
  • But i don't want to use MCU to calculate vR3, vR2, vR1, let the Compiler do that, then just add the result of vR3, vR2, vR1 to the Delay() Routines.

    void Delay() {
        #pragma ASM
        MOV R1, #vR1 // vR1 calculate from Compiler
        MOV R2, #vR2 // vR2 calculate from Compiler
        MOV R3, #vR3 // vR3 calculate from Compiler
        DJNZ R1, $
        DJNZ R2, $-2
        DJNZ R3, $-4
        #pragma ENDASM
    }
    

    I mean that, in the main routine, i call Delay MACRO :

    void main() {
       DelayMCs(3000); // 3000 are numeric const, not variable
    }
    


    then the compiler scan and compile this MACRO to something like :

    #define Interval 3000
    #define t3 Interval/2
    #define vR3 ((t3+C2-2)/(C2+1))
    #define t2 (t3+C2-(C2+1)*vR3)
    #define vR2 ((t2+C1-1)/(C1+1))
    #define t1  (t2+C1-(C2+1)*vR2)
    #define vR1 ((t1+C0-0)/(C0+1))
    Delay();
    


    So vR1, vR2, vR3 is calculated from Compiler
    Just "Delay();" is compile to code to download to MCU

Reply
  • But i don't want to use MCU to calculate vR3, vR2, vR1, let the Compiler do that, then just add the result of vR3, vR2, vR1 to the Delay() Routines.

    void Delay() {
        #pragma ASM
        MOV R1, #vR1 // vR1 calculate from Compiler
        MOV R2, #vR2 // vR2 calculate from Compiler
        MOV R3, #vR3 // vR3 calculate from Compiler
        DJNZ R1, $
        DJNZ R2, $-2
        DJNZ R3, $-4
        #pragma ENDASM
    }
    

    I mean that, in the main routine, i call Delay MACRO :

    void main() {
       DelayMCs(3000); // 3000 are numeric const, not variable
    }
    


    then the compiler scan and compile this MACRO to something like :

    #define Interval 3000
    #define t3 Interval/2
    #define vR3 ((t3+C2-2)/(C2+1))
    #define t2 (t3+C2-(C2+1)*vR3)
    #define vR2 ((t2+C1-1)/(C1+1))
    #define t1  (t2+C1-(C2+1)*vR2)
    #define vR1 ((t1+C0-0)/(C0+1))
    Delay();
    


    So vR1, vR2, vR3 is calculated from Compiler
    Just "Delay();" is compile to code to download to MCU

Children