Hi!
For some serious speed optimisations I have to implement a function in Assembler within a C-Sourcecode. I am using Keil uVision 2 with an Infinion C515-CL Processor - and the c51/a51 environment. After reading documentation I got some ideas how to implement a function in ASM and execute it from the C-Source. The problem is: I don't get it compiled. :-)
What I did is the following:
---------------------------- Right-Click on the .c-file and enabled "Generate Assembler SRC File" and "Assemble SRC File" from the file-options-menu.
I implemented the function with the following code:
void myop (unsigned char idx, unsigned char pos1, unsigned char pos2, unsigned char shval) { #pragma asm EXTRN DATA (idx) EXTRN DATA (pos1) EXTRN DATA (pos2) EXTRN DATA (shval)
/* plus */ mov a, #x add a, #pos1 mov r1, a mov a, #x add a, #pos2 mov r0, a mov a, @r0 add a, @r1 mov r7, a
/* rotl */ mov r0, #shval mov a, r7 inc r0 // increase by one to have 0 as exit condition sjmp lab2 // unconditional jump lab1 rl a // rotate left by 1 :-) lab2: djnz r0,lab1 // decrease and jump if not zero mov r7,a
/* xor */ mov a, #x add a, #idx mov r0,a mov a, @r0 xrl a, r7
/* save back */ mov @r0, a #pragma endasm }
The variable x is global and defined by unsigned char idata x[16];
Build-Output:
-------------
Build target 'Target 1' compiling ecrypt.c... ECRYPT.C(104): warning C280: 'idx': unreferenced local variable ECRYPT.C(104): warning C280: 'pos1': unreferenced local variable ECRYPT.C(104): warning C280: 'pos2': unreferenced local variable ECRYPT.C(104): warning C280: 'shval': unreferenced local variable assembling ecrypt.src... linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: ?C_STARTUP MODULE: ecrypt.obj (ECRYPT) Program Size: data=28.0 xdata=0 code=625 "asm_optimized" - 0 Error(s), 5 Warning(s).The questions are: How do I get variables from the function-signature used in ASM-Code? Can I acces them with #varname? Are they on the stack; or in r0-r7? Reading documentation mentions all these possibilities.
And the second one: Which is the "correct" or recommended way to access the unsigned char idata x[16]-array from the assembler code?
Thanks in advance!
Cheers Markus