4

How can we make a .com file using C/C++? Is it possible?

Edit: I was able to successfully make a com file using darin's suggestions. But somehow the exe file of the following program cannot be converted to com file. I get the "File cannot be converted" message by exe2bin. I'm using Borland Turbo C++ 3.0. Any suggestions?

#include <dos.h>
void interrupt (*oldint65)( );
char st[80] = {"Hello World$"};
void interrupt newint65(void);
void main()
{
    oldint65 = getvect(0x65); 
    setvect(0x65, newint65);
    geninterrupt (0x65);
    geninterrupt (0x65);
    geninterrupt (0x65);
    setvect(0x65, oldint65);
}
void interrupt newint65( )
{
     _AH = 0x09;
     _DX=(unsigned int)st;
     geninterrupt (0x21);
}
1
  • Cause: The program to be converted has one of the following problems: * The program has an origin of 0100h but a different entry point. * The program requires segment fixups. * The program code and data are larger than 64 KB. * The program has more than one declared segment * The file is not a valid .EXE-format file. Commented Apr 20, 2009 at 19:04

3 Answers 3

17

In C, you must compile your program with the TINY memory model. Then you can use use EXE2BIN or a similar program to convert an EXE file to a COM file.

Sign up to request clarification or add additional context in comments.

Comments

3

That would depend on what you mean. Do you want to compile your program into a .com file? That would depend on your compiler, if it is possible at all.
If you are writing a compiler (or something like that), and want to produce a .com file from your own program, you should have a look at the COM article on Wikipedia, or use the NASM assembler to assemble to a .com file: nasm -o hello.com hello.asm.

Comments

1

Also, it's probably worth pointing out that you seem to be doing TSR programming, which is unlikely to work fully or even properly on non-DOS (i.e. modern) operating systems such as Windows XP/Vista.

You might want to consider running a DOS emulator such as bochs, which also makes it easier to run legacy development tools such as TC++

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.