Showing posts with label pointer. Show all posts
Showing posts with label pointer. Show all posts
Thursday, August 12, 2010
Print a character to screen without using any Library functions in C.
void main()
{
char far* src = (char far*) 0xB8000000L;
*src = 'H';
src += 2;
*src = 'i';
src+=2;
*src='!';
getch();
}
You may wonder whether it is possible to display a character in the screen without using any C library functions. Yes, it is possible by directly accessing the memory of the device's display buffer with a character pointer and assigning some character to it.
In the above code, the first line assigns the address of the memory location where we want to put the character. Actually the display buffer will be having 4000 memory blocks for printing characters in pure DOS mode.
Pure DOS mode supports printing of 2000 characters per screen.
Generally for displaying a character, two memory blocks(bits) are used. The first block for specifying What the character is and the second block of memory is to represent the property of the character, like color.
If you are printing something using the above method you will find the characters only at the top-left corner of the screen since you are accessing the initial memory address of the display buffer (0xB8000000L).
Anything you have printed on the screen before executing this code will be sent to the lower screen (if you have not specified any clrscr(); in this program)
Subscribe to:
Posts (Atom)