【发布时间】:2012-08-24 05:05:53
【问题描述】:
我在 Tasm 中编程,想输入一个 32 位数字。
我知道我必须逐位输入(我希望没有一个号码输入的呼叫功能)
这是我的代码
. .486
.model small
.code
start:
mov ebx, 0
; enter again and again untill enter is hit
again:
mov ah,01h
int 21h
cmp al, 13
jz next
mov dl, al
mov eax, ebx
mov ebx, 10
mul ebx
mov ebx, eax
mov eax, 0
mov al, dl
add ebx, eax
jmp again
; now find the digits back
next:
; just testing to see if i got number
mov edx, 13
mov ah, 02h
int 21h
mov edx, 10
mov ah,02h
int 21h
mov edx, ebx
mov ah, 02h
int 21h
mov eax, ebx
mov ebx, eax
xor edx, edx
xor cl, cl
; find digits and push into stack from last to first so when i pop i get digits back
finddigit:
xor edx,edx
mov ch , 10
div ch
push dx ;taking risk dx dl
inc cl
cmp eax, 0
jz print
jmp finddigit
; stored into cl the number of digits
print:
cmp cl,0
jz exit
dec cl
pop dx
mov ah,02h
int 21h
jmp print
exit:
end start
我正在停止输入。
我收到错误 NTVDM 遇到一个硬错误。
谢谢
这是我修改后的新代码。它适用于 2 和 123 等数字 但 333、4444、555 失败; (我希望 push 和 poping 不会修改指定以外的任何寄存器):
.486
.model small
.code
start:
mov ebx, 0
; enter again and again untill enter is hit
again:
mov ah,01h
int 21h
cmp al, 13
jz next
mov cl, al
sub cl, 30h
mov eax, ebx
mov ebx, 10
mul ebx
mov ebx, eax
mov eax, 0
mov al, cl
add ebx, eax
jmp again
; now find the digits back
next:
; just testing to see if i got number
mov edx, 13
mov ah, 02h
int 21h
mov edx, 10
mov ah,02h
int 21h
mov eax, ebx
mov ebx, eax
xor ecx, ecx
mov ebx, ebp
; find digits and push into stack from last to first so when i pop i get digits back
finddigit:
xor edx,edx
mov ebp , 10
div ebp
push edx
inc cl
cmp eax, 0
jz print
jmp finddigit
; stored into cl the number of digits
print:
cmp cl,0
jz exit
dec cl
xor edx,edx
pop edx
add dl,30h
mov ah,02h
int 21h
jmp print
exit:
mov ah,4ch
int 21h
end start
我在运行这个是MS-DOS CMD.exe窗口弹出错误来:
【问题讨论】:
标签: assembly input x86 dos digit