Texas Instruments MSC1210 User Manual

Page 63

Advertising
background image

Direct Jumps

6-3

Program Flow

Consider the example:

LJMP NEW_ADDRESS

.

.

.

NEW_ADDRESS: ....

The LJMP instruction in this example means “Long Jump.” When the
MSC1210 executes this instruction, the PC is loaded with the address of
NEW_ADDRESS and program execution continues sequentially from there.

The obvious difference between the Direct Jump and Call instructions and
conditional branching is that with Direct Jumps and Calls, program flow always
changes; with conditional branching, program flow only changes if a certain
condition is true.

It is worth mentioning that, aside from LJMP, there are two other instructions
that cause a direct jump to occur: the SJMP and AJMP commands.
Functionally, these two commands perform the exact same function as the
LJMP command—that is to say, they always cause program flow to continue
at the address indicated by the command. However, these instructions differ
from LJMP in that they are not capable of jumping to any address. They both
have limitations as to the range of the jumps.

The SJMP command, like the conditional branching instructions, can only
jump to an address within −128/+127 bytes of the address following the SJMP
command.

The AJMP command can only jump to an address that is in the same 2k block
of memory as the byte following the AJMP command. That is to say, if the
AJMP command is at code memory location 650

H

, it can only do a jump to ad-

dresses 0000

H

through 07FF

H

(0 through 2047, decimal).

You may ask “why use the SJMP or AJMP commands, which have restrictions
as to how far they can jump, if they do the same thing as the LJMP command
that can jump anywhere in memory?” The answer is simple: the LJMP com-
mand requires three bytes of code memory, whereas both the SJMP and
AJMP commands require only two. When developing applications that have
memory restrictions, quite a bit of memory can be saved using the 2-byte
AJMP/SJMP instructions instead of the 3-byte instruction.

Note:

Some assemblers will do the above conversion automatically. That is, they
will automatically change LJMPs to SJMPs whenever possible. This is a nifty
and very powerful capability that may be a necessity in an assembler, if
planning to develop many projects that have relatively tight memory
restrictions.

Advertising