开发者

Converting an ascii character into decimal in Assembly for use with WriteConsoleA and readConsoleA

开发者 https://www.devze.com 2023-03-01 04:19 出处:网络
I am in a fix. I need to input numbers from the user and then perform arithmetic calculations on the input. I\'m just a beginner now and till now I\'ve not used any IO, except in a program which asks

I am in a fix. I need to input numbers from the user and then perform arithmetic calculations on the input. I'm just a beginner now and till now I've not used any IO, except in a program which asks the user for a name and prints an output, using WriteConsoleA and ReadConsoleA. I couldn't find any help on google, on how to convert ascii characters to decimals for input and how to convert decimals to ascii for output. I'd prefer to do this manually before using any of the library function开发者_StackOverflow中文版s. I can't figure how to convert a single character into a string and vice versa. How is this done? And yeah, if you write code in the answers, if, possible, use masm syntax as i am not familiar with the other assemblers' syntax. Thanks!! Devjeet


If you have a decimal like 31h on al, you can just add 30h to each one to convert them to ASCII characters, like (AL = 31h):

mov cl,al
shr al, 4 // now al = 03
add al,30h // now al = 33h, which if you output is the ASCII character '3'

Now, you can restore al and shift left by 4 to get the next '1' and again add 30h. I hope this illustrates the point :)

0

精彩评论

暂无评论...
验证码 换一张
取 消