Mnemonic
Op Code
Always
BRA
if carry SET
BCS
if carry CLEAR
BCC
if zero
BEQ
if not zero
BNE
if minus
BMI
if plus
BPL
if overflow SET
BVS
if overflow CLEAR BVC
CC
20
25
24
27
26
2B
2A
29
28
C=
C=
Z=1
Z=
N=1
N=0
V=
V=0
1
0
0
1
BRANCH INSTRUCTIONS
The instruction BRA, is an unconditional branch. The
program always jumps or branches when the BRA
(Branch Always) instruction occurs.
The remaining instructions are conditional branches;
they take the branch only if the condition codes are
set properly.
Each branch instruction is accompanied by an
offset, a number that is added to the current value
of the Program Counter to determine where the P
will go if it branches.
Branch instructions skip over a part of the program
to a location that is relative to the program counter.
Example 11
At a point in a program the H, I, and C bits of the CCR
should be SET and the
N, V, and Z bits should be CLEAR. Write a sequence of
instructions to set the
bits accordingly.
SOLUTION
The CCR should look like this
11110001
lt can be forced into this configuration by the following
instructions:
Code
Mnemonic
Comments
86 F1
LDAA #$F1
Load desired contents of
CCR into A
06
TAP
Transfer A to CCR
Calculating Offsets
A BRANCH instruction for the 6800 consists of the
BRANCH op code in one byte and an 8-bit offset in the
following byte.
The offset is a 2s-complement number that is added to
the address.
If N is the location of the branch instruction and T is the
target address (the address the program will jump to),
the following formula can be used to calculate the offset:
Offset: T (N + 2)
Note that both forward and backward branches can be
accommodated.
Backward branches have negative offsets.
Example 12
The op code of the branch instruction is in $011A.
What should the offset be if the program must jump
to $0150?
SOLUTION
From the equation we obtain
$011A + 2 = $011C
Offset = $0150 - $011C = $34
Thus the program segment would be as follows:
011A XX
(branch op code)
011B 34 (offset)
Example 13
The op code of the branch instruction is in $011A.
What should the offset be if the program must jump
to $00EA?
SOLUTION
From the formula
$011A + 2 = $011C
Offset = $00EA - $011C = $FFCE
For an 8-bit negative offset the $FF is discarded and
the program is as follows:
011A XX
(branch op code)
011B CE
(offset)
Note that the offset is a negative number ($CE) and
the program branches backward from $11C to $EA.
Example 13
Express the decimal number 630910 in BCD form.
SOLUTION
From the code conversion table, we find that
6 = 0110
3 = 0011
0 = 0000
9 = 1001
The number 6309 is expressed by stringing these
bits together:
(630910):0110 0011 0000 1001
Example 14
Accumulators A and B contain the decimal numbers
48 and 79, respectively. They are added by an ADD
accumulator (ABA) instruction. What is the result,
and what are the conditions of the C and H bits after
the addition?
SOLUTION
The 6800 adds 48 and 79 as though they were hex
digits, placing the sum, C1, in accumulator A. At the
end of the addition the H bit is SET (because the
sum of 8 and 9 produces a carry), but the carry bit
is CLEAR because the sum of the two most
significant digits is less than 16.
DAA Instruction
The result of Example 14 (48 + 79 = C1) is
unsatisfactory if decimal arithmetic is being used.
This instruction must be followed by a Decimal
Adjust Accumulator (DAA) instruction to convert
the hex result to the correct BCD result.
lt examines four parts of the result:
1.
2.
3.
4.
The
The
The
The
lower half-byte
upper halfbyte
H bit
C bit
Example 15
What happens if a DAA instruction is added to
Example 14?
SOLUTION
ln Example 14, the sum was C1. The DAA notes the
following:
1. The lower half-byte is 0-3.
2. The H bit is SET.
3. The upper half-byte is A-F.
4. The C bit is CLEAR.
The DAA adds 66 to the result and SETs the C bit.
After the DAA, A contains C1 + 66 = 127 and the
carry bit is SET, which indicates a carry (a weight of
100 in decimal arithmetic). Therefore, the BCD sum
is 127, which is correct.
Example 16
The decimal numbers 2948 and 4957 are in locations
$20, $21 and $22, $23, respectively. Write a program to
add them and store the BCD result in locations $24 and
$25.
ADDR OBJECT
MNEMONICS
COMMENTS
C000
96 21
LDA $21 Lead LS byte of Augend
C002
9B 23 ADDA $23 Add LS byte of Addend
C004
19
DAA
Adjust for half carry, if any
C005
97 25 STAA $25
Store results in 25
C007
96 20 LDAA $20 Load MS byte of Augend in
A
C009
99 22 ADCA $22
Add W-C MS byte of
Addend
COOB
19
DAA
Adjust result
COOC
97 24 STAA $24
Store MS byte
Example 17
Subtract 19,307 from 28,652.
SOLUTION
The 9s complement of 19,307 is 80,692. Adding this to
the minuend, we obtain
(minuend) 28,652 (original number)
(subtrahend)
80,692 (9s complement)
109,344
Removing the most significant t and adding it to the
least significant digit yields
Example 18
Subtract 35 from 82 using the method just
described. Assume that B2 is in $20 and 35 is in
$22.
SOLUTION
The correct answer, 47, appears in A at the end of
the program. Some adjustments are required in the
program if multiple-byte subtraction or the
possibility of negative results are to be allowed.
ADDR
OBJECT MNEMOMCS
COMMENTS
C000 86 99
LDAA #$99 Make 9s Complement
C002 90 22
SUBA $22
Get Subtrahend
C004 4C
INCA
Make 10s Complement
C005 9B 20
ADDA $20 Add other number
C007 19
DAA
Decimal Adjust