I've been working on a real mode OS, writing in assembly and compiling to flat .bin executables with NASM.
I would like to write some of the OS in C, and so wrote an experiment program (ctest.c) which I would like to access a string and print the first character:
void test();
int main() { test(); return 0; }
char msg [] = "Hello World!";
void test() {
_asm
{
mov si, word ptr [msg]
mov al, [si]
mov ah, 0eh
int 10h
}
for(;;);
}
I compiled this with Open Watcom v1.9 using wcl ctest.c -lr -l=COM
. This creates ctest.com. The kernel, which I wrote in NASM assembly, loads this program to 0x2010:0x0000, sets DS and ES to 0x2000:0x0000 and then jumps to 0x2010:0x0000. This is how I have been calling .COM programs written in assembly and compiled with nasm -f bin test.asm -o test.com
.
When I test the OS (using Bochs), it successfully loads ctest.com, but prints out a meaningless character that is not part of msg[].
Does anyone have any suggestions about this? I think the string is just being initialized in the wrong place. I would like to keep this as a 16-bit OS.
thanks!