tailieunhanh - The 80x86 IBM PC and Compatible Computers- P4

The 80x86 IBM PC and Compatible Computers- P4: Praised by experts for its clarity and topical breadth, this visually appealing, one-stop source on PCs uses an easy-to-understand, step-by-step approach to teaching the fundamentals of 80x86 assembly language programming and PC architecture. Offering users a fun, hands-on learning experience, it uses the Debug utility to show what action the instruction performs, then provides a sample program to show its application. | Bitwise shift operators in C There are two bitwise shift operators in C Shift Right and Shift Left . They perform exactly the same operation as SHR and SHL in Assembly language as discussed in Section . Their format in C is as follows data number of bits to be shifted shifting right data number of bits to be shifted shifting left The following shows Examples 3-9 through 3-11 using shift operators in C. Program 3-10 shows all of these examples with C syntax. 0x9A 3 0x13 0x7777 4 0x0777 0x6 4 - 0x60 shifting right 3 times see Example 3-9 shifting right 4 times see Example 3-10 shifting left 4 times see Example 3-11 Program 3-10 Repeats Examples 3-5 through 3-11 in C include mainO Notice the way data is defined in C for Hex format using Ox unsigned char data_1 0x35 unsigned int data_2 0x504 unsigned int data_3 0xDA66 unsigned char data_4 0x54 unsigned char data_5 0x78 unsigned char data_6 0x37 unsigned char data_7 0x09A unsigned char temp unsigned int temp_2 temp data_1 0x0F ANDing printf nMasking the upper four bits of X hex we get X hex n data_1 temp temp_2 data_2 data_3 ORing printf The result of X hex ORed with X hex is X hex n data_2 data_3 temp_2 temp data_4 data 5 EX-ORing printf The results oT X hex EX-ORed with X hex is X hex n data_4 data_5 temp temp -data_6 INVERTING printf The result of X hex inverted is X hex n data_6 temp temp data_7 3 SHIFTING Right printff When X hex is shifted right three times we get X hex n data_7 temp printf When X hex is shifted right four times we get X hex n 0x7777 0x7777 4 temp 0x6 4 SHIFTING Left printff When X hex is shifted left d times we get X hex n 0x6 4 temp Program 3-10 Program 3-10 demonstrates the syntax of bitwise operators in C. Next we show some real-world examples of their usage. Please purchase PDF Split-Merge on to remove this SECTION BITWISE OPERATION IN THE C LANGUAGE 115 Packed BCD to ASCII conversion in C Section showed one way to convert a BCD number to ASCII.