1 / 7

ASCII table

ASCII table. 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. How to do it?. Each hex digit represents 4 bits

inara
Download Presentation

ASCII table

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. How to do it? • Each hex digit represents 4 bits • Ex: Numeric value 0x5A in binary is 01011010. • 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? 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 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’ CS-280 Dr. Mark L. Hornick

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

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

More Related