转换成ASCII字符成十进制在大会为使用WriteConsoleA和readConsoleA [英] Converting an ascii character into decimal in Assembly for use with WriteConsoleA and readConsoleA

查看:134
本文介绍了转换成ASCII字符成十进制在大会为使用WriteConsoleA和readConsoleA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进退两难。我需要来自用户的输入数字,然后对输入进行算术运算。我现在只是一个初学者,现在为止我没有用任何IO,除了它要求用户输入一个名称和打印输出,使用WriteConsoleA和ReadConsoleA程序。我找不到对谷歌的帮助,就如何ASCII字符转换为小数输入,以及如何以小数为ASCII码输出转换。我想preFER做到这一点使用任何的库函数之前手动。我想不出如何将单个字符转换为字符串,反之亦然。如何做到这一点?
,是的,如果你写code的答案,如果可能的话,使用MASM语法,我不熟悉其他的汇编'语法。
谢谢!!
Devjeet

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 functions. 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

推荐答案

如果你有这样的人31H小数,你可以再补充30H到每一个将它们转换为ASCII字符,如(AL = 31H):

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'

现在,你可以恢复人与移位4左边得到下一个'1',然后再添加30小时。我希望这说明了这一点:)

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 :)

这篇关于转换成ASCII字符成十进制在大会为使用WriteConsoleA和readConsoleA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆