user2581242
user2581242

Reputation: 23

Basic assembly code crashes DOS emulator

I am a very new assembly coder and most of it is still foreign to me. My code is as follows

0100: mov ah, 09
0102: mov dx, 010A
0105: int 21h
0107: int 20h
010A: db "Hello World!$"

Running this code in my DOS emulator (DosBox) causes the emulator window to produce the "Hello World !" message and continue to freeze and eventually give the "program is not responding" error.

Upvotes: 2

Views: 467

Answers (1)

Aida Paul
Aida Paul

Reputation: 2722

It freezes because you didn't properly quit your application. Try that instead:

mov ah, 4C00h; 
int 21;

which should do the trick. As to explanation of what is going on here, we have to grab a reference for INT 20 and INT 21. As you can see they are both intended to terminate the application, but INT 20 is the legacy way to do it and was later replaced with 21,4c. The main difference between the two is that INT 20 just terminates the process, while INT 21,4C also returns appropriate return code (which is expected by all modern applications).

As of the construct itself, by moving "4C00h" (you should be able to get away with just "4Ch") to registry AH , we tell INT 21 which function we are interested in. Because unlike INT 20, which has only one purpose, INT 21 has a long list of them, and by setting appropriate values in registries, INT 21 knows what is expected of it.

Upvotes: 1

Related Questions