The following example demonstrates using two negative numbers: There is a borrow into bit positions 7 and 6 the carry flag is set to I, and the OV flag is cleared. When numbers of like sign are subtracted, it is impossible for the result to exceed the positive or negative magnitude limits of +I 27d or - I 28d, so the magnitude and sign of the result do not need to be adjusted, as shown in the following example: The magnitude of the result is in true form.Īs is the case for addition, two combinations of unsigned numbers are possible when subtracting: subtracting numbers of like and unlike signs. The C flag is set to 0, and the OV flag is set to 0. The reverse of the example yields the following result: The 2's complement of the result is 085d. The C flag is set to I, and the OV flag is set to 0. The following example demonstrates subtraction of larger number from a smaller number: The range of numbers is from positive 255d (C = 0, A= FFh) to negative 255d (C = I, A= 0th). These are not signed numbers, as all eight bits are used for the magnitude. The result will be in true form, with no borrow if the source number is smaller than A, or in 2's complement form, with a borrow if the source is larger than A. If a multi-byte subtraction is done, the C flag is cleared for the first byte and then included in subsequent higher byte operations. The OV flag indicates results that must be adjusted whenever two numbers of unlike signs are subtracted and the result exceeds the planned signed magnitudes.īecause the C flag is always subtracted from A along with the source byte, it must be set to 0 if the programmer does not want the flag included in the subtraction. The carry flag is now thought of as a borrow flag to account for situations when a larger number is subtracted from a smaller number. As in the case for addition, the OV Flag is the XOR of the borrows into bit positions 7 and 6.Īgain, depending on what is needed, the programmer may choose to use bytes as signed or unsigned numbers. The OV flag is set if there is a borrow into bit 7 and not bit 6 or if there is a borrow into bit 6 and not bit 7. The AC flag is set if a borrow is needed into bit 3 and reset otherwise. Note that the C flag is set if a borrow is needed into bit 7 and reset otherwise. SUBB the contents of the address in Rp and the C flag from A put the result in A Subtract Rr and the C flag from A put the result in A Subtract the contents of add and the C flag from A put the result in A Subtract immediate number n and the C flag from A put the result in A The following table lists the subtract mnemonics. The commands treat the carry flag as a borrow and always subtract the carry flag as part of the operation. All four addressing modes may be used for source addresses. Register A is the destination address for subtraction. The 8051, however, has commands to perform direct subtraction of two signed or unsigned numbers. Subtraction can be done by taking the 2's complement of the number to be subtracted, the subtrahend, and adding it to another number, the minuend.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |