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

C file that also has assembly code

hi,
I'm writting code (8051) that has both C and assambly in the same file.
for example:
void main()
{
long temp;
#pragma asm
mov a, #0; //assambly
#pragma endasm
temp = a*1000; //C
}

problems:
1. a (acc) is not recognizable in the
C part.what is the BEST thing to do?
2. if I'll continue this proram and add
another asm part will the last value
of a,for example zero, and other
reg/ptr will be saved?

Parents
  • 1. a (acc) is not recognizable in the C part.what is the BEST thing to do?

    Well, your C code does not "know" about the registers of the 8051 unless you TELL it.

    The accumulator is an SFR and C51 provides a way to DECLARE it.

    sfr ACC  = 0xE0;
    You may want to use the REG51.H include file to get all of the SFRs declared in your C programs.

    Then, in your program, you can do the following:

    void main()
    {
    long temp;
    
    #pragma asm 
    mov a, #0; //assambly
    #pragma endasm
    
    temp = ACC*1000; //C
    }
    Jon

Reply
  • 1. a (acc) is not recognizable in the C part.what is the BEST thing to do?

    Well, your C code does not "know" about the registers of the 8051 unless you TELL it.

    The accumulator is an SFR and C51 provides a way to DECLARE it.

    sfr ACC  = 0xE0;
    You may want to use the REG51.H include file to get all of the SFRs declared in your C programs.

    Then, in your program, you can do the following:

    void main()
    {
    long temp;
    
    #pragma asm 
    mov a, #0; //assambly
    #pragma endasm
    
    temp = ACC*1000; //C
    }
    Jon

Children
No data