Testing Bits with TEST in Visual Studio .NET

Generation QR Code 2d barcode in Visual Studio .NET Testing Bits with TEST
Testing Bits with TEST
QR Reader In .NET
Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in .NET framework applications.
Service 11H returns a word's worth of bits in AX Singly or in twos or threes, the bits tell a tale about specific hardware options on the installed PC These hardware options are summarized in Figure 105
Denso QR Bar Code Generation In VS .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create QR Code image in .NET applications.
Figure 105: Interrupt 11H configuration information The bits we need to examine are bits 4 and 5 If both are set to 1, then we know we have a Monochrome Display Adapter If the two bits are set to any other combination, the adapter must be a Color Graphics Adapter; all other alternatives have by this time been eliminated Testing for two 1 bits in a byte is an interesting exercise-which is one reason I've retained this code in the book, even though it's not as compellingly useful as it was 10 years ago The x86 instruction set recognizes that bit testing is done a lot in assembly language, and it provides what amounts to a CMP instruction for bits: TEST
Decoding QR-Code In Visual Studio .NET
Using Barcode decoder for .NET Control to read, scan read, scan image in VS .NET applications.
The Phantoms of the Opcodes
Create Barcode In .NET Framework
Using Barcode printer for .NET Control to generate, create bar code image in .NET framework applications.
TEST performs an AND logical operation between two operands, and then sets the flags as AND would, without altering the destination operation, as AND would Here's the TEST instruction syntax: TEST <operand>,<bit mask> The bit mask operand should contain a 1 bit in each position where a 1 bit is to be sought in the operand, and 0 bits in all the other bits What TEST does is AND the operand against the bit mask and set the flags as AND would The operand doesn't change For example, if you want to determine if bit 3 of AX is set to 1, you would use this instruction: TEST AX,3 ; 3 in binary is 00001000B
Recognizing Bar Code In .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
AX doesn't change as a result of the operation, but the AND truth table is asserted between AX and the binary pattern 00001000 If bit 3 in AX is a 1 bit, then the Zero flag is cleared to 0 If bit 3 in AX is a 0 bit, then the Zero flag is set to 1 Why If you AND 1 (in the bit mask) with 0 (in AX), you get 0 (Look it up in Table 102,
QR Code Maker In Visual C#
Using Barcode generation for .NET framework Control to generate, create QR image in .NET framework applications.
the AND truth table) And if all eight bitwise AND operations come up 0, the result is 0, and the Zero flag is raised to 1, indicating that the result is 0 Key to understanding TEST is thinking of TEST as a sort of Phantom of the Opcode, where the Opcode is AND TEST pretends it is AND, but doesn't follow through with the results of the operation It simply sets the flags as though an AND operation had occurred CMP is another Phantom of the Opcode and bears the same relation to SUB as TEST bears to AND CMP subtracts its second operand from its first, but doesn't follow through and store the result in the first operand It just sets the flags as though a subtraction had occurred
QR Code 2d Barcode Creation In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
TEST Pointers
QR Code JIS X 0510 Generation In VB.NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in .NET framework applications.
Here's something important to keep in mind: TEST is only useful for finding 1 bits If you need to identify 0 bits, you must first flip each bit to its opposite state with the logical NOT instruction, as I explained earlier NOT changes all 1 bits to 0 bits, and all 0 bits to 1 bits Once all 0 bits are flipped to 1 bits, you can test for a 1 bit where you need to find a 0 bit (Sometimes it helps to map it out on paper to keep it all straight in your head) Also, TEST will not reliably test for two or more 1 bits in the operand at one time TEST doesn't check for the presence of a bit pattern; it checks for the presence of a single 1 bit In other words, if you need to check to make sure that both bits 4 and 5 are set to 1, TEST won't hack it And unfortunately, that's what we have to do in DispID What we're looking for in the last part of DispID is the monochrome code in bits 4 and 5, which is the value 30H; that is, both bits 4 and 5 set to 1 Don't make the mistake (as I did once, in ages long past) of assuming that we can use TEST to spot the two 1 bits in bits 4 and 5: test AL,30H jnz CGA ; If bits 4 & 5 are both =1, it's an MDA ; otherwise it's a CGA
European Article Number 13 Generator In .NET
Using Barcode creation for .NET Control to generate, create GTIN - 13 image in Visual Studio .NET applications.
This doesn't work! The Zero flag will be set only if both bits are zero If either bit is 1, ZF will become 0, and the branch will be taken However, we only want to take the branch if both bits are 1 Here's where your right brain can sometimes save both sides of your butt TEST only spots a single 1 bit at a time We need to detect a condition where two 1 bits are present So let's get inspired and first flip the state of all bits in the Equipment Identification Byte with NOT, and then look at the byte with TEST After using NOT, what we need to find are two 0 bits, not two 1 bits And if the two bits in question (4 and 5) are now both zero, the whole byte is zero, and the Zero flag will be set and ready to test via JNZ: not AL test AL,30H jnz CGA ; ; ; ; Invert all bits in the equipment ID byte See if either of bits 4 or 5 are 1-bits If both = 0, they originally were both 1's, and the adapter is a monochrome
Barcode Creator In Visual Studio .NET
Using Barcode printer for .NET Control to generate, create bar code image in .NET framework applications.
Tricky, tricky But as you get accustomed to the instruction set and its quirks, you'll hit upon lots of nonobvious solutions to difficult problems of that kind So, get that right brain working: How would you test for a specific pattern that was a mix of 0 bits and 1 bits
Data Matrix ECC200 Generator In VS .NET
Using Barcode encoder for .NET framework Control to generate, create DataMatrix image in .NET applications.
Codabar Generator In .NET
Using Barcode maker for .NET framework Control to generate, create USD-4 image in .NET applications.
Paint Code128 In VB.NET
Using Barcode generator for VS .NET Control to generate, create Code 128C image in Visual Studio .NET applications.
Scan ANSI/AIM Code 39 In .NET Framework
Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Draw Code 128 Code Set B In Java
Using Barcode drawer for Java Control to generate, create Code 128 Code Set C image in Java applications.
Barcode Generator In Java
Using Barcode printer for Java Control to generate, create barcode image in Java applications.