Hello, I need help with my code.
The user enters a binary number (1 and 0 only) the output is the decimal value of the input.
if the user enters a digit between 2-9 it goes to error label.
Here is the problems:
When I enter more than 10 digits it goes to error label. I need to enter 32 digits.
Also when I enter a number starting with zero (like 011) it goes to error label.
---------------------------------------------------------------------------------------------------------------
here is the code:
%include "asm_io.inc"
segment .data
msg1 db "Enter a number: ",0
msg2 db "Bad Number! try again. ",0
msg3 db "Enter Decimal value is: ",0
segment .bss
mask resd 1
segment .text
global main
main:
enter 0,0
pusha
mov dword[mask],1
mov esi,10
mov ebx,0
input:
mov eax,msg1
call print_string
call read_int
mov ecx,eax
next:
cmp eax,0
je continue
mov edx,0
div esi
cmp edx,1
ja error
jmp next
error:
mov eax,msg2
call print_string
call print_nl
jmp input
continue: mov eax,ecx
convert:
cmp eax,0
je print
mov edx,0
div esi
cmp edx,0
je shift_1
or ebx,[mask]
shift_1:
shl dword[mask],1
jmp convert
print:
mov eax,msg3
call print_string
mov eax,ebx
call print_int
call print_nl
popa
leave
ret