EasyManuals Logo

Atmel 8051 User Manual

Atmel 8051
113 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #13 background imageLoading...
Page #13 background image
Atmel 8051 Microcontrollers Hardware Manual 1-12
Rev. 4316B–8051–02/04
In this example, FLAG is the name of any addressable bit in the lower 128 or SFR
space. An I/O line (the LSB of Port 1, in the case) is set or cleared depending on
whether the flag bit is 1 or 0.
The Carry bit in the PSW is used as the single-bit Accumulator of the Boolean proces-
sor. Bit instructions that refer to the Carry bit as C assemble as Carry-specific
instructions (CLR C, etc.). The Carry bit also has a direct address, since it resides in the
PSW register, which is bit-addressable.
Note that the Boolean instruction set includes ANL and ORL operations, but not the XRL
(Exclusive OR) operation. An XRL operation is simple to implement in software. Sup-
pose, for example, it is required to form the Exclusive OR of two bits:
C= bit1 XRL bit2
The software to do that could be as follows:
MOV C, bit1
JNB bit2, OVER
CPL C
OVER: (continue)
First, bit 1 is moved to the Carry. If bit 2 = 0, then C now contains the correct result. That
is, bit 1 XRL bit2 = bit1 if bit2 = 0. On the other hand, if bit2 = 1 C now contains the com-
plement of the correct result. It need only be inverted (CPL C) to complete the operation.
This code uses the JNB instruction, one of a series of bit-test instructions which execute
a jump if the addressed bit is set (JC, JB, JBC) or if the addressed bit is not set (JNC,
JNB). In the above case, bit2 is being tested, and if bit2 = 0 the CPL C instruction is
jumped over.
JBC executes the jump if the addressed bit is set, and also clears the bit. Thus a flag
can be tested and cleared in one operation.
All the PSW bits are directly addressable, so the Parity bit, or the general purpose flags,
for example, are also available to the bit-test instructions.
1.8.1 Relative Offset
The destination address for these jumps is specified to the assembler by a label or by an
actual address in Program Memory. However, the destination address assembles to a
relative offset byte. This is a signed (two’s complement) offset byte which is added to the
PC in two’s complement arithmetic if the jump is executed.
The range of the jump is therefore -128 to +127 Program Memory bytes relative to the
first byte following the instruction.

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Atmel 8051 and is the answer not in the manual?

Atmel 8051 Specifications

General IconGeneral
BrandAtmel
Model8051
CategoryMicrocontrollers
LanguageEnglish

Related product manuals