Skip to main content
Top

1981 | Book

Z80 Assembly Language Programming for Students

Author: Roger Hutty

Publisher: Macmillan Education UK

Book Series : Computer Science Series

insite
SEARCH

Table of Contents

Frontmatter
1. The Z80 architecture
Abstract
Computing, like many other processes, has three main parts In a computer system, data (numbers and words) is input by an input device, the processing is performed by a central processing unit and data is output by an output device.
Roger Hutty
2. Accumulator and register instructions
Abstract
In this chapter we shall consider the one-byte operations of loading registers, adding to the accumulator, subtracting from the accumulator, incrementing and decrementing registers and negating the accumulator. All these instructions allow 8-bit arithmetic to be performed.
Roger Hutty
3. Subroutines and display output
Abstract
Subroutines are a very important feature of programming which, unfortunately, are usually left until the end of a programming course. At this stage in the book you will learn why subroutines are used and how to use them, but not how they work. The subroutine mechanism will be covered in a Chapter 7.
Roger Hutty
4. Unconditional jumps and keyboard input
Abstract
Execution of Z80 programs we have looked at so far proceeds sequentially through the instructions, one after another. However, it is possible and, in fact, usual to change the sequence of execution for one reason or another. Jump instructions allow the execution of a program to take different paths through the instructions. There are two types of jump instructions — unconditional and conditional. We will look at conditional jumps in the next chapter.
Roger Hutty
5. Flags, conditional jumps and the CP instruction
Abstract
The Z80 has an 8-bit flag register which is used to contain information regarding the result produced by the last executed instruction. In fact, only six of the eight bits are used as follows The SIGN FLAG is set to 1 if the result produced by an instruction is negative, otherwise the flag is reset to 0. For example, after execution of the instructions the accumulator will contain −33 and the sign flag will be set to 1.
Roger Hutty
6. Counting loops and the stack
Abstract
There are many different constructions used in looping. We have already used an ‘indefinite loop’ construct (not recommended) and a ‘conditional terminated loop’ construct. We shall consider several more types of loop construct throughout the book, starting now with a ‘counting loop’ construct.
Roger Hutty
7. Nested loops and addressing modes
Abstract
A natural extension of the loops we have used so far is a construction which has a loop within a loop, within a loop, and so on. This type of construction is referred to as nested loops, because each loop nests insides another loop. The terms outer loop and inner loop are used to describe a loop containing another loop, and a loop which is inside another loop, respectively. Program 7.1 shows a program with two loops.
Roger Hutty
8. Carry and overflow
Abstract
Carry and overflow are two conditions which can occur during addition and subtraction. The conditions affect bits in the flag register which can then be tested by conditional jump instructions.
Roger Hutty
9. Bit operations and the index registers
Abstract
The Z80 has an extensive range of bit instructions. The bit instructions allow individual bits of a register or memory byte to be tested (for 0 or 1), set to 1 and reset to 0. The number of the bit in the register or memory byte to be used in the operation has to be specified in the instruction and, for this purpose, the bits are numbered right to left starting at 0, as follows All bit instructions operate on any of one of the single registers or a memory byte pointed to by HL, IX or IY.
Roger Hutty
10. Shift instructions, multiply and divide
Abstract
Shift instructions allow the bits of a register or memory byte to be shifted one bit place to the left or to the right. There are two types of shift instructions — logical and arithmetic. Logical shifts consider the contents of the register or memory byte to be just a bit pattern when the shift is made. Arithmetic shifts consider the contents of the register or memory byte to be a signed number so that when the shift is made the number is arithmetically multiplied by two (left shift) or divided by two (right shift). The Z80 microprocessor has one logical instruction and two arithmetic instructions. Descriptions of the shift instructions are included in Table C.8 in Appendix C.
Roger Hutty
11. Logical operations and macros
Abstract
There are several Z80 logical instructions which allow logical operations to be performed between corresponding bits in the accumulator and an 8-bit operand.
Roger Hutty
12. Rotate instructions and parity
Abstract
Rotate instructions are similar to shift instructions except that the bit shifted out of one end is shifted into the other end — hence, the name rotate.
Roger Hutty
13. 16-bit and multiple byte arithmetic
Abstract
So far we have been concerned with 8-bit arithmetic — that is, 8-bit operands and 8-bit results. The range of numeric values which can be manipulated by 8-bit arithmetics is small and so we may need to use 16-bit arithmetic and more. The Z80 microprocessor has instructions which allows 16-bit arithmetic to be performed directly. These instructions can also be used to provide 32-bit arithmetic, 48-bit arithmetic and so on. The 16-bit arithmetic instructions also allow additional loop facilities.
Roger Hutty
14. Block transfer and search instructions
Abstract
The Z80 microprocessor has eight very powerful block instructions which allow operations on blocks of consecutive memory bytes. Four of the instructions are block transfer instructions which allow the contents of one block of memory bytes to be transferred to another block of memory; the other four instructions are block search instructions which allow a block of memory bytes to be searched for one of the bytes containing a specified value.
Roger Hutty
15. Decimal arithmetic
Abstract
Up to now, we have only considered the binary representation of numbers in the Z80 microprocessor, and arithmetic has involved signed and unsigned binary numbers. However, the Z80 microprocessor caters for another representation of numbers — Binary Coded Decimal, or BCD for short.
Roger Hutty
16. Miscellaneous instructions
Abstract
There are several instructions which have not yet been considered because they are rarely used or because they are beyond the scope of this book. However, for completeness, they are discussed briefly in this final chapter.
Roger Hutty
Backmatter
Metadata
Title
Z80 Assembly Language Programming for Students
Author
Roger Hutty
Copyright Year
1981
Publisher
Macmillan Education UK
Electronic ISBN
978-1-349-06155-6
Print ISBN
978-0-333-32295-6
DOI
https://doi.org/10.1007/978-1-349-06155-6