#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 get how the output is getting printed without any printf or other print statements.
This is a x86 real-mode IBM PC program that assumes CGA/EGA/VGA compatible graphics adapter in color text mode mapped at the default memory location (B800:0000); it is basically from the era of MS-DOS (1980s/1990s). In any case it’s very old school!
Memory address (in real mode) of the video buffer (use
0xb0000000if you have an old Hercules)Clears the screen
Writes at row
0, column0the characterwSkips
2 bytes(in the character mode the buffer is interleaved:1 bytefor the character and1 bytefor the color.1 bitfor the flashing,3 bitsfor the background 0-7 and4 bitsfor the foreground 0-15, packed in this way:foreground + 16 * background + 128 if you want flashing)Writes at row
0, column1the charactereWaits for a key
Now a link about the CGA Text Mode Format, for those that FEEL the need of knowing how the “old generation” did it, before “Windows” came (and even before all that “Linux” came 🙂 ). Ah… and another link (a wiki this time) for those that still don’t know what REAL-MODE is.