-3

I want to convert user's input character to digit(decimal) in Assembly MASM and Irvine library.

`CALL ReadChar ; store user input in AL register -> c ; user input character C

some code here to convert AL data to decimal 12

`

Jeff
  • 380
  • 7
  • 20

1 Answers1

1

read the char
subtract a '0' from it
if after that, it's larger than 9,
and it with 0xBF (to lowercase 'A'-'F' to 'a'-'f')
and subtract 7 again.
et voilá, there's your value

Tommylee2k
  • 2,683
  • 1
  • 9
  • 22
  • AND with `~0x20` upcases. the lower-case ASCII range has one extra bit set. `'r'` = `'R' + 0x20` = `'R' | 0x20`. (And yes this holds for all the alphabetic chars). BTW, the question asks for decimal, in which case you stop after the `sub al, '0'` step. – Peter Cordes Oct 05 '17 at 11:15