[英]hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord
I am making a program in which I want to take up to a 10 digit number我正在制作一个程序,我想在其中使用最多 10 位数字
(4,294,967,296) digit by digit from user and store all of the digits and make (4,294,967,296) 逐位来自用户并存储所有数字并制作
one number of them in EAX. EAX 中的其中一个。
for example: input = 1 2 3 4, EAX = 1234例如:输入 = 1 2 3 4,EAX = 1234
i tried with 2 digits for the start and i got some problems and i dont know how我试着用 2 位数字开始,但我遇到了一些问题,我不知道怎么做
to continue from here.从这里继续。 I would really appreciate your help, thanks in advance!!非常感谢您的帮助,在此先感谢!!
.model small
.STACK 100h
.data
num dd ?
ten DB 10
.code
.386
start:
MOV AX, @DATA
MOV DS, AX
MOV AH,1
INT 21H
SUB AL,30H
MOV BH,AL
MOV AH,1
INT 21H
SUB AL,30H
MOV CH,AL
MOV AL,BL
MUL ten
ADD AL,CH
push eax
call printNum
MOV AX, 4c00h
INT 21h
END start
MOV AL,BL MUL ten ADD AL,CH
The above would produce the value of your 2-digit number if you would have used the correct register.如果您使用了正确的寄存器,以上将产生您的 2 位数字的值。 You have stored the first digit in BH
, but you're using BL
here!您已将第一个数字存储在BH
中,但您在这里使用的是BL
!
.386 push eax
You are in emu8086.你在emu8086。 Forget about using 32-bit registers.忘记使用 32 位寄存器。 If you want to work with 32-bit numbers, you'll have to store them in a couple of 16-bit registers.如果要使用 32 位数字,则必须将它们存储在几个 16 位寄存器中。 eg DX:AX
where DX
holds the Most Significand Word and AX
holds the Least Significand Word.例如DX:AX
,其中DX
保存最高有效位字, AX
保存最低有效位字。
To solve your task of building a 10 digit number up to 4GB-1, next codez will be useful:为了解决您构建高达 4GB-1 的 10 位数字的任务,下一个 codez 将很有用:
DI:SI
by 10将DI:SI
中的 dword 乘以 10mov ax, 10
mul si ; LSW * 10 -> DX:AX
mov si, ax
xchg di, dx
mov ax, 10
mul dx ; MSW * 10 -> DX:AX
jc Overflow
add di, ax
jc Overflow
AL=[0,9]
to the dword in DI:SI
将新数字AL=[0,9]
添加到DI:SI
中的 dwordmov ah, ah
add si, ax
adc di, 0
jc Overflow
Input:
mov ah, 01h ; DOS.GetKeyWithEcho
int 21h ; -> AL
cmp al, 13 ; Is it <ENTER> ?
je Done
sub al, '0' ; From character to digit
cmp al, 9
ja Invalid
...
jmp Input
Done:
It's important that you decide how you will handle an invalid user input and what you will do for an input that yields a number bigger than 4GB-1.决定如何处理无效的用户输入以及如何处理产生大于 4GB-1 的数字的输入非常重要。 Many programs have been written that overlook this and then at some point mysteriously fail...许多程序都忽略了这一点,然后在某些时候神秘地失败了......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.