简体   繁体   中英

How to create DOS .com file with OpenWatcom `owcc`, but without the OpenWatcom libc?

Here is a short C file cu.c :

int main(int argc, char **argv) {
  (void)argc; (void)argv;
  return 0;
}

When I compile it with OpenWatcom to a DOS.com file, the result is almost 3 KiB:

$ owcc -bcom -mcmodel=t -fno-stack-check -Os -s -march=i86 -W -Wall -Wextra -o cu.com cu.c
$ ls -l cu.com
-rwxr-x--- 1 pts pts 2938 Jun 20 19:26 cu.com

The smallest possible DOS.com file which does the same (just exits) is 1 byte long: it contains a single ret instruction (byte 0xc3).

How can I compile my cu.c file (with possibly some modifications, I don't care about argc or argv) to a smaller DOS.com file, without the OpenWatcom C library (libc), preferably less than 100 bytes? I will call DOS API functions ( int 0x21 ) directly from my program, thus I won't need any of the OpenWatcom C library functions.

Please note that COM executables with Open Watcom doesn't answer my question, because the solutions presented there all include the OpenWatcom C library.

I was able to solve it by using format dos com instead of system com in my custom.lnk file. By doing so, the libfile cstart_t.obj in system begin com in link.lnk wasn't used, thus the startup code in the OpenWatcom C library wasn't referenced.

The resulting.com file is only 3 bytes ( xor ax, eax ; ret ), which I'm happy with. To make it actually run, I have to prepare and add my .obj file though which contains ..start: and sets up segments.

I'm still looking for a solution which doesn't need a custom.lnk file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM