Here i have a assembly code that converts word value to string
; si -> Offset Address of String
; ax -> Number to be converted
itoa:
push ax ; Backup AX To Stack
push bx ; Backup BX To Stack
push dx ; Backup DX To Stack
push si ; Backup SI To Stack
mov bx,10 ; Set BX to 10 for Dividing the AX by 10
.loop:
div bx ; Divide AX With BX For Getting The Digit And Removing First Digit Of Number
add dl,48 ; Add 48 to DL to Convert Digit to Ascii
mov [cs:si],dl ; Write digit to string
xor dl,dl ; Set DX to 0
inc si ; Increase SI
cmp ax,0 ; Compare AX with 0
jne .loop ; If ax not equals 0 then jump back to start of loop
pop si ; Get Backup Value of SI From Stack
pop dx ; Get Backup Value of DX From Stack
pop bx ; Get Backup Value of BX From Stack
pop ax ; Get Backup Value of AX From Stack
ret ; Return from Subroutine
When i run this code, it outputs reverse of number that given in AX, which is problem for me. How can i solve this ?