(16C) HEX2ASC/ASC2HEX Conversion Routines - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (16C) HEX2ASC/ASC2HEX Conversion Routines (/thread-12841.html) |
(16C) HEX2ASC/ASC2HEX Conversion Routines - mfleming - 04-21-2019 03:55 AM These two conversion routines were common in the early 80's when writing code in assembly language for the early 8-bit microprocessors. You might communicate via a serial port to peek and poke values in memory when debugging, so you needed a way to translate between an 8-bit value in memory and the ASCII representation of the value on the console. These two routines are complementary. HEX2ASC takes an 8-bit value in X and returns the low and high ASCII representation of the value in X and Y. ASC2HEX does the opposite, taking two ASCII characters in X and Y and returning an 8-bit value in X. The two routines are listed separately but were entered together as can be seen in the line numbering. Conditions: HEX mode, word size 8 bits Usage: HEX2ASC Input: X - 8 bit value Output: Y - ASCII character for upper nibble X - ASCII character for lower nibble Code: 001 LBL A | 43 22 A HEX2ASC Usage: ASC2HEX Input: Y - ASCII character for upper nibble X - ASCII character for lower nibble Output: X - 8 bit value Code: 029 LBL B | 43 22 B ASC2HEX Examples: 5Ch GSB A Y - 35h X - 43h x<>y GSB B X - C5h Edit: Word size must be 8 bits due to Rotate-Left (RLn) instruction. |