How data processes in microprocesser ??

Hi all,

I was going through the source code of some embedded application where I saw a code written like

uint16_t opcode = (0x08

Reply to
mithlesh88
Loading thread data ...

Reply to
Simon Clubley

Reply to
George Neuner

Which would not relieve a conforming C compiler from jumping through whatever hoops needed to perform an actual shift by 10.

I agree with Simon, most likely this was intended to provide some sort of clarity/documentation.

A second, and lesser, possibility is a very poor compiler that optimized the double shift form better, perhaps by generating a 2 bit shift and then a byte move, as opposed to a (perhaps very) slow 10 bit shift.

Reply to
Robert Wessel

20 years ago your "very poor" compiler would have been about par for the course for embedded C. Giving the compiler clues like that was pretty normal.

Now, it just gets in the way of readability, and sometimes messes up the optimizer (when it's a more complicated "clue" than that one).

--
Tim Wescott 
Control system and signal processing consulting 
 Click to see the full signature
Reply to
Tim Wescott

But it's a compile time known constant, so surely the compiler would just evaluate the expression at compile time and just place the final result in the generated code.

Back in the 1990s (your twenty years ago) I was writing LL(1) recursive descent based compilers and that was normal behaviour even in the simple compilers I was writing then.

Perhaps the original author wanted to make clear what bit pattern lives in the top 8 bits of the opcode.

Simon.

--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP 
Microsoft: Bringing you 1980s technology to a 21st century world
Reply to
Simon Clubley

I was using some pretty simple-minded compilers. And some good ones. I recall spending a lot more time dodging compiler oddities than I do now.

That could be, too. Certainly with a modern compiler that's the only excuse.

--
Tim Wescott 
Control system and signal processing consulting 
 Click to see the full signature
Reply to
Tim Wescott

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.