Hello,
I am writing small kernel for the 8086 processor (Working in BC3.1, on Windows XP as host operating system). Kernel is multithreaded, so I have problems when I use printf or cout for debugging (somewhere in code, printf sets InterruptEnable flag to 1, and my timer interrupt routine calls dispatch and my code breaks down).
Because of that, I wrote simple puts function in inline asm:
void _printf(char *c)
{
//setup data
asm{
mov ch, 10
mov cl, 0
mov ah, 0x2
mov bx, WORD PTR c
}
loop: asm{
//\0?
cmp [bx], cl
je exit_prc
mov dl, [bx]
int 0x21
inc bx
//is there \n?
cmp [bx], ch
je newline
jmp loop
}
exit_prc: return;
newline: asm{
//insert cr char
mov dl, 0xD
int 21h
jmp loop
}
}
Now, I call it somewhere in, lets say PCB::PCB() like this:
_printf("Counstructor PCBa\n");
and it works fine. However, when I call it somewhere else, in some other file with other string it outputs for example "tructor PCBa\n".
I don't have a clue what is going on. Memory model is huge.