??? 09/08/05 12:45 Read: times |
#100802 - Explanation Responding to: ???'s previous message |
I'll try to give an explanation on what, and why, it is considered to be a negative value of a binary number.
Let's take a usual binary counter, for example with 8 stages (8 bits). Every pulse increments its state, so that it shows ...000, ...001, ...010, etc. Every time a stage changes from 1 to 0, it also makes the pulse for the next higher stage. We know that an 8 bit counter has 256 different states. What happens when all 8 stages are 1 and a new pulse comes ? The lowest will go to 0, so the next receives pulse and goes to 0 and so on. The highest also goes to 0, but its pulse doesn't affect any stage, because there is no higher. So, after 1...11, we are back to all zeroes. In that way, the counter counts cyclically in a closed loop. Counting down would make a similar effect, after 0, all stages come to all 1's and so on. Addition or subtraction of some values makes the same effect as counting up or down. (Exactly the same is behaviour of a mechanical counter, which you can turn up or down!) So, the value of FFh may be considered as -1, because we get 0 when 1 is added. FEh is then -2, and so on. So called Signed integers take the lower half of the range (MSB is 0) as positive and upper half (MSB is 1) as negative. To get a negative number of ACC, you should perform: CPL A INC A.(If you like to play, apply this formula to the values: 1, 2, FDh, 0, 128 !) As timer counters all count up, when we decide about reloading value for a timer, we express it as a negative value, because that's exactly the number of counts before the counter reaches the top-to-zero transition. Slobodan |