For efficiency,i have to use inline assembly in my code, but I failed to access local variables My code is something like this:
void func(void) { unsigned int i; i=0; #pragma asm MOV A,i #pragma endasm }
but i get a error : error A45: UNDEFINED SYMBOL (PASS-2)
So i there and way to solve this problem
For efficiency I would recommend that you consider adding an assembler file and write the full function in assembler. You write the assembler code, and let the compiler generate processor instructions based on your C code.
Definitely.
You can get the compiler to create the "skeleton" for you:
www.8052.com/.../149030
I always flinch when I see the statement "for efficiency,i have to use inline assembly".
The truth is that the C51 compiler will generate better code than most assembly programmers. Yes the code routines must be written more general than a tightly defined assembly code but I normally see most coders can't write tight assembly code better than the C51 compiler.
This seems to be the case because the OP says he MUST use in-line assembly. He appears not to know the best way is to let the compiler generate SRC code and then edit if necessary.
Bradford
"This seems to be the case because the OP says he MUST use in-line assembly. He appears not to know the best way is to let the compiler generate SRC code and then edit if necessary"
Indeed.
It takes a highly skilled & experienced assembler programmer to beat a modern optimising compiler. It does seem rather unlikely that such a programmer would be asking basic questions like this...
I know what you mean, but the truth is :
R1 = (bit)(*buffer1 & i);
will generate code like this
MOV A,0x08 ANL A,R5 MOV R7,A MOV A,R7 ADD A,#0xFF MOV R1(0xA0.1),C
I know KEIL always generate codes better than me most of time.but this ,i'm really confused about the redundant two instructions
MOV R7,A MOV A,R7
I want to elimate this two instruction, so that's why i need to use inline assembly.
"I want to elimate this two instruction, so that's why i need to use inline assembly."
The word "need" doesn't mean what you think it does in the above sentence. "need" would imply that "inline assembly" is the only possible solution.
that's what i mean...Or is there another way to remove those two instructions?
Yes!
As already suggested and illustrated, create an assembler function; in an assembler source file.
The real question here is: why does the OP need to remove those two instructions. If the OPs code is so, that it will not work with those 4? cycles spent, there is more problems than what is posted
will generate code like this Two remarks to that: 1) Not when I try that here it doesn't. 2) You've been told already that "like this" doesn't cut it. Either that is the actual code, or you're essentially blowing smoke.
the redundant two instructions And have you made absolutely, positively sure that those are actually redundant? Do you understand not just these six machine instructions, but also the entire surrounding code well enough that you can make sure that all of it would still work the same way without these instructions?
And have you made absolutely, positively sure that those are actually redundant?
Well it shouldn't take a programmer with much experience to see that 50% of the sequence is redundant, regardless of surrounding code.