[ Pobierz całość w formacie PDF ]
.The mailman looks to see if theSmith's flag is raised (a test) and if so, opens the Smith's mailbox and picks up thewaiting mail.Each of the Flags register's nine flags has a two-letter symbol by which mostprogrammers know them.I'll use those symbols most of the time, and you shouldbecome familiar with them.The flags, their symbols, and brief descrip-tions of what theystand for follows:" OF The Overflow flag is set when the result of an operation becomes too large to fitin the operand it originally occupied." DF The Direction flag is an oddball among the flags in that it tells the CPUsomething that you want it to know, rather than the other way around.It dictates thedirection that activity moves (up in memory or down in memory) during the execution ofstring instructions.When DF is set, string instructions proceed from high memorytoward low memory.When DF is cleared, string instructions proceed from low memorytoward high memory.See Chapter 10." IF The Interrupt enable flag is a two-way flag.The CPU sets it under certainconditions, and you can set it yourself using the STI and CLI instructions.When IF isset, interrupts (see Chapter 9) are enabled and may occur when requested.When IF iscleared, interrupts are ignored by the CPU." TF When set, the Trap flag allows DEBUG's command to execute only a singleinstruction before the CPU calls an interrupt routine.This is not an especially useful flagfor ordinary programming and I won't have anything more to say about it." SF The Sign flag is set when the result of an operation forces the operand to becomenegative.By "negative," I mean that the highest order bit in the operand (the sign bit)becomes a 1 during a signed arithmetic operation.Any operation that leaves the signpositive will clear SF." ZF The Zero flag is set when the result of an operation is zero.If the operand is somenon-zero value, ZF is cleared." AF The Auxiliary carry flag is used only for Binary Coded Decimal (BCD)arithmetic.BCD arithmetic treats each operand byte as a pair of 4-bit nybbles, and allowssomething approximating decimal (base 10) arithmetic to be done directly in the CPUhardware by using one of the BCD arithmetic instructions.I'll discuss BCD arithmeticbriefly in Chapter 10." PF The Parity flag will seem instantly familiar to anyone who understands serial datafile:///E|/TEMP/Chapter%206%20new.htm (23 of 30) [9/30/02 08:32:41 PM] file:///E|/TEMP/Chapter%206%20new.htmcommunications, and utterly bizarre to anyone who doesn't.PF indicates whether thenumber of set bits in the low-order byte of a result is even or odd.For example, if theresult is OF2H PF will be cleared, because OF2H (11110010) contains an odd numberof 1 bits.Similarly, if the result is 3AH (00111100) PF will be set because there is aneven number (4) of 1 bits in the result.This flag is a carryover from the days when allcomputer communications were done through a serial port, for which a system of errordetection called "parity checking" depends on knowing whether a count of set bits in acharacter byte is even or odd.PF has no other use and I won't be describing it further." CF The Carry flag is by far the most useful flag in the Flags register, and the one youwill have to pay attention to most.If the result of an arithmetic or shift operation "carriesout" a bit from the operand, CF becomes set.Other-wise, if nothing is carried out, CF iscleared.Check That Reference Page!What I call "flag etiquette" is the way a given instruction affects the flags in the Flagsregister.You must remember that the descriptions of the flags on the previous pages aregeneralizations only, and are subject to specific restrictions and special cases imposed byindividual instructions.Flag etiquette for indi-vidual flags varies widely from instructionto instruction, even though the sense of the flag's use may be the same in every case.For example, some instructions that cause a 0 to appear in an operand set ZF, whileothers do not.Sadly, there's no system to it and no easy way to keep it straight in yourhead.When you intend to use the flags in testing by way of conditional jump instructions(See Chapter 9), you have to check each indi-vidual instruction to see how the variousflags are affected.Flag etiquette is a highly individual matter.Check the reference for each instruction tosee it affects the flags.Assume nothing.A simple lesson in flag etiquette involves two new instructions, INC and DEC, and yetanother interesting ability of DEBUG.Adding and Subtracting 1 with INC and DECSeveral instructions come in pairs.Simplest among those are INC and DEC, whichincrement and decrement an operand by 1, respectively.Adding 1 to something or subtracting 1 from something happens a lot in computerprogramming.If you're counting the number of times a program is executing a loop, orfile:///E|/TEMP/Chapter%206%20new.htm (24 of 30) [9/30/02 08:32:41 PM] file:///E|/TEMP/Chapter%206%20new.htmcounting bytes in a table, or doing something that ad-vances or retreats one count at atime, INC or DEC can be a very quick way to make the actual addition or subtractionhappen.Both INC and DEC take only one operand.An error will be flagged by DEBUG or yourassembler if you try to use either INC or DEC with two operands, or without any.Try both by using the Assemble command and the Trace command under DEBUG.Assemble this short program, display the registers after entering it, and then tracethrough it:MOV AX,FFFFMOV BX,002FDEC BXINC AXThe session should look very much like this:-A1980:0100 MOV AX,FFFF1980:0103 MOV BX,002D1980:0106 INC AX1980:0107 DEC BX1980:0108-RAX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=1980 ES=1980 SS=1980 CS=1980 IP=0100 NV UP EI PL NZ NA PONC1980:0100 B8FFFF MOV AX,FFFFTAX=FFFF BX=0000 CX=0000 DX=0000 SP-FFEE BP=0000 SI=0000 DI-0000DS=1980 ES=1980 SS=1980 CS=1980 IP=0103 NV UP EI PL NZ NA PO NC1980:0103 BB2DOO MOV BX,002D-TAX=FFFF BX=002D CX=0000 DX=.0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=1980 ES=1980 SS=1980 CS=1980 IP=0106 NV UP EI PL NZ NA PO NC1980:0106 40 INC AX-Tfile:///E|/TEMP/Chapter%206%20new.htm (25 of 30) [9/30/02 08:32:41 PM] file:///E|/TEMP/Chapter%206%20new.htmAX=0000 BX=002D CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=1980 ES-1980 SS=1980 CS=1980 IP=0107 NV UP EI PL ZR AC PE NC1980:0107 4B DEC BX-TAX-0000 BX=002C CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=1980 ES-1980 SS=1980 CS=1980 IP=0108 NV UP EI PL NZ NA PO NC1980:0108 OF POP CSWatch what happens to the registers.Decrementing BX predictably turns the value 2DHinto value 2CH.Incrementing 0FFFFH, on the other hand, "rolls over" the register to 0.0FFFFH is the largest unsigned value that can be expressed in a 16-bit register [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • czarkowski.pev.pl
  •