[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Low-level vs. High-level programming



In article <RFoJa.7756$mS2.5421@fe04.atl2.webusenet.com>,
Randy McLaughlin <randy@nospam.com> wrote:
 
> I would love to see someone control a port at a non-standard address in
> Basic, Fortran, Cobol, C, C++, etc without using extensions beyond the
> standard language.
 
The problem with Basic here is that there are hardly any ANSI Basic
implementations....
 
Anyway, doing this in C and C++ is quite trivial.  Suppose we wanted
to read a character off the Apple II keyboard (address $C000) and
then tell the keyboard we'd read it by writing to $C010.  In ANSI C
we would do like this:
 
    char c = *((char *) 0xC000);
    *((char *) 0xC010) = 0;
 
Another example is if you run C in 16-bit real mode on a PC and wanted
your C code to reboot the computer.  This is done by jumping to
FFFF:FFF0, or in ANSI C (must be compiled under medium or large memory
model):
 
        ((void (*)(void)) 0xFFFFFFF0L)();
 
or:
 
        (*((void (*)(void)) 0xFFFFFFF0L))();
 
 
If you wonder why these two expressions are equivalent, then consider
why this works, in ANSI C (if you don't believe it works, try it!):
 
#include <stdio.h>
 
int main()
{
    (******************************printf)("Hello, world\n");
    return 0;
}
 
-- 
----------------------------------------------------------------
Paul Schlyter,  Grev Turegatan 40,  SE-114 38 Stockholm,  SWEDEN
e-mail:  pausch at stockholm dot bostream dot se
WWW:     http://www.stjarnhimlen.se/
         http://home.tiscali.se/pausch/