I've been working on a customized operating system project in school, and when I started coding in C++, I reached a huge problem:
I've built a custom put_char function in assembly, it basically takes an address and a Dword value and saves it in memory. I'm using Qemu virtual machine, and 0xb8000 is the Screen memory start (SCREEN_START)
if I run the code in CPP:
put_char(SCREEN_START, 0x2f562f56)
(0x2f202f56 is "/V/V") it prints "VV" to the screen, so the function itself does work.
The put_chars code:
put_char:
push ebp ; save the prior EBP value
mov ebp, esp
mov ebx, edi;
mov edx, esi;
mov dword [ebx], edx
xor eax,eax
pop ebp ; minimal cleanup
ret
But the problem happens when i tied to print a char from an array: When I tried passing a string (char *) to a function, it sends the wrong values.
void pp(char hello[])
{
for (int i = 0; i < 7; i++)
{
put_char(SCREEN_START + i*4, hello[i] );
}
}
global void kernel_main()
{
pp("Hello!");
}
The screen prints different values each time, and it's never "Hello!"... For example it prints spaces only...
According to what I read, this happens when the stack is corrupted, but I haven't used the stack in any of my codes, especially the assembly ones.
Not really sure how to fix this, tried different things, like building a struct or a class, passing it as char* and not char[], making a constant string to print outside of the function... nothing really worked, I even tried sending int array, and didn't work.
Please let me know if anyone could help! really need it!