问题描述
Iam学习程序集,我发现了如何获取用户输入的信息
Iam learning assembly and I found out how to get user input with
mov al, 3 ; system call number (sys_read)
xor bl, bl ; file descriptor 0 (stdin)
mov rcx, buf ; buffer to store input
mov dl, 4 ; Lenght of buffer
int 0x80 ; interrupt
但是实际上得到的是正确的字符串吗?我的问题是我如何获得整数值...所以,如果我输入100,我如何获得64h的值,这样我就可以加,减等而不是一个字符串,每个字节都是数字的ascii表示然后我如何在屏幕上输出一个像64h这样的值,使其显示为100?我不需要代码只是一些指导
but that actually gets a string right?my question is how do i get a integer value...so if i type 100 how do i get the value 64h so i can add, subtract etcinstead of a string with each byte being the ascii representation of the numberand then how do i output a value like 64h to the screen so that it shows 100?i dont need code just some guidance
谢谢!
推荐答案
一旦有了ASCII表示形式,就可以使用数字按顺序编码的事实,逐位建立结果.在伪代码中,从左到右读取(即从最高有效位开始):
Once you have the ASCII representation, you can just build up the result digit by digit, using the fact that the numerals are encoded in order. In pseudo-code, reading from left to right (i.e. starting with the most significant digit):
- 将
result
初始化为0 - 对于每个数字
c
,result *= 10; result += (c - '0');
-
result
保存字符串的数字值
- initialize
result
to 0 - for each digit
c
,result *= 10; result += (c - '0');
result
holds the numeric value of the string
这篇关于如何使用汇编获取整数输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!