eZ80 College Course, Semester 1, Week 5
Divider

Arithmetic, Logical, and Bit Manipulation Instructions

In this section we continue our examination of the eZ80 CPU instruction set. Again, recall that detailed information about each instruction can be found in the following document:

Arithmetic Instructions

The Arithmetic instructions provide the eZ80 CPU with its number-crunching ability. With all basic mathematical operations except division, the Arithmetic instructions provide the means to work with binary and BCD numbers (the BCD is limited to two digits 0-9 in the accumulator after the DAA instruction is used).

Logical Instructions

The Logical instructions provide us with the Boolean operations necessary for making decisions, as well as methods of manipulating bits in registers or memory.

Bit Manipulation Instructions

Bit manipulation involves testing, clearing, or setting a bit in a register or memory location. While these operations can be performed with other eZ80 instructions, the BIT, RES, and SET instructions do it easier with less code.

Suppose you want to clear the MSB of register B. One way is to use these instructions:

ld  a,b
and a,7fh
ld  b,a

An even simple and more straightforward way is to use the RES instruction like this:

res 7,b

Similar groups of instructions used to set and test bits can also be replaced with a single SET or BIT instruction. Details of the bitwise instructions available on the eZ80 are found here.

In the experiment of Semester 1 Week 6 the Bit Manipulation instructions are used to assist with simple control loops.

Rotate and Shift Instructions

The Rotate and Shift instructions are used to move bits left or right within a register or memory location. Arithmetic shift right is provided for signed binary numbers, while the logical shifts are for unsigned numbers. BCD rotations are also possible, where groups of four bits are moved between the accumulator and a memory location.

All of the rotate and shift instructions are summarized in the following table:

Instruction Operation
RL (HL)
RL (IX/Y+d)
RL r
RLA
RLC (HL)
RLC (IX/Y+d)
RLC r
RLCA
RLD
RR (HL)
RR (IX/Y+d)
RR r
RRA
RRC (HL)
RRC (IX/Y+d)
RRC r
RRCA
RRD
SLA (HL)
SLA (IX/Y+d)
SLA r
SRA (HL)
SRA (IX/Y+d)
SRA r
SRL (HL)
SRL (IX/Y+d)
SRL r

Troubleshooting Techniques

Now that we have seen most of the eZ80 instruction set, let us spend a moment on some tips designed to keep the software development process running smoothly.

It may be a good idea to keep a logbook of the problems you encounter working with assembly language. Until you have seen the same problem enough times, or learn how to avoid it, keeping track of the problem and its solution will save a lot of time and effort should you encounter it again.

Last modified December 2003