0

Can anyone one explain me , how does this procedure works ??

disp32_proc:

    mov esi,char_count+7    ; load last byte address of char_count buffer in rsi
    mov ecx,8               ; number of digits

    cnt: 
    mov edx,0               ; make rdx=0 (as in div instruction rdx:rax/rbx)
    mov ebx,16              ; divisor=16 for hex
    div ebx
    cmp dl, 09h             ; check for remainder in RDX
    jbe add30
    add dl, 07h

    add30: 
    add dl,30h              ; calculate ASCII code 
    mov [esi],dl            ; store it in buffer 
    dec esi                 ; point to one byte back
    dec ecx                 ; decrement count 
    jnz cnt                 ; if not zero repeat

    print char_count,8      ; display result on screen 

ret
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
  • Please indent your code by 4-spaces to have it format correctly `:)` What part are you stuck on? It seems to be parsing 8 hex digits from `char_count`. – David C. Rankin Mar 10 '18 at 05:48
  • It's an implementation of [this algorithm](https://stackoverflow.com/questions/13166064/how-do-i-print-an-integer-in-assembly-level-programming-without-printf-from-the/46301894#46301894), inefficiently written to use `div` even though the divisor is a power of 2. See that link for a full description of how repeated division gives you the digits in order from last to first, thus `dec esi` to store them in reverse order in a buffer. – Peter Cordes Mar 10 '18 at 05:56

0 Answers0