Python for everything?

Roy Smith roy at panix.com
Thu Jun 30 20:25:17 EDT 2005


Ivan Van Laningham <ivanlan at pauahtun.org> wrote:
> It really was used "for everything"; C compilers have *always* let you
> include assembler, with the "asm" keyword.  Unless you're talking about
> the early days of DOS/Windows compilers, about which I know little, but
> all *K&R* compilers had asm.  If you wanted to write kernel code and
> device driver code (including disk drivers) for large Unix systems, asm
> was a requirement.

The ability to embed assembler in-line with C code is only a convenience.  
For the extremely small amount of assembler code required in a typical 
kernel, it's easy enough to write small routines directly in assembler, and 
call them from your C code like you would any other function.

The last time I was inside a Unix kernel was the pdp-11 days.  The pdp-11 
was a memory-mapped machine, which meant almost all hardware interactions 
were done by loading and reading fixed memory locations.  So, you could do 
things like (I'm doing this from memory, so it's only vaguely correct):

struct dr11regs {
   unsigned int cmd;
   unsigned int status;
   unsigned int count;
   unsigned int base;
};

struct dr11regs *drptr = 0177540;
char buf[MAXBUF];

drptr->base = buf;
drptr->count = MAXBUF;
drptr->cmd =& DR_START;
while ((drptr->status & DR_REMAIN) > 0) {
   wait();
}

That's a lot of low-level bit fiddling right down on the bare metal, and 
not a line of assembler in sight.



More information about the Python-list mailing list