"IBM personal computer assembly language tutorial" - читать интересную книгу автора (Auerbach J.)



You should understand that all conditional jumps are inherently
DIRECT, NEAR, and "short"; the "short" part means that they can't
go more than 128 bytes in either direction. Again, this is some-
thing you could easily imagine to be more of a problem than it is.
I follow this simple approach:

1) When taking an abnormal exit from a block of code, I always use
an unconditional jump. Who knows how far you are going to end
up jumping by the time the program is finished. For example, I
wouldn't code this:

TEST AL,IDIBIT ;Is the idiot bit on?
JNZ OYVEY ;Yes. Go to general cleanup

Rather, I would probably code this:

TEST AL,IDIBIT ;Is the idiot bit on?
JZ NOIDIOCY ;No. I am saved.
JMP OYVEY ;Yes. What can we say...
NOIDIOCY:

The latter, of course, is a jump around a jump. Some would say
it is evil, but I submit it is hard to avoid in this language.

2) Otherwise, within a block of code, I use conditional jumps
freely. If the block eventually grows so long that the assem-
bler starts complaining that my conditional jumps are too long
I

a) consider reorganizing the block but

b) also consider changing some conditional jumps to their
opposite and use the "jump around a jump" approach as shown
above.

Enough about specific instructions!

6. Finally, in order to use the assembler effectively, you need to know
the default rules for which segment registers are used to complete
addresses in which situations.

a. CS is used to complete an address which is the target of a NEAR
DIRECT jump. On an NEAR INDIRECT jump, DS is used to fetch the
address from memory but then CS is used to complete the address
thus fetched. On FAR jumps, of course, CS is itself altered. The
instruction counter is always implicitly pointing in the code seg-
ment.