>but why did u put 2 in the di regester
Here's how the division algorithm works:
123 / 10
AX = 12
DX = 3
12 / 10
AX = 1
DX = 2
1 / 10
AX = 0
DX = 1
Notice how DX, the value that is used to build the string, gives the digits in reverse order. By starting di at 2 and decrementing it, the algorithm builds the string in reverse order, thus negating the reverse order of the digits:
--0---1---2---3--
save: | | | |'$'|
-----------------
DX = '3'
DI = 2
--0---1---2---3--
save: | | |'3'|'$'|
-----------------
DX = '2'
DI = 1
--0---1---2---3--
save: | |'2'|'3'|'$'|
-----------------
DX = '1'
DI = 0
--0---1---2---3--
save: |'1'|'2'|'3'|'$'|
----------------- You can see what would happen if you just start at the beginning and go to the end by changing the corresponding portion of the code to this:
mov di,0
convert:
mov dx,0
div bx
add dx,'0'
mov [save+di],dl
inc di
test ax,ax
jnz convert