Skip to main content
main-content

Inhaltsverzeichnis

Frontmatter

1. Inside the Computer

Abstract
Computing, like many other processes, has three main parts: \(input\quad -\quad processing\quad -\quad output\)
Anthony Woods

2. Assembly Language Programs

Abstract
The most convenient way of writing and running assembly language programs on the ZX81 computer is to use an assembler program to carry out the translation from assembly language to machine code. A suitable assembler program is ZXAS. If an assembler is not available, programs can be translated manually; this process is known as hand assembly and is described in detail in Appendix B. After the program has been translated into machine code it can be run by the computer and any errors in the program can be found and corrected. This is a more difficult process with assembly language programs than it is with BASIC programs. The process can be made easier by the use of a program which helps you to examine what is happening inside the computer while your program is running. A program of this type is called a debugger and for the ZX81 the program ZXDB performs this invaluable task.
Anthony Woods

3. Some Simple Instructions

Abstract
In this chapter we shall look at the operations of loading registers, adding to the value in the accumulator, subtracting from the value in the accumulator, incrementing and decrementing the value in a register, and taking the negative of the value in the accumulator. These instructions allow us to carry out simple arithmetic with 8-bit numbers.
Anthony Woods

4. Subroutines and Output to the Screen

Abstract
Subroutines are a very important feature of programming, especially assembly language programming, which are usually left until near the end of any course on programming. Because of their importance, this chapter will show why they are used and how to use them. It will not look at the details of how they work; this will be covered in chapter 8.
Anthony Woods

5. Unconditional Jumps and Keyboard Input

Abstract
You have so far only seen programs which carry out their instructions in the sequence in which they are written. However, as you know from your BASIC programs, it is usual to include in programs some instructions which allow the sequence to be changed. This is done by jumping from the present instruction in the program to some other instruction. There are two types of jump instructions — unconditional and conditional. This chapter will only look at unconditional jumps. An unconditional jump has the form
$$JP\;\,nn$$
where nn is the address of a memory byte. The instruction causes the computer to take the instruction at address nn as the next instruction. Because it can be quite difficult to calculate the address for the required jump, the address to be jumped to is usually specified to the assembler program by means of a label, as shown in figure 5.1.
Anthony Woods

6. Conditional Jumps and Comparisons

Abstract
Inside the Z80 microprocessor there is a register, the F register, which is only used to hold information concerning the result produced by the last arithmetic or logic instruction. Of the eight bits in the register only six are used. Figure 6.1 shows the information held in these bits.
Anthony Woods

7. Counting Loops

Abstract
There are many different forms of loops used in programs. The indefinite loop and the conditional termination loop have already been used and several more forms will be used throughout the book. One of the simplest and most useful is the counting loop. The counting loop allows a sequence of instructions to be executed a set number of times. The program in figure 7.1 is an example of this; it is a program to input and sum four numbers.
Anthony Woods

8. Loops Within Loops

Abstract
A natural follow-on to the loops which have been used so far is to put a loop inside another loop. This type of construction is known as a nested loop. The terms outer loop and inner loop are then used to describe the loop forming the outside of the nest and the loop which is on the inside of the nest. Figure 8.1 shows a program which has two loops, one inside the other. This program outputs four lines of six asterisks. The outer loop uses the C register to count the number of lines and the inner loop uses the B register to count the number of asterisks.
Anthony Woods

9. Carry and Overflow

Abstract
Two conditions, which are of particular importance when performing addition and subtraction, are carry and overflow. They are conditions which affect bits in the flag register so that they can then be tested by conditional jump instructions. The carry and overflow conditions are used as an aid in determining whether an arithmetic operation has been carried out correctly.
Anthony Woods

10. Multiplication and Division

Abstract
Shift instructions allow the bits of a register, or memory byte, to be moved 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, as a pattern of binary digits when the shift is made. Arithmetic shifts treat the contents of the register, or memory byte, as a signed number, so that the effect of a left shift is equivalent to multiplication by two and a right shift is equivalent to division by two. The Z80 microprocessor in the ZX81 has one logical and two arithmetic shift instructions.
Anthony Woods

11. The Logical Bits

Abstract
The Z80 microprocessor has an extensive range of instructions which use data bit by bit. There is a series of bit instructions which allows individual bits of a register, or memory byte, to be tested, set to 1 or reset to 0. The number of the bit used in the operation is specified in the instruction; for this purpose the bits are numbered right to left as in figure 11.1. All bit instructions operate on any of the 8-bit registers, or a memory byte pointed to by HL, IX or IY.
Anthony Woods

12. Rotate Instructions and Parity

Abstract
Rotate instructions are similar to shift instructions, except that the bit which is moved out of one end is carried round, and put into the other end, hence the name rotate.
Anthony Woods

13. Multiple Byte Arithmetic

Abstract
So far we have only been concerned with single byte arithmetic, that is, arithmetic using 8-bit operands and giving 8-bit results. The range of numeric values which can be manipulated by 8-bit arithmetic is small, so we often need to use more than one byte to hold our numbers; we then need to carry out arithmetic using sixteen or more bits. The microprocessor inside the ZX81 has assembly language instructions which allow 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.
Anthony Woods

14. Block Transfer and Search

Abstract
The microprocessor in the ZX81 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 bytes. One interesting use of these instructions is to enable a graphics display to be stored in memory and then transferred to the display file when it is to be displayed on the screen.
Anthony Woods

15. Decimal Arithmetic

Abstract
Up to now we have only considered the binary representation of numbers, and arithmetic has involved signed and unsigned binary numbers. However, the microprocessor in the ZX81 also caters for another representation of numbers, called Binary Coded Decimal, or BCD for short.
Anthony Woods

16. Miscellaneous Instructions

Abstract
There are several instructions which have not yet been considered because they are only used rarely. For completeness, they are discussed briefly in this final chapter.
Anthony Woods

Backmatter

Weitere Informationen