Skip to content

Instantly share code, notes, and snippets.

@davidejones
Created January 19, 2017 16:59
Show Gist options
  • Save davidejones/233abdd393add4ff157c9b565c76821b to your computer and use it in GitHub Desktop.
Save davidejones/233abdd393add4ff157c9b565c76821b to your computer and use it in GitHub Desktop.
mingw gcc dos compile (thanks to http://nullprogram.com/blog/2014/12/09/)
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;
}
CFLAGS = -std=gnu99 -Wall -Wextra -Os -nostdlib -m32 -march=i386 \
-Wno-unused-function \
-ffreestanding -fomit-frame-pointer -fwrapv -fno-strict-aliasing \
-fno-leading-underscore \
-Wl,--nmagic,-static,-Tmingw.com.ld
all:
gcc $(CFLAGS) -o hello.o hello.c
objcopy -O binary hello.o hello.com
SECTIONS
{
. = 0x0100;
.text :
{
*(.text);
}
.data :
{
*(.data);
*(.bss);
*(.rodata);
}
_heap = ALIGN(4);
}
Copy link

ghost commented Apr 27, 2017

Thanks a lot for this!

@davidejones
Copy link
Author

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment