CH55x special instruction 0xA5 (MOVX @DPTR1,A)

I have designed 2 short asm modules for copy data from code or xdata. 


My goal is to replace the generic memcpy () and memset() library functions for most cases.

While this is working well I have some doubts if this is interrupt save. I dont plan to use that special

auto inc feature bDPTR_AUTO_INC because i think its not worth the trouble i might get.


;void fastccpy8 (unsigned char xdata *dest, //r6r7    
;                unsigned char code  *src,  //r4r5     
;                unsigned char  size)       //r3        
sfr XBUS_AUX = 0xA2;     
?PR?_fastccpy8?FASTCCOPY  SEGMENT CODE    
PUBLIC	_fastccpy8    
$REGUSE _fastccpy8(R7,A,DPTR)    

RSEG   ?PR?_fastccpy8?FASTCCOPY    
_fastccpy8:     
       MOV  XBUS_AUX,#0x01; select DPTR1, no auto inc         
       MOV  DPH,R6     
       MOV  DPL,R7     ;destination    
       DEC  XBUS_AUX   ;select DPTR0    
       MOV  DPH, R4    
       MOV  DPL, R5    ;source    
       mov  A,R3    
       MOV  R7,A       
       JZ   ?C001      ;nothing todo     
?C000: CLR  A    
       MOVC A,@A+DPTR   ;read source    
       INC  DPTR       ;no autoinc its not irq save    
       DB   0A5H       ;MOVX @DPTR1,A & INC DPTR1    
       DJNZ R7,?C000    
?C001: RET

I have successfully testet that in interrupt functions as well as in main context, but i still have doubts if it is working correctly in

complex applications with irqs possibly set on different priorities.

There is a simlar function fastxcpy8 for copy from xdata


Any ideas are welcome.

donot doubts about auto inc,  these instructions are single cycle.

but, DPTR and DPTR1 are two reg,

ASM: in interrupt, you need save DPH/DPL if use DPTR in interrupt, just like using&saving B.

      and, if use the copy with DPTR1, u need save DPTR1 too, by save XBUS_AUX then select,

      save all regs u changed in interrupt.

keil C: it will save DPTR auto (if used), but not include DPTR1

so, 1. disable interrupt on copy entry, so not save DPTR1 & XBUS_AUX

2. or dont call the copy in interrupt


many thanks for your sugestions. 

I have compiled them into my code snippet. Cant find any downside exept after the first  calling of the copy function interrupts are globally enabled. This could be solved by reserving a bit in bit space for the EA state. I need to read the Keil docs about the correct syntax for that.

;void fastccpy8 (unsigned char xdata *dest, //r6r7    
;                unsigned char code  *src,  //r4r5     
;                unsigned char  size)       //r3        
sfr XBUS_AUX = 0xA2;     
?PR?_fastccpy8?FASTCCOPY  SEGMENT CODE    
PUBLIC  _fastccpy8    
$REGUSE _fastccpy8(R7,A,DPTR)    
 
RSEG   ?PR?_fastccpy8?FASTCCOPY    
_fastccpy8: 
       CLR  EA      
       MOV  XBUS_AUX,#0x01; select DPTR1, no auto inc
       PUSH DPH        ;save old DPTR1
       PUSH DPL         
       MOV  DPH,R6     
       MOV  DPL,R7     ;destination    
       DEC  XBUS_AUX   ;select DPTR0
       SETB EA    
       MOV  DPH, R4    
       MOV  DPL, R5    ;source    
       mov  A,R3    
       MOV  R7,A       
       JZ   ?C001      ;nothing todo     
?C000: CLR  A    
       MOVC A,@A+DPTR  ;read source    
       INC  DPTR       ;no autoinc its not irq save    
       DB   0A5H       ;MOVX @DPTR1,A & INC DPTR1    
       DJNZ R7,?C000    
?C001: CLR  EA         ;restore the old values
       MOV  XBUS_AUX,#0x01
       POP  DPL
       POP  DPH
       DEC  XBUS_AUX
       SETB EA
       RET

so now 2 extra bytes in stack space are used (3 if i also save XBUS_AUX).


On the longterm I am planing to create device libs for the WCH chips with a bunch of functions. Similar to the WCH debug.c but sperately compiled as library.


FOR RE-ENTER SUBROUTINE (CALLED BY BOTH MAIN PROGRAM & INTERRUPT)

_fastccpy8: 

       PUSH XBUS_AUX      
       MOV  XBUS_AUX,#0x01; select DPTR1
       PUSH DPH        ;save old DPTR1
       PUSH DPL         
       MOV  DPH,R6     
       MOV  DPL,R7     ;destination    
       DEC  XBUS_AUX   ;select DPTR0
       MOV  DPH, R4    
       MOV  DPL, R5    ;source    
       mov  A,R3    
       MOV  R7,A       
       JZ   ?C001      ;nothing todo     
?C000: CLR  A    
       MOVC A,@A+DPTR  ;read source    

        INC  DPTR

       DB   0A5H       ;MOVX @DPTR1,A & INC DPTR1    

       DJNZ R7,?C000    
?C001: INC XBUS_AUX
       POP  DPL
       POP  DPH
       POP  XBUS_AUX

       RET

OR:

_fastccpy8: 

       CLR  EA
       MOV  XBUS_AUX,#0x01; select DPTR1
       MOV  DPH,R6     
       MOV  DPL,R7     ;destination    
       DEC  XBUS_AUX   ;select DPTR0
       MOV  DPH, R4    
       MOV  DPL, R5    ;source    
       mov  A,R3    
       MOV  R7,A       
       JZ   ?C001      ;nothing todo     
?C000: CLR  A    

       MOVC A,@A+DPTR  ;read source  

         INC DPTR  

       DB   0A5H       ;MOVX @DPTR1,A & INC DPTR1    
       DJNZ R7,?C000    
?C001:  SETB EA

       RET






does auto inc work on MOVC A,@A+DPTR too?

In the datasheet and h files auto inc is just mentioned for MOVX (CH552)


SORRY,  AUTO INC NOT SUPPORT MOVC


只有登录才能回复,可以选择微信账号登录