Sunday, September 19, 2010

[EI 502, IC 503, EI 405, EI 611]Common Mistake about Logical Operations

There is a very common mistake most of us make when working with logical shift/rotate operations. Until you are absolutely conscious, we tend to do logical operations before setting up a conditional jump instruction (jump of zero, jump on non zero etc.). We simply assume that, like in most instructions of a microprocessor, the flags get set because of the logical operation. We expect the zero, minus, sign etc. flags will get set appropriately and we should be able to use that condition for the conditional branch instruction immediately after this operation.

However, the logical shift/rotate operations group of instructions do not affect the flags in the processor (in the 8085 at least, except CY sometimes). Thus if you use a conditional jump/branch instruction after a these logical operations, it'll fail or will cause wrong results. So, watch out! Before you use a conditional jump/branch instruction, check if the instruction you are using for setting the flags actually does it!

No comments:

Post a Comment