Instructables

How to write the world's smallest "Hello World!" executable for PC

Step 6: Still not happy with the result?

Still want more that just a Hello World?

Well, ok, i'll show you some usefull stuff, but only recommended for experienced PC users with a little knoledge of CPUs :)
From now on, try to SAVE BEFORE EXECUTE, because if the code go bad for some unknown reason, you will loose everything in memory if you didnt saved first.

to load a file, use "debug.exe (filename)", also you wont need the "n" command.

This extra code will make the app to wait for the user to press a key:
MOV AH, 00 ; "Function 00h - get character from keyboard" of Interrupt 16h
INT 16 ; Interrupt 16h

The "Hello World!" text with new-line at the end (0x24 is "$" if you forgot):
DB "Hello World!",0D,0A,24

Multi-line text:
DB "First Line!!",0D,0A
DB "Second Line!!",0D,0A,24

Correct way to terminate current application in DOS:
MOV AH, 4C ; Function 4Ch - "EXIT" - TERMINATE WITH RETURN CODE
MOV AL, 00 ; Errorlevel 0
INT 21 ; Interrupt 21h - DOS Interrupt

You can jump to other locations in the code with JMP opcode:
JMP 0180 ; Jump to ????:0180

You can read a key press and jump to another location of the program if the key match (DON'T WORK VERY WELL WHEN EXECUTED INSIDE DEBUG.EXE, IT MAY CRASH).
MOV AH, 08 ; function 08h - CHARACTER INPUT WITHOUT ECHO
INT 21 ; Call DOS Intrerrupt, AL register will have the key that the user pressed.
CMP AL, 31 ; Compare AL with 0x31 (0x31 = Character '1')
JZ 0180 ; Jump to 0180 if AL equal to 31
JNZ 0200 ; Jump to 0200 if AL not equal to 31

If you want to go serious with x86 assembly, I'll recommend:
NASM, best for 16-Bits DOS: http://www.nasm.us/
MASM32, best for 32-Bits WIN: http://www.masm32.com/
The best is, they are both free and much nicer than DEBUG.EXE for managing asm code!

Thanks for reading my instructable and have fun! :)
 
Remove these adsRemove these ads by Signing Up