问题
I need to find an interrupt that can receive from a user a number with more than 1 digit. ;code
mov [0],0
mov si,0
lop:
mov ah,1
int 21h
cmp al,'q'
je finishedInput
xor ah,ah
add [word ptr si], ax
jmp lop
finishedInput:
I have already tried to do an end less loop that each time uses the
mov ah,1
int 21h
combination until the user press 'q' and the endless loop will stop and. However, I am almost convinced that I have seen a code that do the same thing with interrupt instead.
I want to stop using this block and use short interrupt that does the work better
回答1:
In most cases, it makes it a lot easier if input is taken in as a string and then converted to an integer. int 21h/ah=0ah
can read buffered input into a string pointed to at DS:DX
.
Once you have that, you can take that string and convert it to an integer. This sounds like a homework problem, so rather than give you code for it, here is a high level algorithm for converting a string of ASCII characters containing a number in base-10 into an actual integer (pseudocode):
accum = 0
i = 0
while(string[i] != '\r')
accum *= 10
accum += (string[i] - '0')
i++
Robust code would check for overflow and invalid characters as well. You're in luck here, since in ASCII the characters representing numbers ('0'...'9') are stored consecutively, and the x86 has a FLAGS register that you can check for overflow.
来源:https://stackoverflow.com/questions/54696513/how-to-input-from-user-number-more-than-one-digit-in-assembly