Manipulating Hardware with C -

Manipulating Hardware with C


C is the language of choice for any type of systems prog ramming (including embedded systems), because it allows the programmer to gain easy access to the hardware. Unfortunately, the built-in support for that access isn't as great as what C's reputation might imply.

Depending on the environment, programmers may need to directly manipulate memory, registers, processor status flags, I/O ports, or interrupt vectors and handlers. Pointers do allow direct access to memory, but all other hardware resources must be accessed with assembly language, either through a separately written and linked function, in-line assembly (if your compiler allows it), or very nasty tricks like executable strings. Fortunately, because C is so often used for systems programming, most compiler vendors include in their standard library package routines for manipulating ports and restricted aspects of interrupts.

Mainstream compilers, though, seldom include a means of accessing processor flags and register contents, or completely general support for interrupt use. Thus, If you need to manipulate only memory and ports, you may be able to avoid writing any assembly in your project by becoming familiar with the support built into your compiler's library. Otherwise you will need to resort to the techniques developed here.

ESC_1991_Vol2_Page710_Ward – Manipulating Hardware with C.pdf

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.