Move Code Byte – MOVC A,@A+base-reg
The MOVC instructions load the Accumulator with a code byte or constant from program memory. The address of the byte fetched is the sum of the original unsigned 8-bit Accumulator contents and the contents of a 16-bit base register, which may be either the Data Pointer or the PC. In the latter case, the PC is incremented to the address of the following instruction before being added with the Accumulator; otherwise the base register is not altered. Sixteen-bit addition is performed so a carry-out from the low-order eight bits may propagate through higher-order bits. No flags are affected.
MOVC A,@A+DPTR
Encoding:10010011
MOVC A,@A+PC
Encoding:10000011
A value between 0 and 3 is in the Accumulator. The following instructions will translate the value in the Accumulator to one of four values defined by the DB (define byte) directive.
REL_PC : | ||
INC A | ||
MOVC A,@A+PC | ||
RET | ||
DB 66H | ||
DB 77H | ||
DB 88H | ||
DB 99H |
If the subroutine is called with the Accumulator equal to 01H, it returns with 77H in the Accumulator. The INC A before the MOVC instruction is needed to “get around” the RET instruction above the table. If several bytes of code separate the MOVC from the table, the corresponding number is added to the Accumulator instead.
Example:
ORG 0H ; start (origin) at location 0
MAIN :
MOV A, #00H
ACALL REL_PC
MOV P0, #10H
AJMP MAIN
RET
ORG 100H
REL_PC :
INC A
MOVC A,@A+PC
RET
DB 66H
DB 77H
DB 88H
DB 99H
END ; end of asm source file
Related topics:
8051 Move Byte | 8051 Move Bit | 8051 Move Word | 8051 Move External | 8051 MOVX Instruction | 8051 MOVC Instruction | 8051 MOV Instruction
List of topics: 8051
No comments:
Post a Comment