OVERVIEW: Z80 INSTRUCTION SET par 2

Example 6.1

Write instructions in English-like statements to load the two data bytes 53H and F5H in registers A and B, respectively, and add the two bytes. Translate these statements into Z80 assembly language. I1lustrate the contents of registers af­fected in the programming model after the execution of each instruction and the status of the Carry and Zero flags.

z80 Interfacing and programming-44_11

This example does not show how to translate these instructions into binary code or how to execute them; this is discussed in the next section. Assuming these instructions are executed by the Z80 microprocessor, Figure 6.4(a) shows the con­tents of registers A and B after the execution of the first two instructions. The next instruction adds the contents of registers A and B; the sum is 148H• Figure 6.4(b) shows the accumulator with 48H and the CY flag set in the flag register. Please note that the flags are not affected by the Load or Copy instructions.

LOGIC OPERATIONS

The instructions related to logic operations can be divided into three groups logic functions (AND, OR, etc.), bit rotations or shifts and comp arisons (less than, greater than, and equal to) of data bytes.

· Logic Functions. Any 8-bit number, the contents of a register, or the contents of a memory location can be ANDed, ORed, or Exclusive ORed with the con­tents of the accumulator. The result is stored in the accumulator, and the flags are affected by the result.

Examples:

Ø Logically AND the contents of register B with the contents of the accumulator. → AND B

Ø Exclusive OR the contents of register B with the contents of the accumulator . →XOR B

· Shift and Rotate. Each bit in the accumulator, in the registers, or in memory can be shifted either left or right by one position.

Examples:

Ø Rotate the contents of the accumulator Right through Carry flag. → RRA

Ø Rotate left the contents of register B → RLC B

· Compare. Any 8-bit number, the contents of a register, or memory can be com­pared for equality, greater than, or less than with the contents of the accumu­lator. The result of the comparison is indicated by appropriate flags.

Examples:

Ø Compare the contents of register B with the contents of the accumulator. → CP B

Ø Compare the data byte 97 H with the contents of the accumulator. →CP 97H

BIT MANIPULATION

The bit manipulation instructions can be classified into two groups: bit test and bit set/reset.

· Bit Test- Any one of the eight bits in a register, accumulator, or memory can be verified as 0 or I, and the Z flag will be modified accordingly.

Example:

Ø Check bit D7 in register B. → BIT 7, B

· Bit Set/Reset– Anyone of the eight bits in a register, accumulator, or memory can be set or reset.

Example:

set bit d5 in the accumulator. →SET5, A

Reset bit D2 in register B.→RES2, B

BRANCHING OPERATIONS

This group of instructions alters the sequence of program execution either con­ditionally or unconditionally.

· Jump. The sequence of program execution can be altered either conditionally or unconditionally. When a conditional Jump instruction is used, the micropro­cessor checks the specified flag, and if the condition is true, the execution se­quence is altered; otherwise, the next instruction is executed. The destination location to which the program should be directed can be specified directly or relative to the contents of the program counter. These instructions are critical to the decision-making process in programming.

Examples:

Ø After an operation(such as an addition), → JP C, 2050H

if CY flag is set, jump to location 2050H

If Zero flag is not set, jump forward by 15 locations. →JR NZ, 0FH

· Call/Return. These instructions change the sequence of a program by calling a subroutine or returning from a subroutine. The conditional Call and Return in­structions check for appropriate flags.

Examples:

Ø Go to subroutine located at 2050H →CALL 2050H

Go to Subroutine located at 2070H if Z flag is set. → CALL Z, 2070H

· Restart. These instructions are used to change the program sequence to one of eight restart locations on memory page 00.The instructions are generally used with interrupts.

Example:

Ø Call location 0028H• → RST 28H

MACHINE CONTROL OPERATIONS

These instructions control microprocessor operations such as Halt and Interrupt.

Examples:

Ø Suspend execution of instruction. → HALT

Disable interrupts by resetting the Interrupt Enable flip-flops. → DI

6.2.3 Review of Important Concepts

Our intent here is to give you an overall view of the instruction set and the ca­pability of the Z80 microprocessor. The Z80 has 158 instruction types with 694opcodes. These numbers can be overwhelming and intimidating to a beginner. Fortunately, as you begin to use instructions, a logical pattern will begin to emerge. At this point, the important concepts to remember are as follows:

1. Each instruction has two parts: opcode and operand. The opcode specifies the task, and the operand specifies either data or where data are located.

2. Instructions can be classified into four groups according to their word length: one to four bytes.

3. In an instruction, when the data Source and the destination are explicitly spec­ified, the destination is shown first and the source second.

4. When an operand is a l6-bit address (or data).it is specified in a reversed order: the low-order byte first, followed by the high-order byte.

5. Instructions are stored in memory in binary format; the microprocessor neither reads nor understands mnemonics or hexadecimal numbers.

6. The number of memory locations required to store an instruction is determined by the word length. For example, a 3-byte instruction would require three memory locations.

Leave a comment

Your email address will not be published. Required fields are marked *