We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
if my ASM code is previously coded to run for 256Byte internal RAM of MCU (use MOV instruction) and i now need to change to external 2Kbyte RAM (use MOVX), then should i change R7 to R7:R6 because R7 is not big enought to address BUFFER? or can anyone suggest what should i change the following code? unsigned char Test(unsigned char BUFFER) { #pragma asm MOV A, R7 MOV R1, A RET #pragma endasm return 1; }
The address for the MOVX A, @DPTR instruction comes from the DPTR register. For "pdata" access with the MOVX A,@Ri form, the high byte of the address comes from P2, and the low byte comes from the register in question.
Sorry, let me make it clear! 2Kbyte should be expanded internal RAM of MCU. The datasheet of MCU states that MOVX should be used to access data. So, how to deal with R7 in this case?
Your example moves the BUFFER parameter (a byte in R7) to R1, which has no practical effect that we can see. That said, it will work on any 8051 regardless of its external or expanded internal RAM. So no changes are required.
If my ASM code is previously coded to run for 256 byte internal RAM of MCU (use MOV instruction) and i now need to change to external 2Kbyte RAM (use MOVX), then should i change R7 to R7:R6 because R7 is not big enought to address BUFFER? or can anyone suggest what should i change the following code? Some 8051 family variants have extra memory beyond the 256 byte scratchpad RAM that is described as "internal". Invariably, a better description from a programmers point of view would be "external on-chip RAM". To the CPU this extra on-chip RAM looks just like RAM that would be in an external chip accessed via an external bus on a conventional 8051/8052 design. Of course, there will be some other differences, P0 may be available as an I/O port for example. So, you need to use a MOVX instruction to get at this on-chip ram. For example, you will need something like the following (untested):
unsigned char Test( unsigned int address ) { address = address; //suppress UNUSED warning // will be optimised out. #pragma asm MOV DPH,R6 MOV DPL,R7 MOVX A,@DPTR MOV R7,A RET #pragma endasm return( 1 ); // dummy return }
But R1 in RB0 has physical address 0x01, R1 in RB1 has physical address 0x09, R1 in RB2 has physical address 0x11, and R1 in RB3 has physical address 0x19. The example is effectively R1 = BUFFER. What 8051 has registers allocated to memory accessible via MOVX?