阅读使用INT 21H(DOS)及一些; 8086 assmebly [英] Reading a number using INT 21h (DOS) & 8086 assmebly
本文介绍了阅读使用INT 21H(DOS)及一些; 8086 assmebly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要提示用户味精,告诉他写一个数字,然后我保存这个数字,做它的一些操作
在INT 21H搜索后,我发现这一点:
I need to prompt to user a msg that tells him to write a number , then I store this number and do some operation on it After searching in INT 21h I found this :
INT 21h / AH=1 - read character from standard input, with echo, result is stored in AL.
if there is no character in the keyboard buffer, the function waits until any key is pressed.
example:
mov ah, 1
int 21h
的主要问题,这只能读取一个字符,再present它作为ASCII
所以如果我需要写数字357
我会读它为3,5,7
The main problem that this only reads one character and represent it as ASCII so If I need to write the number "357" I will read it as 3 , 5 , 7
和这不是我的目标。
任何想法?
and this is not my goal . any ideas ?
推荐答案
当设法让用户输入,把它的指针在ESI(ESI =地址字符串)
When you managed to get the user input, put the its pointer in ESI (ESI = address to the string)
.DATA
myNumber BYTE "12345",0 ;for test purpose I declare a string '12345'
Main Proc
xor ebx,ebx ;EBX = 0
mov esi,offset myNumber ;ESI points to '12345'
loopme:
lodsb ;load the first byte pointed by ESI in al
cmp al,'0' ;check if it's an ascii number [0-9]
jb noascii ;not ascii, exit
cmp al,'9' ;check the if it's an ascii number [0-9]
ja noascii ;not ascii, exit
sub al,30h ;ascii '0' = 30h, ascii '1' = 31h ...etc.
cbw ;byte to word
cwd ;word to dword
push eax
mov eax,ebx ;EBX will contain '12345' in hexadecimal
mov ecx,10
mul ecx ;AX=AX*10
mov ebx,eax
pop eax
add ebx,eax
jmp loopme ;continue until ESI points to a non-ascii [0-9] character
noascii:
ret ;EBX = 0x00003039 = 12345
Main EndP
这篇关于阅读使用INT 21H(DOS)及一些; 8086 assmebly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文