Friday, September 23, 2011

MOVC A, @A+DPTR

It moves code byte.
No flags are affected
This moves a byte of data located in program code ROM into Accumulator A.
This allows to create a lookup table of sorts in code space and read them into CPU.
The address of the desired byte in code space is formed by adding A + DPTR

Example:

ORG 0000
MOV DPTR, #200H    ;
LOOP : CLR A    ;
MOVC A,@A+DPTR    ; MOVE DATA @A+DPTR IN A
JZ EXIT        ;
MOV P1, A    ;
INC DPTR    ;
SJMP LOOP    ;
EXIT :
-----
-----
ORG 200H
DB 'A','B','C',0;
END

another example can be finding square or square root of numbers.
This is strictly used for on chip ROM. for off chip memory we use MOVX.


MOVC A, @A+PC

It moves code byte.
No flags are affected
Same as above instruction inly difference is that the PC is used instead of DPTR.

Example:

MOV A, R3    ;
INC A        ;
MOVC A, @A+PC    ;
RET
DB 0,1,4,9,16,25;

The following should be noted:

The program counter, which is pointing to the RET is taken for addition.
Always remember that always the next code value is taken in PC before adding to Accumulator A.
 This method is preferrable over "MOVC A, @A+DPTR" when we do not want to divide the program code space into 2 separate

areas of code and data. As a result we save considerable amount of space on chip

No comments:

Post a Comment