main-content

### 1. Preliminary Ideas

Abstract
In its simplest form, a computer can be considered in four sections: input, output, microprocessor and internal memory. Figure 1.1 shows the interrelationship
Ian Birnbaum

### 2. Assignments

Abstract
The first and the most important of the ‘Other Registers’ in figure 1.4 that we will consider is the Accumulator. This is an 8-bit register, like all the ‘Other Registers’, and communicates with both the address bus and the data bus. The principal feature of the accumulator is that all arithmetic and most logical operations must take place using it. So, for example, if two numbers are to be added, one of them must be in the accumulator. The result of this addition will also be placed in the accumulator.
Ian Birnbaum

Abstract
At the beginning of the previous chapter we mentioned that all arithmetic must take place in the accumulator. The part of the microprocessor used to perform the arithmetic is called the Arithmetic Logic Unit (Arithmetic Unit or ALU for short). Figure 3.1 shows the simplified architectural details.
Ian Birnbaum

### 4. Decision-making in Assembly Language

Abstract
In the previous chapter (section 3.1) reference was made to a new register: P, the status register. Figure 3.1 shows it in relation to the rest of the architecture that we have met so far. Each of the eight bits of this register has a separate function: each operates as a flag, indicating that certain conditions have or have not occurred. If the bit is 1, the flag is said to be set, if the bit is 0, the flag is said to be clear (or sometimes reset). We have already considered two flags: C, the carry flag, and V, the overflow flag. Figure 4.1 shows all the flags in the P register. There are five new ones, N, B, D, I, Z. Of these, we will defer discussion of B, D and I until later chapters.
Ian Birnbaum

### 5. Loop Structure in Assembly Language

Abstract
BBC BASIC has two loop structures: the FOR…NEXT loop and the REPEAT…UNTIL loop. These structures are essential components of most realistic programs in BASIC, and the same is true of assembly language. However, in assembly language the structures do not come ready made as in BASIC, so we need to develop methods of building them up from the component instructions available. In doing this, we will also create a third important structure, regrettably missing in BBC BASIC: this structure we will term the REPEAT WHILE loop. The difference between REPEAT…UNTIL and REPEAT WHILE is that the former will always be executed at least once, since the exit is at the end; the latter need not be executed at all, since the exit is at the beginning.
Ian Birnbaum

Abstract
Consider the following fragment of a BASIC program
Ian Birnbaum

Abstract
Let us consider how we might move a section of memory which is more than 256 bytes long. In section 5.4(c) we saw a general method of performing a FOR…NEXT loop with more than 256 cycles. We can modify that idea for our present task. Listing 7.1 shows the program.
Ian Birnbaum

### 8. Multiplication and Division

Abstract
Let us begin this chapter by reviewing the familiar algorithm for multiplying two base 10 numbers together.
Ian Birnbaum

### 9. The Stack: Subroutines and Interrupts

Abstract
In section 6.5 we met the idea of a queue. This was described as a FIFO structure, in that the first item to enter the queue was the first to be taken from it. The contrasting structure to this is the stack, for this is a FILO data structure. Thus, the first item on the stack is the last to be taken from it; and conversely, the last item on the stack is the first to be taken from it.
Ian Birnbaum

### 10. Some Utility Programs

Abstract
The principal purpose of this chapter is to draw together all the preceding ideas in the past nine chapters into a series of example programs. As a bonus, these programs will be found to be particularly useful to you in your work with BASIC and with assembly language. In this sense they may be called utility programs. This is not to imply that programs in the rest of the book are not useful (for example listing 8.6 is certainly of use if you have a printer). But the earlier programs were chosen to make specific pedagogical points: the programs here try to draw together all the points already made. If you purchase the cassette available with this book you will find some other utility programs. It contains an assembly program to find and list the lines containing any section of code in a BASIC program (FIND-CODE) and another to replace any section of code by any other section in a BASIC program (REPLACE).
Ian Birnbaum