简体   繁体   English

如何使用 OpenWatcom `owcc` 创建 DOS.com 文件,但没有 OpenWatcom libc?

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

Here is a short C file cu.c :这是一个简短的 C 文件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:当我使用 OpenWatcom 将其编译为 DOS.com 文件时,结果几乎是 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).执行相同操作(只是退出)的最小可能 DOS.com 文件是 1 字节长:它包含单个ret指令(字节 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? 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.我将直接从我的程序中调用 DOS API 函数( int 0x21 ),因此我不需要任何 OpenWatcom C 库函数。

Please note that COM executables with Open Watcom doesn't answer my question, because the solutions presented there all include the OpenWatcom C library.请注意, 带有 Open Watcom 的 COM 可执行文件不能回答我的问题,因为那里提供的解决方案都包括 OpenWatcom C 库。

I was able to solve it by using format dos com instead of system com in my custom.lnk file.我能够通过在我的 custom.lnk 文件中使用format dos com而不是system com来解决它。 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.通过这样做,系统中的lib文件libfile cstart_t.objlink.lnksystem begin com没有被使用,因此OpenWatcom C库中的启动代码没有被引用。

The resulting.com file is only 3 bytes ( xor ax, eax ; ret ), which I'm happy with.结果 .com 文件只有 3 个字节( xor ax, eax ; ret ),我很满意。 To make it actually run, I have to prepare and add my .obj file though which contains ..start: and sets up segments.为了让它真正运行,我必须准备并添加我的.obj文件,其中包含..start:并设置段。

I'm still looking for a solution which doesn't need a custom.lnk file.我仍在寻找不需要 custom.lnk 文件的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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