Texas Instruments MSC1210 User Manual

Page 227

Advertising
background image

Reading Code Memory/Tables (MOVC)

16-33

8052 Assembly Language

For example, if the data in the previous example are located right after the rou-
tine that read it, instead of being located at code memory 2000

H

, the subrou-

tine could be changed to:

SUB:

INC A

;Increment accumulator to account for
;RET instruction

MOVC A,@A+PC ;Get the data from the table

RET

;Return from subroutine

DB 01h,02h,03h,04h,05h

;The actual data table

Note:

In the above example, we first increment the accumulator by 1. This is
because the value of PC will be that of the instruction immediately following
the MOVC instruction—in this case, the RET instruction. The RET opcode
is not needed, but the data that follows RET is. The accumulator needs to
be INCremented by 1 byte to skip over the RET instruction because the RET
instruction requires one byte of code memory.

Note:

The value that the accumulator must be incremented by is the number of
bytes between the MOVC instruction and the first data of the table being
read. For example, if the RET instruction above is replaced with an LJMP
instruction that is 3 bytes long, the INC A instruction would be replaced with
ADD A,#03h to increment the accumulator by 3.

Advertising