我在Tasm中編程,想要輸入一個32位的數字。如何在程序集中輸入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失敗; (我希望推動和空間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窗口彈出錯誤談到:
在你的「exit:」標籤處還需要一個「退出」(mov ah,4Ch/int 21h)。這可能是NTDVM所抱怨的。 –
@nrz我已經更新了這個問題。新代碼粘貼。它對一些輸入工作正常,但對其他輸入失敗。 –
如果我使用ebp,我必須在使用它之前存儲它,並在工作後將其替換。 –