LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2011, 06:08 PM   #1
Zssfssz
Member
 
Registered: Sep 2011
Location: Las Vegas!
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339

Rep: Reputation: Disabled
C++ make a .com


How would I make a .com in c++, not the domain the old dos executable, I have open watcom and can make the compiler wise but what code should I use? Normal code brings up a ton of errors...
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-14-2011, 02:15 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
You have a C++ compiler that generates 16 bit x86 machine code? (Sorry I don't know what watcom is).

If you have compiled into 16 bit .obj files, it shouldn't be too hard to link the result into a .com as long as the whole program is small enough (including all the 16 bit C++ startup code and C++ library code).
 
Old 12-14-2011, 03:17 PM   #3
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by Zssfssz View Post
How would I make a .com in c++, not the domain the old dos executable, I have open watcom and can make the compiler wise but what code should I use? Normal code brings up a ton of errors...
The COM file format used in historical DOS versions is taylored to applications that run on as little as 64kB of memory. Actually, the file format was developed for CP/M and slightly adapted for the first DOS incarnation. A DOS application using the old COM file format is restricted to 64kB (actually it's 64kB minus 256 bytes, since the 64k segment begins with the PSP and code starts at 0100h) for code, data and stack together.

In the end, I suppose you don't want to build an old style COM executable. Instead, you want to compile and run your program. So let's face the "ton of errors" you get and think about their reason - and how to get rid of them.

If you still insist on building a 64k DOS executable: Choose the "tiny" memory model, compile your program to a standard DOS EXE file, and convert it to the COM format using the DOS tool exe2bin. Though I still wonder why someone would want to build a DOS application nowadays, instead of a Windows console application ...

[X] Doc CPU

Last edited by Doc CPU; 12-14-2011 at 03:39 PM. Reason: Digits were swapped: It's 256 bytes, not 265
 
2 members found this post helpful.
Old 12-14-2011, 03:31 PM   #4
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Doc CPU View Post
Though I still wonder why someone would want to build a DOS application nowadays, instead of a Windows console application ...
There's a trick that allows packing executables into something as small as 4kB. The trick involves *.COM file format - apparently it is possible to compress *.exe into simple compressed format, attach it to *.COM unpacker (*.com has no overhead, unlike PE *.exe that has minimal size of roughly 8kB) - and make unpacker decompress and launch the program. Apparently it is possible because real-mode *.com executable can launch protected mode windows executable. It's been a while since I heard about this trick and I no longer can find relevant articles (there was an entire tutorial with asm listings), but if you search for "4kb demo" or "4kb demoscene", I'm sure you'll find something on the subject. Also, I don't think they will work on windows 7 - only on XP.
 
Old 12-14-2011, 03:40 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by SigTerm View Post
It's been a while since I heard about this trick and I no longer can find relevant articles (there was an entire tutorial with asm listings), but if you search for "4kb demo" or "4kb demoscene", I'm sure you'll find something on the subject. Also, I don't think they will work on windows 7 - only on XP.
So far as I recall, I haven't seen that used since Windows 95. Does it really work on XP (which was derived from Windows NT, not from 95)?

It shouldn't be possible on any 64 bit Windows (even for 32 bit applications) even 64bit XP. Since I don't know why it would work even in 32bit XP, I'm not qualified to guess why it might or might not work in 32 bit Windows 7.
 
Old 12-14-2011, 03:49 PM   #6
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by SigTerm View Post
There's a trick that allows packing executables into something as small as 4kB. The trick involves *.COM file format - apparently it is possible to compress *.exe into simple compressed format, attach it to *.COM unpacker (*.com has no overhead, unlike PE *.exe that has minimal size of roughly 8kB) - and make unpacker decompress and launch the program. Apparently it is possible because real-mode *.com executable can launch protected mode windows executable.
yea, sure you can append a compressed PE file to a COM decompressor stub, and I guess that might even work with recent Windows versions. But what's the point? Disk space is cheap, at least when we're talking about saving a few kB. It hardly matters whether I have a 100kB EXE file on my disk, or a 60kB COM file including the compressed payload.
Besides, what's the significance of those 4kB you mention? That's probably the size of the decompressor stub, is it?

Quote:
Originally Posted by SigTerm View Post
Also, I don't think they will work on windows 7 - only on XP.
I'm sure it'll also work with Seven - because injecting a new process into memory is a task that every debugger does.

[X] Doc CPU
 
Old 12-14-2011, 04:19 PM   #7
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by johnsfine View Post
So far as I recall, I haven't seen that used since Windows 95. Does it really work on XP (which was derived from Windows NT, not from 95)?
Now that you say it, I'm not entirely certain. I'm not entirely sure whether I saw it last time on windows 98 or windows xp, but it definitely wasn't win95. I also remember playing around with the technique, but again - I don't remember where any of those programs are now and can't find any of them to check.

Quote:
Originally Posted by Doc CPU View Post
But what's the point?
The only point I know of is demoscene contests. They have size limits - 4k, 64k, etc. A programming exercise. See .kkrieger(youtube video) for example (100kb 3d first person shooter prototype).

Quote:
Originally Posted by Doc CPU View Post
I'm sure it'll also work with Seven - because injecting a new process into memory is a task that every debugger does.
*IF* I remember correctly, it didn't work this way - *.com file have been unpacking PE onto disk and starting new process using dos interrupts. The problem is that I don't remember how exactly it was done - I think it called some kind of equivalent of exec() or system() using an interrupt. So if you'll tweak ntvdm equivalent on win7, it'll stop working - assuming it actually worked the way I think it did.

Anyway, I can't find any program that uses this technique on WinXP in my backups and can't verify if I'm correct (that it'll work on winxp). It is possible that I was mistaken somewhere.

Last edited by SigTerm; 12-14-2011 at 04:28 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
libogg not installing, make and make install don't give errors, but fail lilmike Linux - Newbie 6 11-14-2009 07:33 PM
Help needed for make file problem : make: *** No rule to make target `flash', needed rameshsatyavaram Linux - Newbie 3 09-11-2008 02:13 AM
Make Trouble linking some fortran code Make file problem? any ideas? TheBrick Linux - General 0 05-17-2006 11:21 AM
How to make rule for make install and make uninstall melinda_sayang Programming 1 06-14-2004 05:58 AM
make dep,make clean,make bzImage problem Babba Linux - Newbie 2 01-08-2003 03:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration