BBC MASTER GUIDES

   MASTERING ASSEMBLY CODE

   RICHARD VIALLS



   CONTENTS

Preface

5

1

Assembly language programming
6
Number systems7
The memory13
The CPU15
Commands17
Addressing modes21
Conditional branches24
The index registers26
Logical commands39
Indexed indirect addressing42

2

The operating system
45
Useful OS routines45
Memory usage51

3

Pure machine code
55
Addressing modes56
A machine code monitor60

4

Interrupts
84
The system VIA87
Events97
BRK100

5

A few ways to protect your programs
103
Locked tapes files104
Unlistable programs105
Disc tricks108

6

The keyboard
113
A BASIC input routine114
A machine code input routine114
The BREAK key120

7

General graphics
123
The graphics registers123
The video ULA123
Screen splitting128
Screen swapping135
A BASIC swap139
Three-dimensional graphics143

8

Fill routines
149
A BASIC fill150
A machine code fill159
A faster fill167

9

Screen dumps
180
A simple BASIC dump180
A machine code equivalent184
A colour-as-tone dump188
A miniature dump199

10

Sprite graphics
216
A BASIC sprite routine217
A machine code sprite routine222
Moving sprites230
The flicker licker239
Using the mover252
Anyone for tennis?255

Appendix A

276
Two's-complement table

Appendix B

278
Assembler commands and op-codes

Appendix C

279
Op-codes and assembler commands


   PREFACE


   This book is aimed at the programmer who has become proficient in BASIC and wants to explore the realms of machine code. The first section of the book sets out to give a detailed description of assembly language programming. However, it is impossible to teach someone to program creatively and professionally. The second section of the book discusses techniques and gives a series of examples of the uses of machine code. It is hoped that, by examining these programs in detail, you will begin to think in the ways that produce a good machine-code programmer.
      Don't assume that the programs in this book are at a height of perfection. There are probably a number of improvements that can be made to them. Don't just use the programs in this book without thought. If, for example, you write an arcade game don't just use the sprite routine at the end of chapter ten - study that routine and then either write your own or adapt that routine and then either write your own or adapt it to suit your particular needs. This will not only produce better programs, but should also help to make you a better programmer.
      The overall message of this book is that a professional programmer is a perfectionist and will do everything within his power to improve a program to its limits.