An Engineer in Wonderland – Help Alice with assembler code
I am trying to write some code for a microcontroller – a PIC – and have stumbled across a problem, and a sort-of answer.
As I have no formal training in well-structured assembler code, I suspect my answer is sub-optimal – or even sub-passable – and could do with some help.
My hope is that some kind soul will say ‘What you need is to use Shubunkin’s inferior parameter pass, or the Smyth-Hamilton’s data swap’, or some such.
Anyway, this is the problem:
My interrupts service routine stores a number in a byte of memory for the main programme loop to use. For the sake of argument, the byte is called John.
The main loop transfers this number to a working register to use it, then clears John.
The problem that I envisage is: That the ISR will very occasionally put a new value into John in the 1µs between the main loop reading John and the main loop clearing John.
Which will mean the main loop occasionally misses a new value from the ISR.
How do you get over that?
My clunky answer is to have the ISR read John to make sure it is clear before storing a new value into it. If John is not clear, the ISR will have to store the spare value until the next time tick and have another go at putting it into John.
The additional time delay will be no problem, but the ISR may have to store one or two spare values pending putting them into John.
And is there a book on good structured assembler programming that would help?
Please don’t respond below as our spam blocking system doesn’t work and the inbox is overwhelmed by all kinds of generous offers from a multitude of rather annoying people.
Should you feel the need, respond to firstname.lastname@example.org with ‘Assembler’ in the title.
No email addresses are collected for marketing (or any other) purposes from responses to this blog. I will keep it that way for as long as possible.Tags: Alice, Engineer in Wonderland