Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS-280 Dr. Mark L. Hornick 1 ASCII table. 2 Displaying Numbers as Text Problem: display numerical values as text Consider the numerical value 0x5A held.

Similar presentations


Presentation on theme: "CS-280 Dr. Mark L. Hornick 1 ASCII table. 2 Displaying Numbers as Text Problem: display numerical values as text Consider the numerical value 0x5A held."— Presentation transcript:

1 CS-280 Dr. Mark L. Hornick 1 ASCII table

2 2 Displaying Numbers as Text Problem: display numerical values as text Consider the numerical value 0x5A held in a single 8-bit register The string “0x5A” is to be displayed on the LCD

3 CS-280 Dr. Mark L. Hornick 3 How to do it? Each hex digit represents 4 bits Ex: Numeric value 0x5A in binary is 0101 1010. We need to output characters ‘0’, ‘x’, ‘5’, ‘A’ ‘0’ is ASCII character code 0x30 ‘x’ is ASCII 0x78 ‘5’ is ASCII 0x35 ‘A’ is ASCII 0x41 Is there any pattern here?

4 CS-280 Dr. Mark L. Hornick 4 Pattern? ASCII characters ‘0’-’9’: The ASCII code for ‘0’ is 0x30 = 0x0 + 0x30 The ASCII code for ‘1’ is 0x31 = 0x1 + 0x30 The ASCII code for ‘8’ is 0x38 = 0x8 + 0x30 The ASCII code for ‘9’ is 0x39 = 0x9 + 0x30 ASCII characters ‘A’-’F’ The ASCII code for A is 0x41 = 0xA + 0x37 The ASCII code for B is 0x42 = 0xB + 0x37 The ASCII code for C is 0x43 = 0xC + 0x37 The ASCII code for D is 0x44 = 0xD + 0x37 The ASCII code for E is 0x45 = 0xE + 0x37 The ASCII code for F is 0x46 = 0xF + 0x37

5 CS-280 Dr. Mark L. Hornick 5 Solution For hex values 0x0 – 0x9 Add 0x30 to convert to ASCII code of corresponding character ‘0’ – ‘9’ For hex values 0xA – 0xF Add 0x37 to convert to ASCII code of corresponding character ‘A’ – ‘F’ Add 0x57 to convert to ASCII code of corresponding character ‘a’ – ‘f’

6 CS-280 Dr. Mark L. Hornick 6 SWAP Instruction LDIr20, 0x5A; init SWAP r20; swap nibbles After SWAP, r20 contains 0xA5

7 CS-280 Dr. Mark L. Hornick 7 Converting numeric to ASCII LDIr20, 0x5A; init r20 to a value MOVr21, r20; copy r20 ANDIr21, 0x0F; r21=0x0A after mask MOVr22, r20; copy r20 SWAP r22; r22=0xA5 after swap ANDIr22, 0x0F; r22=0x05 after mask LDIr20, 0x37; ASCII offset for A-F ADDr21, r20; r21 is now 0x41=‘A’ LDIr20, 0x30; ASCII offset for 0-9 ADDr22, r20; r22 is now 0x35=‘5’


Download ppt "CS-280 Dr. Mark L. Hornick 1 ASCII table. 2 Displaying Numbers as Text Problem: display numerical values as text Consider the numerical value 0x5A held."

Similar presentations


Ads by Google