I am trying to build an old 16 bit DOS like OS.
My example kernel code:
asm(".code16\n");
void putchar(char);
int main()
{
putchar('A');
return 0;
}
void putchar(char val)
{
asm("movb %0, %%al\n"
"movb $0x0E, %%ah\n"
"int $0x10\n"
:
:"r"(val)
) ;
}
This is how I compile it :
nasm -f bin -o ./bin/boot.bin ./source/boot.asm
gcc -nostdinc -fno-builtin -I./include -c -o ./bin/kernel.o ./source/kernel.c
ld -Ttext=0x9000 -o ./bin/kernel.bin ./bin/kernel.o -e 0x0
dd if=/dev/zero of=./bin/empty.bin bs=1440K count=1
cat ./bin/boot.bin ./bin/kernel.bin ./bin/empty.bin|head -c 1440K > ./bin/os
rm ./bin/empty.bin
and I run it in a virtual machine.
When I make the putchar function ( in kernel code ) for constant value ....i.e like this:
void putchar()
{
char val = 'A';
asm("movb %0, %%al\n"
"movb $0x0E, %%ah\n"
"int $0x10\n"
:
:"r"(val)
) ;
}
then it works fine. But when I pass argument to it (That is in the previous code), then it prints a space for any character. What should I do?