c - Writing to 0xb8000000 yields output on screen without any print statements such as `printf` -


#include <stdio.h> #include <conio.h>  void main() {   char far *v = (char far*)0xb8000000;   clrscr();    *v = 'w';   v += 2;   *v = 'e';    getch(); } 

output is: we

i don't how output getting printed without printf or other print statements.

this x86 real-mode ibm pc program assumes cga/ega/vga compatible graphics adapter in color text mode mapped @ default memory location (b800:0000); era of ms-dos (1980s/1990s). in case it's old school!

char far *v=(char far*)0xb8000000; 

memory address (in real mode) of video buffer (use 0xb0000000 if have old hercules)

clrscr(); 

clears screen

*v='w'; 

writes @ row 0, column 0 character w

v+=2; 

skips 2 bytes (in character mode buffer interleaved: 1 byte character , 1 byte color. 1 bit flashing, 3 bits background 0-7 , 4 bits foreground 0-15, packed in way: foreground + 16 * background + 128 if want flashing)

*v='e'; 

writes @ row 0, column 1 character e

getch(); 

waits key

now link cga text mode format, feel need of knowing how "old generation" did it, before "windows" came (and before "linux" came :-) ). ah... , link (a wiki time) still don't know real-mode is.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -