We had an activity about looping in assembly language. Our task is simple: display the numbers 0 to 9 with spaces in-between each number. I got the code to work in the command prompt using the 'debug' command in WINDOWS 7 in our school. My laptop is Windows 10 and I recently found out that there's no 'debug' command in the command prompt. So I tried writing my code in DOSBox 0.74 (latest, maybe). Every time i run it in DOSBox, the programs suddenly hangs up and then crashes. Here's the code
mov cx,0a
mov ah,02
mov dl,30
int 21
mov bl,dl
mov dl,20
int 21
mov dl,bl
inc dl
loop 0107
int 20
Can someone please explain me why DOSBox crashes?
Here is a sample pic of the working program which runs in cmd on Windows 7:
Although your question isn't a duplicate of this other Stackoverflow question it seems to share certain similarities. Namely unexpected hangs or unusual behaviour. It would seem that DEBUG.EXE
versions available for MS-DOS do not always function properly when run in DOSBox. This may be because DOSBox may not be 100% compatible emulating a real PC/Hardware(and DOS). This could result in some programs and/or OSes to not work as expected when used in DOSBox.
I have amended my previous Stackoverflow answer to suggest a variety of MS-DOS DEBUG.EXE
programs may not work properly when run under DOSBox. Ross Ridge confirms he can duplicate your problem with DOS 6.22's debugger when run inside DOSBox.
There is a version of DEBUG.COM
that was released by FreeDOS that seems to play well with DOSBox. I have made the FreeDOS version of DEBUG.COM available for download from my website. Alternatively you can download the ZIP File from Softpedia and extract DEBUG.COM
.
AX
is a volatile register for DOS-interrupt int 21h
. So the content of AH=02h
will be overwritten by INT 21h
calls. The only source I could find to reference to is a document about Interrupt Services from the Mississippi State University which states on page one:
BIOS (and most DOS) ISRs Preserve Register Contents – Except ax
So in your code
int 21 ; alters AX
mov dl,bl ; AH is undefined
inc dl ; DL is increased correctly
loop 0107
you falsely assume that AH
would still contain the value of 02h
. This is not (necessarily) the case.
So add a MOV AH, 02h
before the loop statement and your program should execute less erroneous, because your INT 21h
located at 0107
then would call the correct DOS-function 02h
.