Search code examples
c++iolow-level

is it possible to perform I/O operations in C++ without using any header files?


I just wondered, all I/O in C++ is done through the standard library header files which means (for C++ std libs) input and output streams or (for C std libs) means standard input/output functions.

My question is, Is it possible to not use these at all, and directly interface with the stdin and stdout of the OS?

In C++, without using any headers, I mean.


Solution

  • unsigned char in(unsigned short port) {
    unsigned char rv;
    __asm__ __voltaile__ ("inb %1, %0" : "=a" (rv) : "dN" (port));
     return rv;
    }
    void out(unsigned short port, unsigned char data) {
     __asm__ __voltaile__ ("outb %1, %0" : : "dN" (port) : "a" (data));
    } 
    
    

    It exists...