title: CONVERT decimal to hexadecimal in assembly language NASM
body: <p>This is one of the hexadecimal part from my code, and i a little bit stuck in the hexadecimal part. when i key in 2560(decimal) and the output is :00(hexadecimal). it give me right value , but i need A in instead of : . Anyone can tell me where is my problem. i will appreciated with your help.thanks.</p>
  
  <p>DecToHex:</p>
  
  <pre><code>mov eax, msg8
  call sprint
  
  mov edx, 255
  mov ecx, sinput8
  mov ebx, 0
  mov eax, 3
  int 80h
  
  mov eax, sinput8
  
  call atoiToHex
  call iprintLFToHex
  ret
  </code></pre>
  
  <p>iprintToHex:</p>
  
  <pre><code>push    eax             
  push    ecx             
  push    edx           
  push    esi             
  
  mov     ecx, 0          
  </code></pre>
  
  <p>divideLoopToHex:</p>
  
  <pre><code>inc     ecx              
  mov     edx, 0         
  mov     esi, 16      
  idiv    esi            
  add     edx, 48         
  push    edx            
  cmp     eax, 0          
  jnz     divideLoopToHex 
  </code></pre>
  
  <p>printLoopToHex:</p>
  
  <pre><code>dec     ecx             
  mov     eax, esp        
  call    sprint          
  pop     eax             
  cmp     ecx, 0          
  jnz     printLoopToHex       
  
  pop     esi            
  pop     edx             
  pop     ecx             
  pop     eax             
  ret
  </code></pre>
  
  <p>iprintLFToHex:</p>
  
  <pre><code>call    iprintToHex     
  push    eax            
  mov     eax, 0Ah         
  mov     eax, esp        
  call    sprint          
  pop     eax            
  pop     eax             
  ret
  </code></pre>
  
  <p>atoiToHex:</p>
  
  <pre><code>push    ebx             
  push    ecx             
  push    edx             
  push    esi             
  mov     esi, eax        
  mov     eax, 0          
  mov     ecx, 0          
  </code></pre>
  
  <p>.multiplyLoopToHex:</p>
  
  <pre><code>xor     ebx, ebx        
  mov     bl, [esi+ecx]   
  cmp     bl, 48          
  jl      .finishedToHex  
  cmp     bl, 70          
  jg      .finishedToHex  
  cmp     bl, 10          
  je      .finishedToHex 
  cmp     bl, 0           
  jz      .finishedToHex  
  
  sub     bl, 48         
  add     eax, ebx        
  mov     ebx, 10         
  mul     ebx             
  inc     ecx             
  jmp     .multiplyLoop   
  </code></pre>
  
  <p>.finishedToHex:</p>
  
  <pre><code>mov     ebx, 10         
  div     ebx             
  pop     esi            
  pop     edx            
  pop     ecx             
  pop     ebx             
  ret
  </code></pre>