At 12:47 PM 8/29/2005, you wrote:
One thing to be careful about if your segments are large is that the 16
bits used for relative branching is a *signed* value, meaning that you can
jump +/- 32K bytes from the current location. This in turn means that an
instruction near the end of a 64K segment still can't branch to an
instruction near the beginning of the segment if the two instructions are
more than 32K bytes apart, even though they're in the same segment.
If you keep your segments to no more than 32K bytes total, then you will
always be safe. And inter-segment branches are done with "long" 32-bit
direct jumps.
Actually, inter-segment jumps are done with indirect jumps through a table
-- rather than jumping to a specific address, you instead jump to a
hard-coded jump instruction that's stored in the data section of the
program, with the hard-coded address modified at application launch time by
the startup code.
It is possible to do relative jumps of >32K -- CW generates those when you
use the large code model. Those are done by reading the PC into a
register, adding a value to that register, then doing an indirect jump
through the register. They are slower than normal jumps as they take three
instructions to execute, where a normal relative jump is just one instruction.
-- Ben Combee, Senior Software Engineer, palmOne, Inc.
"Combee on Palm OS" weblog: http://palmos.combee.net/
Developer Forum Archives: http://news.palmos.com/read/all_forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/