Practical ASCII Layout

As we all know, numeric is not printable directly. They must be tranlated to ASCII one by one, and then print to screen. numeric 0 is 30h in ASCII character, 1 is 31h ... and 9 is 39h. You may want to

add    al, 30h         ; Not good

   Yes, they work! But not the best. Think this case: if you don't know whether or not it is a numeric value or ASCII value, how will you do? Try the follow:

or    al, 00110000b    ; Integer to ASCII

   And the reverse operation is:

and    al, 00001111b    ; ASCII to integer

  

Now, let's see how to exchange upper case and lower case character.

ASCII code for an uppercase letter and the ASCII code for the corresponding lowercase letter differ only in the value of bit 5 (80x86 Assembly Language and Computer Architecture. p.274). So we can:

or     al, 00100000b    ; To lower case.

and al, 11011111b ; To upper case.

xor al, 00100000b ; Upper to lower while lower to upper.

  When you use statement above, you will never need to take special care of numeric characters among alpha characters. How wonderful and practical ASCII table it is!

  

posted @ 2011-08-30 16:34  walfud  阅读(211)  评论(1编辑  收藏  举报