[分享] How to build DOS COM files with GCC

看板CompilerDev作者 (影斯作業系統)時間5年前 (2020/10/30 02:22), 編輯推噓1(100)
留言1則, 1人參與, 5年前最新討論串1/2 (看更多)
之前意外看到的 gcc 特殊應用。 https://nullprogram.com/blog/2014/12/09/ "The most technically interesting part is that I didn’t need any DOS development tools to create this!" Compiler Options Here are the essential compiler options. -std=gnu99 -Os -nostdlib -m32 -march=i386 -ffreestanding Linker Options The -Wl option is used to pass arguments to the linker (ld). We need it since we’re doing all this in one call to GCC. -Wl,--nmagic,--script=com.ld com.ld OUTPUT_FORMAT(binary) SECTIONS { . = 0x0100; .text : { *(.text); } .data : { *(.data); *(.bss); *(.rodata); } _heap = ALIGN(4); } Program Startup asm (".code16gcc\n" "call dosmain\n" "mov $0x4C, %ah\n" "int $0x21\n"); static void print(char *string) { asm volatile ("mov $0x09, %%ah\n" "int $0x21\n" : /* no output */ : "d"(string) : "ah"); } int dosmain(void) { print("Hello, World!\n$"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.45.139.241 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/CompilerDev/M.1603995735.A.91D.html

10/30 02:45, 5年前 , 1F
酷 XD 不過這可能也是得利於 COM 格式沒有 metadata 的關係
10/30 02:45, 1F
文章代碼(AID): #1VcmXNaT (CompilerDev)
文章代碼(AID): #1VcmXNaT (CompilerDev)