How to create a .com file using C / C ++?

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

Edit: I was able to successfully create a com file using darin suggestions. But somehow the exe file of the next program cannot be converted to a com file. I get the message "File cannot be converted" exe2bin. I am 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);
}
+3
source share
3 answers

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

+16
source

, . a .com? , .
( - ) .com , COM- NASM .com : nasm -o hello.com hello.asm.

+3

, , , , , TSR, -DOS ( ) , Windows XP/Vista.

, DOS, bochs, , T++

+1

Source: https://habr.com/ru/post/1706640/


All Articles