Stupid arrays in C
Posted: Sat Feb 16, 2008 8:15 pm
Hi,
after pausing os development a few years i just tried to come back.
I wrote a very small piece of code th have an environment to start with, but it drives me crazy. Grub is booting my elf32 file containing this piece of code:
Somehow the first and the second element of an array are always the same. However, increasing the pointer (with videoMem++) works correctly. Even the assemler code gcc -S creates seems to be correct:
Am I stupid, or is this a bug in my (emulated) hardware?
Cheers, Michael
after pausing os development a few years i just tried to come back.
I wrote a very small piece of code th have an environment to start with, but it drives me crazy. Grub is booting my elf32 file containing this piece of code:
Code: Select all
void print()
{
volatile char *videoMem = (volatile char*)0xB8000;
videoMem[0]='A'; //prints an A to (0,0) on the screen
videoMem[1]='B'; //overwrites the A with a B
videoMem[2]='C'; //makes the B cyan on red
videoMem[3]='D';//writes a D to (1,0)
}
Code: Select all
movq $753664, -8(%rbp)
movq -8(%rbp), %rax
movb $65, (%rax)
movq -8(%rbp), %rax
incq %rax
movb $66, (%rax)
movq -8(%rbp), %rax
addq $2, %rax
movb $67, (%rax)
movq -8(%rbp), %rax
addq $3, %rax
movb $68, (%rax)
Cheers, Michael