??? 01/09/07 13:58 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#130495 - Code transform from A51 -> SDCC Responding to: ???'s previous message |
SDCC has data types for 16 and 32 bit SFR so translating your assembly code to C is straightforward:
#include <8052.h> /* It is highly encouraged to have a look into the include file compiler.h http://svn.sourceforge.net/viewvc/sd...iew=markup if you want to share header files between different compilers: */ #include <compiler.h> /* you did not tell the addresses so you have to adapt these to your hardware */ SFR (APBBR_OPCODE, 0xE6); SFR16 (APBBR_ADDR, 0xE0); //SFR16E (APBBR_ADDR, 0xE1E0); SFR32 (APBBR_RDATA, 0xE2); //SFR32E (APBBR_RDATA, 0xE5E4E3E2); #define APBBR_OP_SINGLE_READ (0x0a) unsigned long APBBR_read_data(unsigned int addr) { bit tmp_EA = EA; EA = 0; APBBR_ADDR = addr; APBBR_OPCODE = APBBR_OP_SINGLE_READ; __asm nop __endasm; EA = tmp_EA; return APBBR_RDATA; } compiles to: 0000 340 _APBBR_read_data: 0000 AA 82 350 mov r2,dpl 0002 AB 83 351 mov r3,dph 352 ; sfr32.c:21: bit tmp_EA = EA; 0004 A2 AF 354 mov c,_EA 0006 92*00 355 mov _APBBR_read_data_tmp_EA_1_1,c 356 ; sfr32.c:23: EA = 0; 0008 C2 AF 358 clr _EA 359 ; sfr32.c:24: APBBR_ADDR = addr; 000A 8A E0 361 mov _APBBR_ADDR,r2 000C 8B E1 362 mov (_APBBR_ADDR >> 8),r3 363 ; sfr32.c:25: APBBR_OPCODE = APBBR_OP_SINGLE_READ; 000E 75 E6 0A 365 mov _APBBR_OPCODE,#0x0A 366 ; sfr32.c:27: __asm nop __endasm; 0011 00 368 nop 369 ; sfr32.c:29: EA = tmp_EA; 0012 A2*00 371 mov c,_APBBR_read_data_tmp_EA_1_1 0014 92 AF 372 mov _EA,c 373 ; sfr32.c:30: return APBBR_RDATA; 0016 85 E2 82 375 mov dpl,_APBBR_RDATA 0019 85 E3 83 376 mov dph,(_APBBR_RDATA >> 8) 001C 85 E4 F0 377 mov b,(_APBBR_RDATA >> 16) 001F E5 E5 378 mov a,(_APBBR_RDATA >> 24) 0021 22 380 ret (No library calls involved) If your code is really time critical please see manual section 3.12 Inline Assembler Code Happy hacking! |