Texas Instruments MSC1210 Zero and Non-Zero Decisions JZ/JNZ, Performing Additions ADD, Addc

Models: MSC1210

1 324
Download 324 pages 20.97 Kb
Page 212
Image 212

Zero and Non-Zero Decisions (JZ/JNZ)

16.16 Zero and Non-Zero Decisions (JZ/JNZ)

Sometimes, it is useful to be able to simply determine if the accumulator holds a zero or not. This could be done with a CJNE instruction, but because these types of tests are so common in software, the 8052 instruction set provides two instructions for this purpose: JZ and JNZ.

JZ will jump to the given address or label if the accumulator is zero. The instruc- tion means jump if zero.

JNZ will jump to the given address or label if the accumulator is not zero. The instruction means jump if not zero.

For example:

JZ ACCUM_ZERO ;Jump to ACCUM_ZERO if the accumulator = 0

JNZ NOT_ZERO ;Jump to NOT_ZERO if the accumulator is not 0

Using JZ and/or JNZ is much easier and faster than using CJNE, if all that is needed is to test for a zero/non-zero value in the accumulator.

Note:

Other non-8052 architectures have a zero flag that is set by instructions, and the zero-test instruction tests that flag, not the accumulator. The 8052, how- ever, has no zero flag, and JZ and JNZ both test the value of the accumulator, not the status of any flag.

16.17 Performing Additions (ADD, ADDC)

The ADD and ADDC instructions provide a way to perform 8-bit addition. All addition involves adding some number or register to the accumulator and leav- ing the result in the accumulator. The original value in the accumulator is al- ways overwritten with the result of the addition.

ADD A,#25h

;Add 25h

to whatever value is in the accumulator

ADD A,40h

;Add contents of Internal RAM address 40h to

 

;accumulator

ADD A,R4

;Add the contents of R4 to the accumulator

ADDC A,#22h

;Add 22h

to the accumulator, plus carry bit

The ADD and ADDC instructions are identical except that ADD will only add the accumulator and the specified value or register, whereas ADDC will also add the carry bit. The difference between the two, and the use of both, can be seen in the following code.

16-18

Page 212
Image 212
Texas Instruments MSC1210 manual Zero and Non-Zero Decisions JZ/JNZ, Performing Additions ADD, Addc