(16C) HEX2ASC/ASC2HEX Conversion Routines
|
04-21-2019, 03:55 AM
(This post was last modified: 04-21-2019 05:38 PM by mfleming.)
Post: #1
|
|||
|
|||
(16C) HEX2ASC/ASC2HEX Conversion Routines
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. Remember kids, "In a democracy, you get the government you deserve." |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)