| ??? 01/08/07 17:18 Read: times |
#130441 - Code transform from A51 -> C51 Keil |
Hi people,
I am having a problem with a code transformation from Keil A51 to C51. The reason why am I doing such a craziness is because I want that the source code can be compiled by both Keil and SDCC. And because SDCC assembler does not support macros, defines I want to have all the source code in C. The mentioned code piece is time critical (that's why It was written in assembler) so I have to be SURE that the C compiled code has the same efficienty as the assembler one. So simple to say I want to be sure that the code piece translated by Keil to assembler is the same as "it was" when it was written in assembler. So here is the assembler code which I want to translate:
?PR?_APBBR_read_data?APBBR_READ_DATA SEGMENT CODE
RSEG ?PR?_APBBR_read_data?APBBR_READ_DATA
_APBBR_read_data :
; save the EA bit in C and disable interrupts
;PUSH PSW
MOV C,EA
CLR EA
; set the address
MOV APBBR_ADDR_LSB_REG, R7
MOV APBBR_ADDR_MSB_REG, R6
; do the APB access
MOV APBBR_OPCODE_REG, #APBBR_OP_SINGLE_READ
NOP
; get the resulting data
MOV R7, APBBR_RDATA_LLSB_REG
MOV R6, APBBR_RDATA_ILSB_REG
MOV R5, APBBR_RDATA_IMSB_REG
MOV R4, APBBR_RDATA_MMSB_REG
; restore previous condition for the interrupts
MOV EA,C
;POP PSW
RET
END
Here is the translation to C51:
#define APBBR_set_address(addr)
{ APBBR_ADDR_LSB_REG = ( (addr) & ((uint16)0x00FF) ) ; \
APBBR_ADDR_MSB_REG = (((addr)>>8) & ((uint16)0x00FF) ) ; }
uint32 APBBR_read_data(uint16 addr)
{
uint32 *tmp;
tmp=APBBR_RDATA_MMSB_ADDR;
//save the EA bit in Carry bit in PSW register and disable interrupts
CY=EA;
EA=0;
//set the address
APBBR_set_address(addr);
//do the APB access
APBBR_OPCODE_REG=APBBR_OP_SINGLE_READ;
_nop_ ();
EA=CY;
//get the resulting data
return *tmp;
}
When I check the C51 compilation listing, everything is optimal except of the tmp return value translation. Keil uses it special function called ?C?LLDPTR to transform the return values. But I have no access to this function source code. My question is: How can I be sure that the function ?C?LLDPTR does not take more time as the MOV's R7-R4 in my assembler version? Thank you for any response in advance. Attila |



