Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Micro was Coldfire MCF52259, using C in Codewarrior. Looking at the disassembler / asm is a useful exercise as it shows all the steps the CPU has to go through to do even the most basic operation. <br>We also spotted other CPU-hogging instructions in time-critical loops - constraining a variable by doing var %= max_val costs a pile of CPU cycles every time round, while doing if(var > max_val)var-=max_val uses only a couple of instructions. <br>A good guide to a few more tricks is here: codeproject.com/Articles/6154/… Commented Jun 19, 2012 at 17:33
  • 1
    Even more importantly, the helper memory-mapped I/O registers provide a mechanism for atomic updates. Read/modify/write can go very badly if the sequence is interrupted. Commented Feb 22, 2015 at 2:16
  • 3
    Keep in mind that all port registers will be defined as volatile and therefore the compiler is unable to perform any optimizations on code involving such registers. Therefore, it is good practice to disassemble such code and see how it turned out on assembler level. Commented Dec 14, 2015 at 9:42
  • This isn't clear. What is faster? Operating directly on the memory mapped I/O? Doing everything in (presumably) CPU registers and writing the final result to the I/O register? Commented Aug 22, 2023 at 0:41
  • Operating directly on the I/O registers can lead to glitches (pulses) on the output pins where intermediate results of the bitwise operations are written out. Commented Aug 22, 2023 at 0:43