Assemly Language Code To Convert From Character To Numeric Or Hex Value In 8086 Assembly Language
Read a numeric character from keybaord and convert into numeric integer or hex so that it can be used for further operations like additiona division or multiplication. this article will give students the basic knowledge read a single a single digit numeric character using Keyboard and convert it into Integer / Hex . Now once you know how to convert one character all you neeed to do is improve the logic and read longer characters.
Read Single Digit Numeric Character And Convert It To Numeric Or Hex
Some one today send me a piece of code which is used to add two numbers. Its a very simple program so it adds just two single digit numbers.
Interesting part of the code is it gives you an easy way to convert the number from character to numeric.
mov ah,1h ;read character
Now if I am entering a value = 5 ,
Its corresponding value from the below table is Hex 35H or Decimal 53D
Now the interesting part is that they subtract Hex value of character 0
30H or 48D
So ideally if you are subtracting the decimal values 53 - 48 = 5 or 35H - 30H = 5
5 which is the converted value in 8086 from Character to Numeric.
ASCII Table Reference
Assembly Language Code To Convert Single Digit Numeric Character To Integer
Sample Code .model tiny .code org 100h ; add your code here main proc near mov ah,1h ;Read Character From Console int 21h sub al,30h mov num1,al mov ah,4ch ; Terminate & Return Back To Dos Prompt mov al,00 int 21h endp num1 db ?; end main ret
Now Lets Debug The Output
We are not displaying anything . So I would like to teach you on how to debug in emu8086 and find out wether you have the right value 5 after you subtract in the AL Register .
STEP 1 : Read Numeric Character
STEP 2 : Convert To Number Or Integer Or Hex