title: NASM convert Binary number to Decimal
body: <pre><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 cont
      mov edx,0   
      div esi
      cmp edx,1
      ja error
      jmp next
  
  error:      
      mov eax,msg2
      call print_string
      call print_nl
      jmp input
  
  
  cont: mov eax,ecx
  
  convert:
      cmp eax,0
      je sof
      mov edx,0
      div esi
      cmp edx,0
      je shift_1
      or ebx,[mask]
  
  shift_1:    
      shl dword[mask],1
      jmp convert
  
  sof:    
      mov eax,msg3
      call print_string
      mov eax,ebx
      call print_int
      call print_nl
  
      popa 
      leave 
      ret
  </code></pre>
  
  <hr>
  
  <p>The program gets only 1 and 0 and prints its decimal value.
  It does not work on more than 10 bits number (i need it to be working on 32 bits number), also it does not work with number that starts with 0 (like 011)
  Help pls :)</p>