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

Re: Low-level vs. High-level programming



In article <EHrJa.16254$bH3.337@fe02.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 truth is that your statement "If you can
>> | do it in asm you can do it in any language that is sufficiently
>> | complete." is not quite true.  Many computer languages do have
>> | limitations built into them. One good example is reentrant code, some
>> | can some can not.
>>
>> Fine, and I would love to oblige you.
>> If you would care to give me the address of the hypothetical port, then I
>> would be happy to furnish you with examples in Basic (yeauch !), Fortran,
>> Cobol and C. Can't really clain to know C++ that well, but might be
>> persuaded to give it a try. Might even be persuaded to give it a go in
>> Forth, Assembler and Java too if you ask nicely (and pay well). Please
>> don't
>> ask me to try it in HTML or XML.
>> Kevin.
>> P.S. Computer programming services at #30 per hour, plus expenses.
> 
> You might no be aware of it but without extensions these languages do not
> access hardware directly.  It does not matter how much you charge (your
> rates seem low to me) it can not be done.
 
If the hardware is memory mapped, it's trivial to access the hardware
in C.  That's why it's popular to use C to write device drivers, OS
kernels and stuff like that....  Here's how you do it:
 
    unsigned int memory_address = <address_of_memory_mapped_HW-device>;
 
Read the hardware:
 
    char c = *((char *) memory_address);
 
Write to the hardware:
 
    *((char *) memory_address) = 0;

Note that no extensions to C are needed to do this - C was designed to
be able to do stuff like this.
 
> If a computer can do the task it can be done in asm,  if it can be
> done in asm it does not guarantee it can be done in another language.
 
In most cases it can be done in C as well -- that's why C often is
called a "high level assembler"....
 
> I pointed out that the posters statement that to be a computer
> programming language you must be able to do what can be
> done in asm is incorrect.
 
With that I fully agree!  There are different levels of programming;
not everyone program on the "bare metal".....
 
-- 
----------------------------------------------------------------
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/