title: convert binary to hex in assembly 80x86
body: <p>I'm looking for a program that coverts a String of 1's and 0's to hexadecimal  string in assembly, where the binary string comes from a code that I write in 'C'.<br>
   for example: </p>
  
  <pre><code>10111111100-&gt; "5 F C"
  </code></pre>
  
  <p>The problem is that for more than 12 chars input , the output is wrong , and my mission demands at most 32 chars.</p>
  
  <p>for example given 110010101111-> "CAF"  it works ok!
  but giving 10010001101000101011001111000 should be "12345678"
  but i only get "123"
  debugging with gdb tool i see that the values are being override . how to take care of this with minimal changes in the code? Thanks</p>
  
  <p>The idea is to transform the string pointed by ecx to a value in eax.
  now i want to take the 4 most right each time and convert them , and them put them in edx .</p>
  
  <p>So far, I have:</p>
  
  <pre><code>section .rodata
  LC0:
    DB    "The result is:  %s", 10, 0 ; Format string
  
  section .bss
  
  LC1:
    RESB  32
  
  section .text
    align 16
  
    global my_func
    extern printf
  
  my_func:
    push  ebp
    mov   ebp, esp            ; Entry code - set up ebp and esp
    pusha                   ; Save registers
    mov ecx, dword [ebp+8]    ; Get argument (pointer to string)
    mov ebx, 0              ; counter for length
    mov eax, 0              ; will hold the string as a value
    mov edx, 0              ; manipulation helper
    mov edi, 0              ; counter for ehile_length loop
  
  length:
    inc ebx
    cmp byte [ecx+ebx], 0x00
    jne length
    dec ebx
  
  ;;;;THIS PART IS PARSING THE STRING INTO A REGISTER;;;
  
  bring_ecx_to_end:
    inc ecx
    cmp byte [ecx], 0x0
    JNE bring_ecx_to_end
      dec ecx
      dec ecx
      or edi ,ebx
      add esi,1
  
  while_length:
    mov  dl,byte [ecx]      ; gets 1 char into edx
    cmp DL, 0x31            ; the right character
    JE inc1                 ; if it  a '1'    
  
  resume_loop:
    shl esi,1 ; multiply by 2
    dec ecx
    sub edi,1
    cmp edi,0
    jne while_length
  
  ;;;;;;;;;;NOW EAX CONSISTS THE STRING ;;;;;;;;;;;;;;
  
  mov dword edx,0 ;target register
  
  
      while:
          mov dword edi ,0
          add edi ,15 ; masking
  
          and edi,eax
          cmp di , 10
           jl less_than_10
  
        ;less_than_F
            add di ,55    
            jmp resume
  
      less_than_10:
       add di ,48
  
   resume:    
       or edx,edi
       shl edx,8
       shr eax,4
       cmp al ,0
        jne while
  
        shr edx , 8
  
  ;;;;;;;;;DONE;;;;;;;;;;;;;
  
  end:
    mov dword [LC1],edx
  
    push LC1                ; Call printf with 2 arguments: pointer to str
    push LC0                ; and pointer to format string.
    call printf
    add esp, 8              ; Clean up stack after call
  
    popa                    ; Restore registers
    mov   esp, ebp            ; Function exit code
    pop   ebp
    ret
  
  inc1:   
    or eax, esi
    jmp resume_loop
  </code></pre>