
LED_OK      EQU   P1.0
LED_ERROR   EQU   P1.1
RAM         EQU   8000h
Test:
   mov   dptr,#RAM                ;set destination address
   mov   r2,dph
   mov   r3,dpl                   ;and store it
   mov   dptr,#RAMTest            ;set source address
   mov   r7,#RAMTestEnd-RAMTest   ;set counter
Loop:
   clr   a
   movc  a,@a+dptr                ;get source byte
   mov   r6,a                     ;store it temporarily
   inc   dptr                     ;advance source address
   mov   r4,dph
   mov   r5,dpl                   ;store source address
   mov   dph,r2
   mov   dpl,r3                   ;restore destination address
   movx  @dptr,a                  ;store byte to destination
   movx  a,@dptr                  ;readback byte from RAM
   xrl   a,r6                     ;test if stored in RAM correctly
   jnz   Error
   inc   dptr                     ;advance destination address
   mov   r2,dph
   mov   r3,dpl
   mov   dph,r4
   mov   dpl,r5                   ;exchange src/dest addresses
   djnz  r7,Loop                  ;loop for all bytes
   ljmp  RAM                      ;execute code in RAM

Error:
   clr   LED_ERROR                ;in case of error, red LED lit
   sjmp  Error                    ;and stay looping forever

RAMTest:
   clr   LED_OK                   ;turn on green LED
   ljmp  RAMTest                  ;and stay looping forever
RAMTestEnd:
   end