I am programming in Tasm and want to input a 32 bit number.
I know that i have to input it digit by digit (i hope there is no one call function for number input)
This is my code
. .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
i am stopping input at enter .
i am getting error NTVDM encountered a hard errror.
Thanks
This is my new modified code. It is working fine for some numbers like 2 and 123
but is failing for 333, 4444, 555; (i hope pushing and poping does not modify any registers other than specified):
.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
I am running this is MS-DOS CMD.exe window A pop up Error comes:

Assuming this is for DOS environment (due to
int 21h):There are some bugs in your code.
1.Read character function returns its output inal, that’s ok. But then you immediately destroy the value of read character with the following sequence:So you can’t store the character in
dlif you are going to domul ebx, becausemul reg32outputs the result inedx:eax. You could store it eg. inclorchinstead.2.Other bug which I notice is that you are attempting to multiply ASCII values by 10 (in the previous code). You should first subtract the value of ‘0’ of every read character before multiplication, that would besub al, 30horsub al, '0'.3.Third bug is in the following sequence:Edit: Here you are dividing
axbych, which obviously does not work right for 32-bit division. As it seems that you want to have your dividend ineax, clearedxwithxor edx, edx(as you do), and then divideedx:eaxwith a 32-bit register, eg.ebp,esioredi(those seem to be unused in your code so far), and you’ll get the quotient ineaxand the remainder inedx.