> > "Embedded systems suffer from another dependency problem: code that > > talks to hardware. Encapsulate all I/O operations." > > and > > "The OOP folks chant 'encapsulation, polymorphism and inheritance'; of > > those three, encapsulation is the easiest and most powerful tool for > > building well-written, easy to understand code. It's equally effective > > in assembly, C, or C++. Bind 'methods' (code that accesses a device or > > data structure) with the data itself." > > > > Does anyone have an example or explanation of how to encapsulate i/o in > > assembly and C? > > > > I'll keep looking, but so far what I've found discusses encapsulation in > > terms of how classes of objects are declared in C++; I haven't figured > > out yet how to relate that to non-object oriented languages. > > In the context of a typical microcontroller program, encapsulation of > I/O simply means putting all the actual hardware interface in a minimal > set of subroutines. All interaction with the hardware should be done > through those routines, rather than by directly changing hardware > registers. Complex I/O operations should be built on top of the basic > ones when possible, rather than by talking to hardware directly. As far as I understand, encapsulation in embedded system assembly/C programming is not much diff. from structure/module/data-structure programming. The objective is hiding as much info. from each other as possible. All these hidings come at a price of speed and memory. The other end of implementing this, you have the OOP language, and it is an evolution from the structure/module/data-structure programming. So in assembly and C, you implement this according to your budget. And bettering the budget is sometime what you are asked to do. Cheers, Ling SM -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads