MC 68000 MACHINE LANGUAGE COURSE PART VII by Mark van den Boer
I would like to dedicate this part to Willeke, who gives Richard
sleepless nights and the inspiration to write even more exciting
issues of ST NEWS. I only saw Willeke on photograph, but she must
be a fine girl. In my opinion there are three qualities which a
girl must have, to qualify as a fine girl. These are: 1) like
Queensrÿche, 2) like ST NEWS (no, she doesn't have to like this
particular machine language course).
Now, you're all anxious to know the third quality, aren't you? If
you think you know the third one, send your answer to ST NEWS. A
bottle of wine will be raffled among the persons who gave the
right answer. There will be another bottle for the most original
answer!
Bit Manipulation instructions
Instruction: BTST
Syntax: BTST Dn,<ea> or BTST #,<ea>
Data sizes: only byte when <ea> is an address. Only long when
<ea> is a data register.
Condition codes affected:
X not affected
N not affected
Z set if the result is zero, cleared otherwise
V not affected
C not affected
Addressing modes allowed:
Destination:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
w(PC)
b(PC,Rn)
# (only when source is Dn)
Function: Test a single bit of an effective address operand. Bits
are numbered from 0 to 31, where 0 is the least
significant bit (you could use this instruction to test
if a number is odd). This instruction is useful when
specific bits of an operand have to be checked. E.g.
when reading joystick information one could test with a
single instruction whether the fire-button was pressed
or not. Compared to the 6502 and 6809 this instruction
(in fact all bit manipulation instructions) are a step
forward, since with these older processors one had to
put the data in a register first, then filter the bit
with an AND-operation and then the Z-bit in the status
register was at last set. Viva el 68000!! Since this
instruction has the rather odd property of only working
on byte and long operands it is important that you
remember what I wrote in a previous part about
specifying data sizes.
Examples:
Instruction Before After
BTST.B #5,$345678 $345678 $345678 contains
contains $78 $78
Z-bit is 1
BTST.L d0,d1 d0=0 d0=0
d1=$12345678 d1=$12345678
Z-bit is 0
Instruction: BCLR
Syntax: BTST Dn,<ea> or BTST #,<ea>
Data sizes: only byte when <ea> is an address. Only long when
<ea> is a data register.
Condition codes affected:
X not affected
N not affected
Z set if the result is zero, cleared otherwise
V not affected
C not affected
Addressing modes allowed:
Destination:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
w(PC)
b(PC,Rn)
# (only when source is Dn)
Function: Bit test and CLeaR. First tests the bit to be cleared
and sets the Z-bit accordingly, then clears the
specified bit.
Examples:
Instruction Before After
BCLR.B #5,$345678 $345678 $345678 contains
contains $78 $58
Z-bit is 1
BCLR.L d0,d1 d0=0 d0=0
d1=$12345678 d1=$12345678
Z-bit is 0
Instruction: BSET
Syntax: BSET Dn,<ea> or BSET #,<ea>
Data sizes: only byte when <ea> is an address. Only long when
<ea> is a data register.
Condition codes affected:
X not affected
N not affected
Z set if the result is zero, cleared otherwise
V not affected
C not affected
Addressing modes allowed:
Destination:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
w(PC)
b(PC,Rn)
# (only when source is Dn)
Function: Bit test and SET. First tests the bit to be set and sets
the Z-bit accordingly, then sets the specified bit. This
instruction and the BCLR instruction can be used as
alternatives to the TAS-instruction.
Examples:
Instruction Before After
BSET.B #5,$345678 $345678 $345678 contains
contains $78 $78
Z-bit is 1
BSET.L d0,d1 d0=0 d0=0
d1=$12345678 d1=$12345679
Z-bit is 0
Instruction: BCHG
Syntax: BCHG Dn,<ea> or BCHG #,<ea>
Data sizes: only byte when <ea> is an address. Only long when
<ea> is a data register.
Condition codes affected:
X not affected
N not affected
Z set if the result is zero, cleared otherwise
V not affected
C not affected
Addressing modes allowed:
Destination:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
w(PC)
b(PC,Rn)
# (only when source is Dn)
Function: Bit test and CHanGe. First tests the bit to be changed
and sets the Z-bit accordingly, then changes the
specified bit.
Examples:
Instruction Before After
BCHG.B #5,$345678 $345678 $345678 contains
contains $78 $58
Z-bit is 1
BCHG.L d0,d1 d0=0 d0=0
d1=$12345678 d1=$12345679
Z-bit is 0
Binary Coded Decimal (BCD) instructions
To understand this instructionclass we must first know what a BCD-
digit is. It is a representation of decimal digits in an array of
bytes (array may be of length 1 or greater). In every byte the
decimal number 0 to 99 can be represented. This is done as
follows: a byte can be divided into two four-bit parts, called
nibbles. In every nibble, one decimal digit is represented. This
implicates that the binary combination 1010 can never occur in BCD
representation, since it isn't in the decimal range from 0 to 9.
The BCD-representation is especially convenient when printing such
a digit, since it doesn't take much calculation to convert it to a
printable character. A disadvantage of the BCD-representation is
that one doesn't use the full storage capacity of a byte or word.
The 68000 has three special BCD-artithmetic instructions.
Instruction: ABCD
Syntax: ABCD Dn,Dn or ABCD -(An),-(An)
Data sizes: byte
Condition codes affected:
X set by carry out of most significant
BCD-nibble, cleared otherwise
N undefined
Z set if the result is zero, cleared otherwise
V undefined
C same as X-bit
Function: Add two BCD-digits. The predecremeting addressing mode
has been provided for computations with multiple
precision BCD-numbers. This implies that the most
significant BCD-numbers must be stored in the lower
memory addresses.
Examples:
Instruction Before After
ABCD.B d0,d1 d0=$53 d0=$53
d1=$32 d1=$85
Instruction: SBCD
Syntax: SBCD Dn,Dn or SBCD -(An),-(An)
Data sizes: byte
Condition codes affected:
X set by carry out of most significant
BCD-nibble, cleared otherwise
N undefined
Z set if the result is zero, cleared otherwise
V undefined
C same as X-bit
Function: Subtract two BCD-digits.
Examples:
Instruction Before After
ABCD.B d0,d1 d0=$53 d0=$53
d1=$32 d1=$21
Instruction: NBCD
Syntax: NBCD <ea>
Data sizes: byte
Addressing modes allowed:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
Condition codes affected:
X set by borrow out of most significant
BCD-nibble, cleared otherwise
N undefined
Z set if the result is zero, cleared otherwise
V undefined
C same as X-bit
Function: Negate a BCD-number. How it functions can be best
described with an example. Let's negate $23. The NBCD
operation yields $77. Now, how did we get this result?
It's easy, just subtract $23 from $99 and you've got it.
Examples:
Instruction Before After
NBCD.B d0 d0=$43 d0=$56
This is the end of part seven. Next time I will deal with all
program flow instruction, such as branches and jumps.
Disclaimer
The text of the articles is identical to the originals like they appeared
in old ST NEWS issues. Please take into consideration that the author(s)
was (were) a lot younger and less responsible back then. So bad jokes,
bad English, youthful arrogance, insults, bravura, over-crediting and
tastelessness should be taken with at least a grain of salt. Any contact
and/or payment information, as well as deadlines/release dates of any
kind should be regarded as outdated. Due to the fact that these pages are
not actually contained in an Atari executable here, references to scroll
texts, featured demo screens and hidden articles may also be irrelevant.