[ Pobierz całość w formacie PDF ]
.Any XCHG instruction with AX as one of the operands is represented by a single-byteopcode.The general forms of XCHG (like XCHG r16,r16) are always two bytes longinstead.This implies that there are actually two different opcodes that will do the job fora given combination of operands (for example, XCHG AX,DX).True enough andmost assembler programs are "smart" enough to choose the shortest form possible in anygiven situation.If you are hand-assembling a sequence of raw opcode bytes, say, for usein a Turbo Pascal INLINE statement, you need to be aware of the special cases, and allspecial cases will be marked as such in the Legal forms section.When you want to use an instruction with a certain set of operands, make sure you checkthe Legal forms section of the reference guide for that instruc-tion to make sure that thecombination is legal.The MOV instruction, for example, cannot move one segmentregister directly into another, nor can it move immediate data directly into a segmentregister.Neither combination of operands is a legal form of the MOV instruction.In the example reference page on the NEG instruction, you'll see that a segment registercannot be an operand to NEG.(If it could, there would be a NEG sr item in the Legalforms list.) If you want to negate the value in a segment register, you'll first have to useMOV to move the value from the segment register into one of the general-purposeregisters.Then you can use NEG on the general-purpose register, to move the negatedvalue back into the segment register.Operand SymbolsThe symbols used to indicate the nature of the operands are included on every page inAppendix A.They're close to self-explanatory, but I'll take a moment to expand uponthem slightly here:" r8 An 8-bit register half ( AH, AL, BH, BL, CH, CL, DH, or DL).file:///E|/TEMP/Chapter%206%20new.htm (20 of 30) [9/30/02 08:32:41 PM]file:///E|/TEMP/Chapter%206%20new.htm" rl6 A 16-bit general-purpose register (AX, BX, CX, DX, BP, SP, SI or DI)." sr One of the four segment registers (CS, DS, SS, or ES)." m8 An 8-bit byte of memory data." ml6 A 16-bit word of memory data." i8 An 8-bit byte of immediate data." i16 A 16-bit word of immediate data." d8 An 8-bit signed displacement.We haven't covered this operand yet, but a displacement is a distance between the currentlocation in the code and another place in the code to which we want to jump.It's signed(negative or positive) because a positive displacement jumps you higher (forward) inmemory, whereas a negative displacement jumps you lower (back) in memory.We'llexamine this notion in detail in Chapter 9." d16 A 16-bit signed displacement.Again, for use with jump and call instruc-tions.See Chapter 9.ExamplesThe Legal forms section shows what combinations of operands is legal for a giveninstruction, and the Examples section shows examples of the instruction in actualuse just as it would be coded in an assembly-language program.I've tried to put a goodsampling of examples for each instruction, demonstrating the range of possibilitiesavailable with the instruction.This includes situations that require type overridespecifiers (which I'll cover in the next section).NotesThe Notes section of the reference page briefly describes the instruction's action, andprovides information on how it affects the flags, how it may be limited in use, and anyother detail that needs to be remembered, especially things that beginners wouldoverlook or misconstrue.What's Not Here.Appendix A differs from most detailed assembly-language references in that it does nothave the binary opcode encoding information or the indications of how many machinecycles are used by each form of the instruction.file:///E|/TEMP/Chapter%206%20new.htm (21 of 30) [9/30/02 08:32:41 PM]file:///E|/TEMP/Chapter%206%20new.htmThe binary encoding of an instruction is the actual sequence of binary bytes that the CPUdigests as the machine instruction.What we would call POP AX the machine sees as thebinary number 58H.What we call ADD SI,07733H the machine sees as 81H OC6H33H 77H.Machine instructions are encoded into anywhere from one to four (rarelymore) binary bytes depending on what instruction they are and what their operands are.Laying out the system for determining what the encoding will be for any giveninstruction is extremely complicated, in that its component bytes must be set up bit by bitfrom several large tables.I've decided that this book is not the place for that particulardiscussion, and have left encoding information out of Appendix A.Finally, I've included nothing anywhere in this book that indicates how many machinecycles are expended by any given machine instruction.A ma-chine cycle is one pulse ofthe master clock that makes the PC perform its magic.Each instruction uses somenumber of those cycles to do its work, and the number varies all over the map dependingon criteria that I won't be explaining in this book.Furthermore, as Michael Abrash explains in his book, Zen of Assembly Language,knowing the cycle requirements for individual instructions is rarely sufficient to alloweven an expert assembly-language programmer to calculate how much time a givenseries of instructions will take.He and I both agree that it is no fit subject for beginners,and I will let him take it up in his far more advanced volume.6.5 Rally 'Round the Flags, Boys!We haven't studied the Flags register as a whole.The Flags register is a veritablejunkdrawer of disjointed bits of information, and it's tough (and perhaps mis-leading) tojust sit down and describe all of them in detail at once.What I'll do is describe the flagsas we encounter them in discussing the various instructions in this and future chapters.The Flags register as a whole is a single 16-bit register buried inside the CPU.Of those16 bits, 9 are actually used as flags on the 8088/8086.The remaining seven bits areundefined and ignored.You can neither set them nor read them.Some of those seven bitsbecome defined and useful in the more advanced processors like the 286, 386, and 486,but their uses are fairly arcane and I won't be covering them in this book, even in Chapter11, which discusses the more advanced processors.A flag is a single bit of information whose meaning is independent from any other bit.Abit can be set to 1 or cleared to 0 by the CPU as its needs require.The idea is to tell you,the programmer, the state of certain conditions inside the CPU, so that your program cantest for and act on the states of those conditions.file:///E|/TEMP/Chapter%206%20new.htm (22 of 30) [9/30/02 08:32:41 PM]file:///E|/TEMP/Chapter%206%20new.htmI often imagine a row of country mailboxes, each with its own little red flag on the side
[ Pobierz całość w formacie PDF ]