![]() |
![]() |
Objectives
Our programs so far have been fairly dumb. They do one or two simple things but they are incapable of anything "intelligent". To manage this, we need the ability to evaluate current circumstances and make decisions based upon what we find. This has other effects, too. For example, we would then be able to make loop structures by performing a section of code, incrementing some sort of counter and then comparing this with a known upper value. This will be the subject of the next chapter but in this one, we will see how we can simulate the "IF ... THEN ... ELSE
" structure of high-level languages. In addition, we will examine the shift operations which allow us to "slide" the bits in a register to the left or right. This is much more important than, at first glance, it appears to be ...
To enable us to do all of this, you will need to be able to:
Flag Name | Comments |
Z - Zero Flag | This flag is set if the result of the previous operation was zero. |
S - Sign Flag | If the leftmost bit of the result of an operation is set, this flag will be set. Think back to our discussion of negative numbers in Chapter 2. We saw that in signed numbers a value of "1" in the most significant bit was regarded as the sign for the rest of the bits to be taken as a negative number. So, if the sign flag is set, we can interpret the number, if we wish, as a negative value. |
C - Carry Flag | Let's imagine that we have the value 156 in the register AL and we then use the ADD instruction to add 100 to it. In decimal, that would give us 256 but we know that AL can only hold one byte and a byte encodes numbers in the range 0-255. In this case, the result would be 0 and the carry flag would be set to show "carry one". |
O - Overflow Flag | This one's a little harder to understand. Again, think back to the subject of negative numbers in Chapter 2. It is perfectly possible that, when you add two numbers together, the carry flag could be set, as we discussed above. But if you were regarding the numbers as signed, the result would not, in fact be greater than 255 but the resultant bits would still cause the carry flag to be set. The question is, then, how do we show when the addition of two signed numbers causes an overflow? We've just said it - the overflow flag. Look at the example in Jeremey's help manual. |
P - Parity Flag | The parity flag does not really concern us in this series of articles. It is set if the number of bits in a piece of data are even and cleared if thy are odd. For example, 101010102 would set the flag because there are four "1s" in the data. The use of this flag stems back to the earliest days of data communications with mechanisms like RS232 lines and allowed a basic sort of error checking to be made. |
There are, in fact, another two flags - the Auxiliary Carry flag, which is used in Binary Coded Decimal, and the Direction flag. Neither of these is of interest to us here.
![]() |
![]() |