Video memory access and postfix incrementation
Posted: Thu Aug 27, 2015 6:10 am
Hello !
I'm actually trying to create my own kernel, and I have got some problem with video memory access :/
I need to access to video memory at boot, thus, I create a pointer to 0xB8000 address and then, I increment the pointer to access next location.
Basically, the code would be :
This way, p point to the proper memory address, and after each access, it is incremented (I know, the there is 2 bytes for each character displayed, but it will be more simple without taking care of it). So, it should show, on top left of the screen 3 letters 'A', with 'A' = 0x41 attributes, so blue letter on red background.
But this doesn't work, no character displayed. It display nothing. But if I change incrementation position like this, it works, i can see the characters on the screen !
By the way, with a prefix incrementation, it works too. But with postif incrementation, I should set to pointer to the (first_video_memory_location - 1) to write on the good location :
So, I checked assembly code :
I can't spot the difference. By the way, I could use the prefix incrementation but, I would like to understand with does the postfix not work :/
The assembly code is from Visual C++ compiler, I don't have any GCC at work :/
I know the difference between prefix and postfix incrementation, and I see the difference between assembly code present here. But IMO, none of these differences leads to non printing characters on screen.
Thank you
I'm actually trying to create my own kernel, and I have got some problem with video memory access :/
I need to access to video memory at boot, thus, I create a pointer to 0xB8000 address and then, I increment the pointer to access next location.
Basically, the code would be :
Code: Select all
volatile char *p = (volatile char *)0xB8000;
for (int i = 0; i < 6; ++i)
*(p++) = 'A';
But this doesn't work, no character displayed. It display nothing. But if I change incrementation position like this, it works, i can see the characters on the screen !
Code: Select all
volatile char *p = (volatile char *)0xB8000;
for (int i = 0; i < 5; ++i)
*p = 'A';
p++;
Code: Select all
volatile char *p = (volatile char *)0xB7FFF;
for (int i = 0; i < 5; ++i)
*(++p) = 'A';
Code: Select all
; Postfix
mov ecx, DWORD PTR _p$[ebp]
mov BYTE PTR [ecx], 65 ; 'A' character
mov edx, DWORD PTR _p$[ebp]
add edx, 1
mov DWORD PTR _p$[ebp], edx
; Prefix
mov ecx, DWORD PTR _p$[ebp]
add ecx, 1
mov DWORD PTR _p$[ebp], ecx
mov edx, DWORD PTR _p$[ebp]
mov BYTE PTR [edx], 65 ; 'A' character
The assembly code is from Visual C++ compiler, I don't have any GCC at work :/
I know the difference between prefix and postfix incrementation, and I see the difference between assembly code present here. But IMO, none of these differences leads to non printing characters on screen.
Thank you