[C Kernel Development] Strange problem with arrays
Posted: Wed Jun 22, 2016 2:38 am
Hi all again ,
I'm Flavius12 (a member of EvolSoft) and I'm trying to write an alternative kernel in C using OpenWatcom C Compiler.
It's a day that I'm trying to fix a strange problem with arrays.
This is my code:
This is the COMPILE.BAT file (used to compile the kernel):
It's "booted" from the bootloader which prepares all registers before loading and executing it. This is what the bootloader does:
1. Read the kernel file and put it in 0x0060:0x0000
2. Set DS, ES and SS to 0x0060
3. Set SP to 0xFFFE
4. Jump to 0x0060:0x0000 (executes the kernel)
The problem is that when I try to print an element of the array it prints a wrong ASCII character. I don't understand why this happens only with arrays and not for example with a char pointer or with a single char. How can I fix this?
Thanks in advance,
Best Regards,
Flavius12 (EvolSoft)
I'm Flavius12 (a member of EvolSoft) and I'm trying to write an alternative kernel in C using OpenWatcom C Compiler.
It's a day that I'm trying to fix a strange problem with arrays.
This is my code:
Code: Select all
void pokeb(int segment_, int offset_, char chr_);
void kernel(){
char r[3] = {'T', 'K', 'S'};
//Set 80x25 Text screen mode
_asm {
mov ah, 0
mov al, 03h
int 10h
};
//Put a byte into video memory (print a character on x=1 y=1)
pokeb(0xB800, 0, r[1]);
//Wait for key input
_asm {
xor ax, ax
int 16h
};
}
void pokeb(int segment_, int offset_, char chr_){
_asm {
mov bx, segment_
mov es, bx
mov bx, offset_
mov al, chr_
mov BYTE PTR [es:bx], al
};
}
Code: Select all
wcc -0 -d0 -ms -s -zl KERNEL.C
wlink FILE KERNEL.OBJ FORMAT RAW BIN NAME KERNEL.SYS OPTION NODEFAULTLIBS, START=kernel_
1. Read the kernel file and put it in 0x0060:0x0000
2. Set DS, ES and SS to 0x0060
3. Set SP to 0xFFFE
4. Jump to 0x0060:0x0000 (executes the kernel)
The problem is that when I try to print an element of the array it prints a wrong ASCII character. I don't understand why this happens only with arrays and not for example with a char pointer or with a single char. How can I fix this?
Thanks in advance,
Best Regards,
Flavius12 (EvolSoft)