Sort of Gray code to binary converter

[snip]

You left out _women_ ;-)

...Jim Thompson

-- | James E.Thompson, P.E. | mens | | Analog Innovations, Inc. | et | | Analog/Mixed-Signal ASIC's and Discrete Systems | manus | | Phoenix, Arizona Voice:(480)460-2350 | | | E-mail Address at Website Fax:(480)460-2142 | Brass Rat | |

formatting link
| 1962 | I love to cook with wine. Sometimes I even put it in the food.

Reply to
Jim Thompson
Loading thread data ...

newer CPUs

halfword/word,

clear

That's why I have always loved Analog Devices DSP's. A signed MAC instruction with post fetch for instance was:

mr = mr1 + mx0 * my0 (ss), mx0 = dm(i0,m0), my0 = pm(i4,m4)

And yes, this is one assembly instruction doing a multiply accumulate and load the mac input with two new values from pointers with auto-de/increment.

Meindert

Reply to
Meindert Sprang

If we're talking C, all objects with static storage duration *must* be initialized. I've never seen a compiler that fails to do that.

So, if unsigned int table[256] is a global (eg. declared before 'main()'), or if you add the 'static' storage-class specifier it gets initialized by the startup code. *Always* to 0 for each element*.

That said, this would be a horrible way to do it-- for one thing the table would typically reside in RAM if you don't tell it otherwise (there might not be that much RAM!), and would only be initialized once, which leaves you open to RAM data corruption between resets (which could be a long time).

  • IME with a microcontroller compiler, typically the compiler crams all the globals and statics together and the startup code just clears the whole block from beginning to end in one tight loop.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

Stop, stop, stop.

I have just counted 65 messages in this thread and we have already descended into bickering. That wasn't meant to happen until at least the middle of next week.

It's probably only lunchtime for you guys across the pond, but I have just had a wonderful dinner of roast chicken, roast parsnips, baked potatoes, carrots and brussle sprouts (why do we call them that? I don't think they came from Brussles) accompanied by a bottle of Fetzer Sundial Merlot 2004. Why do those Californian winemakers insist on pouring molten wax on top of the cork, it never comes off cleanly and there's always bits floating about, but that's another story. Followed by chocolate and coffee cheesecake with fresh cream. Mmmm, and all cooked by me!

Well I think it's time to announce the winners already, otherwise I'll never be able to toast them all between now and the New Year. My wine cellar only has 47 bottles in it at the moment!!

First prize for most elegant hardware solution goes to Andrew Holme for his 16V8 code.

First prize for lowest number of discrete components to Ken Smith.

First prize for the best off the wall solution goes to Rich for his diode matrix.

This is just a personal thing but anyone who even mentioned PIC has been killfiled (no not really, but you get my meaning) as I'm an AVR and ARM protagonist. I have to say that all of the software solutions have been as ugly as my original code. OK, a look-up table is probably the fastest solution but it is soooo UGLY. 'if' 'else if' etc. or switch{} are also OK but have no elegance.

Sorry guys, but so far the software solutions have been meagre but what else did I expect from a group whose favourite programming language is 'Solder'.

Jim appeared to be working on a solution but faded at the last furlong, but where was Win? He doesn't seem to have even made it out of the starting gate.

Anyway, I congratulate all of the hardware winners, and will toast them all very soon. As for you software guys, well you've failed me and I'll just have to drink an extra toast to Anon in the hope that he/she will come up with the magic bullet solution. Why did we always use that phrase along with 'Paradigm shift' in the batwing corporation?

Merry Christmas to all from the pagan in the West of Scotland.

--
John B
Reply to
John B

How do you like C++? ;-) That's the one that's giving me a headache at the moment.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany
[snip...snip...]

Thanks for the link -- always like to try out new tools.

--
Rich Webb   Norfolk, VA
Reply to
Rich Webb

In article , Rich Grise wrote: [...]

I can't think of any compiler that initializes. I doubt that any micro controller ones do.

This construct takes a *lot* more code space.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

In article , John Larkin wrote: [...]

No, a PDP-8 had a 12 bit ALU.

It also didn't have a stack. The call and return worked by storing the return address in the first location of the subroutine.

It also didn't subtract.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

Yes that is true. The statements after the declare had me thinking of code within a function. I still hate C BTW.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

In article , John Larkin wrote: [...]

If you pipeline, you may be able to do better. I've never tryed to be sure.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

.... so I gave up singing ....

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

Too neat and too subtle for me Speff. This is a dedicated uP, running just the one prog. Why not throw some simple brute force and ignorance at the problem.

.1st Load W with 1st possible input byte. Subtract: W - actual input byte. Skip to .2nd if result was not zero (Z=0). Branch if Z=1 --> Set output nibble req'd for 1st. Clear STATUS register. Branch back to .16th.

.2nd Load W with 2nd possible input byte. Subtract: W - actual input byte. Skip to .3rd if result was not zero (Z=0). Branch if Z=1 --> Set output nibble req'd for 2nd. Clear STATUS register. Branch back to .1st. Similar .3rd, .4th, up to .15th.

.16th Load W with 16th possible input byte. Subtract: W - actual input byte. Skip to .again if result was not zero (Z=0). Branch if Z=1 --> Set output nibble req'd for 16th. Clear STATUS register. Branch back to .15th.

.again Branch back to .1st.

Branching back one place after any match focusses each loop on the three positions centred on the last successful match. So each 3-position loop will be about 7 to 20 instructions.

The inputs are from microswitches, and they only need to be visited at about 1mS intervals. That could be a PIC with an RC clock of about 100KHz or so.

--
Tony Williams.
Reply to
Tony Williams

etc

Oh Bum! Been reading ARM code for the last few days and forgot that the PIC's STATUS register cannot, (and should not), have it's Result bits cleared.

--
Tony Williams.
Reply to
Tony Williams

;-) The ARM has a relatively pleasant machine language. Maybe a $2 Philips ARM would be a good choice for this application. Nah, the second regulator for the core voltage spoils the elegance.

Your method is the same number of instructions per comparison. The clever jumping around adds time worst case (and adds perhaps 1/3 to the instructions), but you've achieved better typical response by using that degree of freedom.

But here is a perhaps a better way than either if detecting invalid states is not a requirement. I'll not bother putting it in asm for any particular processor:

r = 0 ; clear the result x = input ; sample the input ABCDEFGH y = rotate_left(x) ; rotate x 1 bit to the left ; y = BCDEFGHA if (x & y) set bit 0 of r y = !y & x ; !y is 1's complement of y ; y now contains ; A&/B B&/C C&/D D&/E ; E&/F F&/G G&/H H&/A

if (y & 0xAA) set bit 1 of r if (y & 0xCC) set bit 2 of r if (y & 0xF0) set bit 3 of r

This is based on Andrew Holme's SPLD solution.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

Actually, yes. What variety would you like? Fixed point (32 or

64bit) or float (double or single). How much money you got? ;-)
--
  Kieth
Reply to
Keith Williams

Compromise; "it's like arguing whether to have food or wine with your _women_". ;-)

--
  Keith
Reply to
Keith Williams

Well, we all know what a solid piece of code Windows is.

John

Reply to
John Larkin

On 14/12/2005 the venerable Spehro Pefhany etched in runes:

. .

If you think that C++ is bad, just wait until you graduate to Visual C#.NET!!

--
John B
Reply to
John B

On 13/12/2005 the venerable Richard Henry etched in runes:

. .

Hey Richard. Take another week if you need it.

As I said yesterday there are still 47 bottlesh (hic - shorry that'sh now 46) in my wine shellar, sho there'sh plenty to go round!!

Have a go at the really elegant software solution. Maybe four lines of code and a 16 entry look-up table. That's assuming I don't get there first.

--
John B
Reply to
John B

"Here, from a former Microsoft developer, are super secrets for developing bug-free C programs. Maguire provides examples of how bugs are caught at Microsoft (using actual case histories) and shows how readers can use these proven programming techniques to get products to market faster."

Thanks! That's hilarious.

New and used, $9. Almost worth a fling.

John

Reply to
John Larkin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.