How does the Div10 algorithm Div10 in this program? The mathematical meaning of all these exchanges with xchg .
; DWToAscii преобразует 4-байтовое число в последовательность символов DWToAscii proc near call Div10 mov si, dx or si, ax jz done ; Записать первую цифру push bx call DWToAscii pop bx ; Достать очередную цифру done: add bl, '0' ; Перевести цифру в символ mov [di], bl ; Сохранить символ inc di ret DWToAscii endp Div10 proc near mov cx, 10 mov bx, ax xchg ax, dx xor dx, dx div cx xchg dx, bx ret Div10 endp We divide the four-byte number in dx:ax by 10. In the second line, save the low-order bits in bx , instead of the low-order bits, load the high-order bits, while at the same time saving them in dx (this is not clear: why save them if we have already saved them?). Reset the high bits. We divide by 10 the number 0:ax , where the ax now the high-order bits. Now in ax - the quotient, and in dx - the remainder, and we replace the remainder with the lower bits of the number. We somehow broke the number, but for some reason it did not affect the result. This is surprising, because the decomposition of a number by the base of a number system does not allow it to be used in any part of it.
Function call:
start: mov dx, 12345 ; Старшие биты mov ax, 6789 ; Младшие биты mov cx, 10 mov di, offset digit call DWToAscii mov [di], byte ptr 0Dh inc di mov [di], byte ptr 0Ah inc di mov [di], byte ptr '$' mov dx, offset digit mov ah, 9h int 21h mov ah, 4ch int 21h 

