hextable db '0123456789ABCDEF' printi8: push cx push bx push ax sub cx, cx ; set counter = 0 .again: sub ah, ah ; ah = 0, ax is the dividend div bl push ax ; save remainder:quotient on the stack inc cx ; increment the digit counter cmp al, 0 ; if the quotient != 0 do the next digit jne .again ; loop while quotient > 0 .print: pop ax ; get digit from the stack mov al, ah ; convert digit to ascii mov ebx, hextable ; translation table xlatb ; replace al with hex digit from table mov ah, 0eH ; print digit in al int 10H loop .print ; using cx the digit counter to loop pop ax pop bx pop cx ret