On Mar 26, 2012, at 2:57 PM, fireweaver wrote: > > I have a question of some concern to me, perhaps you could help. > > In overview, it involves mixing assembly language and C code. > > In detail: > > The CPU that I am using is ATmega328 using AVR Studio 5 as a development > environment. > > I an writing a motor control application that involves a quadrature encoder > attached to the motor shaft and a corresponding decoder with the following > characteristics: > > [1] The decoder itself is implemented entirely in assembly language. > [2] All the rest of the application will be written in C. > [3] It maintains a running 24-bit count of the encoder's position. > [4] It will be called by a periodic interrupt at 25 kHz sample rate. > [5] THE DECODER RESERVES FIVE OF THE MACHINE REGISTERS FOR ITS EXCLUSIVE > USE. > This is the big deal I want to question you about. > > What I want to do is this: Can I somehow tell the C compiler that comes > with AVR Studio that these certain five registers are reserved for the exclusive > use of the decoder and therefore avoid using them in any way? Question for you: Why are you so determined to implement the decoder in assembly? What evidence do you have to support the additional effort and future difficulty in maintaining the code? The biggest compromise I see to use C is that the counter will be 32 bits. If you must, let C calculate to 32 bits and then chop it down to 24. You can use a mask to reach the high 8 bits, or overlay the 32 bits with a bitfield. Don't worry about the "5 dedicated registers". Use static variables in C and if they have to be stashed in RAM then let them. Its a machine, its not going to complain about repetitive tasks. And as a machine if its fast enough to get the job done, and done correctly, then don't sweat the details. -- David Kelly N4HHE, dkelly@HiWAAY.net ============================================================ Whom computers would destroy, they must first drive mad.
Message
Re: [AVR-Chat] Mixing C and assembly with special requirements.
2012-03-26 by David Kelly
Attachments
- No local attachments were found for this message.