To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 2258
2257  |  2259
Subject: 
Re: GNU C wizards?
Newsgroups: 
lugnet.robotics
Date: 
Mon, 4 Jan 1999 17:50:49 GMT
Original-From: 
John A. Tamplin <jat@Traveller+nomorespam+.COM>
Viewed: 
1139 times
  
On Sun, 3 Jan 1999, dave madden wrote:

Are there any GNU C/C++ wizards out there?  I'm trying to write an
asm() statement to describe the H8's bclr/bset instructions.  I have a
wicked sweet tooth for C++ syntactic sugar, and I'd like to be able to
say (for example):

    Port6.Bit3 = true;

and have it turn into:

    bset #3,@0xbb:8

[Actually, I'd *really* like to say: "Port6[3] = true;" but after
beating my head against the compiler for an hour or two, I don't think
it's going to happen.]

Actually, you can do that -- look at the STL implementation for
BitVector<bool>.

I'm making some headway with templates for Ports and Bits:

    template <int DR, int DDR> Port {
        public:
        template <int N> Bit {
            public:
            Bit &operator=( bool b ) {
                if (b)
                    asm( "bset..." );
                else
                    asm( "bclr..." );
                return *this;
            }
        } ;

        Bit<0>  Bit0;
        // ...
        Bit<7>  Bit7;
    } ;

This is similar to the STL implementation using a helper class for the
assignments.  All you need to do is pass a reference to the port object
into the bit when you create it (in the subscript opererator), and then
the helper object calls members on the Port object when you access the
value (via cast operators) or assign the value (via the assignment operator).

but I can't get the constraints for the two asm() statements quite
right.  Can anybody help?

I don't think you need to use asm - the compiler will use those
instructions.  Just do it in C++:
  value|=(1<<bit) to set
  value&= ~(1<<bit) to clear

One problem to consider is that any of these bit manipulation operations
do a read-modify-write.  That is ok for the P6DR, but not for P6DDR
(which is write-only) or many other on-chip registers it is not.  For those,
you have to keep a shadow copy in RAM, modify the RAM copy, and then copy
that to the register.

John A. Tamplin Traveller Information Services
jat@Traveller.COM 2104 West Ferry Way
256/705-7007 - FAX 256/705-7100 Huntsville, AL 35801

--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



Message has 1 Reply:
  Re: GNU C wizards?
 
On Sun, 3 Jan 1999, I wrote: =>> =>> Are there any GNU C/C++ wizards out there? I'm trying to write an =>> asm() statement to describe the H8's bclr/bset instructions. I have a =>> wicked sweet tooth for C++ syntactic sugar, and I'd like to be able (...) (25 years ago, 4-Jan-99, to lugnet.robotics)

Message is in Reply To:
  GNU C wizards?
 
Are there any GNU C/C++ wizards out there? I'm trying to write an asm() statement to describe the H8's bclr/bset instructions. I have a wicked sweet tooth for C++ syntactic sugar, and I'd like to be able to say (for example): Port6.Bit3 = true; and (...) (25 years ago, 4-Jan-99, to lugnet.robotics)

6 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR