5

I want to compile a "Hello World" MS-DOS exe.

Not a program that runs in XP 16bit mode, or in MS-DOS mode on top of Windows OSs.

A HELOWRLD.EXE that I can run on my MS-DOS box.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
divinci
  • 22,329
  • 11
  • 45
  • 56
  • 3
    In what (programming) language? – wqw Apr 15 '10 at 12:11
  • 4
    echo Hello World (that will write what u need), perhaps you need something more specific, tell us – Hernán Eche Apr 15 '10 at 12:15
  • 1
    Here are examples in many languages (OS listed next to them). As others have pointed out - most likely you are going to use C, C++, Assembly, or even dos batch. http://www.ntecs.de/old-hp/uu9r/lang/html/lang.en.html – ktharsis Apr 15 '10 at 12:19
  • 2
    An MS-DOS exe does run in 16 bit mode, unless one of the various 32 bit extenders are used. – kmarsh Apr 15 '10 at 12:38

8 Answers8

30

I think DEBUG.EXE still ships with windows (at least it does with XP). Run debug and enter something along the lines of the following transcript:

c:\src> debug
-a 100
1373:0100 mov ah,9
1373:0102 mov dx,108
1373:0105 int 21
1373:0107 ret
1373:0108 db "Hello world!$"
1373:0115
-n c:\hi.com
-r bx
BX 0000
:0
-r cx
CX 0000
:15
-w
Writing 00015 bytes
-q

c:\src> c:\hi.com
Hello world!

c:\src> _

Read more on DEBUG.EXE at: http://en.wikipedia.org/wiki/Debug_(command)

And the INT 21 display string http at: http://www.uv.tietgen.dk/staff/mlha/PC/Prog/asm/int/21/09.htm

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
Niels Castle
  • 8,039
  • 35
  • 56
9

Follow these steps:

  1. Get and install Turbo C 2.0 from here, legally.
  2. Copy this code (*)
  3. Compile it.
  4. Your hello.exe is ready to run.

This is code you should copy (*):

int main(int argc, char **argv)
{
   printf("Hello, world.\n");
   return 0;
}
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 2
    There's also DJGPP, which is real free software and not just abandonware: http://www.delorie.com/djgpp/ – Joachim Sauer Apr 15 '10 at 12:17
  • Totally agree with both of you. I just happen to love old Borland compilers. They were AWESOME! – Pablo Santa Cruz Apr 15 '10 at 12:27
  • 1
    Can I suggest you get the Borland compilers from the Borland mesum itself? Abandonware is _not_ a legal concept and the code is still copyright by Borland/Inprise/Enchilada or whatever they call themselves this week. See http://edn.embarcadero.com/museum – paxdiablo Apr 15 '10 at 12:27
  • 1
    @paxdiablo: you're right that abandonware is not legal. But if it's **correctly** declared as abandonware, then that means that you *can no longer buy the software from the owner*. So your only chance is to buy it used from someone who owns it (unless it's not really abandonware). – Joachim Sauer Apr 15 '10 at 12:35
  • 2
    No, you can download it legally from Embarcadero, the current copyright owners (see the link I gave). And even if it wasn't obtainable from anywhere, that doesn't make it legal. The site given in the answer doesn't look like you're buying a legal used copy so much as downloading a file you have no right to - why do that when you can do it legally? – paxdiablo Apr 15 '10 at 12:46
  • 2
    No problems, Pablo, but it'll _always_ be the Borland museum to we who care :-) – paxdiablo Apr 15 '10 at 12:54
4

DJGPP is a complete 32-bit C/C++ development system for Intel 80386 (and higher) PCs running DOS. It includes ports of many GNU development utilities. The development tools require a 80386 or newer computer to run, as do the programs they produce. In most cases, the programs it produces can be sold commercially without license or royalties.

http://www.delorie.com/djgpp/

Simone Margaritelli
  • 4,584
  • 10
  • 45
  • 70
2

For C and C++ development, use one of these free and open source compilers:

  • DJGPP - a DOS port of GCC. It builds 32-bit protected mode DOS applications.
  • Open Watcom - I'm not as familiar with this one, but it's actively developed and can target 16- and 32-bit DOS, Windows, and OS/2.
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
2

This will do it straight in the command line debugger in DOS. http://www2.latech.edu/~acm/helloworld/dosdebug.html

It does write a COM file and not an EXE (there is a difference) but should be a good start for you.

ktharsis
  • 3,160
  • 1
  • 19
  • 30
0

You want a MS-DOS C compiler. Is there still an old version of Borland C floating around? Also, you might find a port of the GNU C compiler for DOS.

Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
0

Install Turbo C/C++ 16-bit compiler. Then create new noname00.c file.
Write this code in it.

//Include necessary files stdio.h and conio.h for function prototypes.
//The "int agrc , char *argv[]" are optional parameters to main program.If you don't want to use //it you can just write "int main()"
int main(int argc,char *argv[])  
{  
     printf("Hello World !!!!");  
     getch();  
     return 0;  
}

the .exe file generated by this compiler can be found in source directory.
Try to run it in your own MS-DOS Box.
It should run.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Parth Desai
  • 1,671
  • 13
  • 15
0

For Pascal you will want Free Pascal. It generates 32-bit Go32v2 binaries like DJGPP, and can compile old TP code.

Work is also being done on a Windows->16-bit Dos compiler (can generate .COM), but while working, that is not in a released branch yet.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89