我正在 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
我在 enter 停止输入。
我收到错误 NTVDM 遇到了一个硬错误。
谢谢
这是我新修改的代码。它对 2 和 123 等数字运行良好,但对 333、4444、555 则失败;(我希望推送和弹出不会修改指定以外的任何寄存器):
.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 窗口 弹出错误来了: