'DOSBox freezes on procedure which prints on screen the integer number from register AX, character by character
I wrote the procedure PRINTNR which divides sequentially the number in AX by 10, saves the rest on the stack. After the number in AX register becomes 0, I sequentially extract the digits from the stack, and add 30h in order to obtain the ascii code of the respective digit. Then I call the 02h function with INT 21h. When I assemble it, it freezes my DosBox.
CODE SEGMENT PARA 'CODE'
ASSUME CS: CODE
MAINPROC PROC FAR
PUSH DS
XOR AX, AX
PUSH AX
MOV AX, 5
CALL PRINTNR
RET
MAINPROC ENDP
PRINTNR PROC NEAR
;IN AX WE HAVE THE NUMBER
MOV CX, 0
MOV BX, 10
AGAIN:
INC CX
DIV BX
PUSH DX
MOV DX, 0
CMP AX, 0
JNE AGAIN
LOOPPRINT:
POP DX
ADD DL, 30h
MOV AH, 02h
INT 21h
LOOP LOOPPRINT
RET
PRINTNR ENDP
CODE ENDS
END MAINPROC
Can you find out what's the problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
