Consider working through such things step by step, with pencil and paper. Microprocessors are not magic. They do precisely what is asked of them.