Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

394 Shown below is an assembly language equivalent of the ‘read a key within one second’ example which we have already seen in BASIC 10 OSBYTE=&FFF4 20 P%=&3500 30 [ 40 LDA#129 50 LDX#100 60 LDY#0 70 JSR OSBYTE 80 RTS 90 ] 100 CALL &3500 The first thing you will notice about the above program is that lines 10, 20 and 100 seem to be BASIC statements. Indeed they are, the program is really a ‘hybrid’. Line 30 tells BASIC ‘assembly language starts here’, line 90 says ‘assembly language finished’. Line 40 says ‘load the accumulator with decimal 129’. Similarly, lines 50 and 60 load the X register with decimal 100 and the Y register with 0.

Line 70 calls OSBYTE, although the machine code assembled from lines 40 to 80 is not actually executed until the program reaches line 100. This description of the program is deliberately brief, but any questions that you may have will be answered in the next chapter. Try typing the program in and running it. You will see that six lines of text appear on the screen (more about that in the next chapter), there is a pause, and then the BASIC prompt reappears. If you run the program again, but press a key immediately after pressing RETURN , you will find that the same thing happens, except that the prompt reappears when you press the key.

In both cases the program doesn’t appear to have done anything! In fact, it has carried out exactly the same processing as the BASIC example, but it hasn’t printed any results out on the screen. This illustrates a disadvantage of making an operating system call from assembly language: there is no direct way of printing out the contents of the 6512 registers. (This isn’t as bad as it sounds because real-life applications of assembly language programs, arcade games for example, rarely require register contents to be printed.) The following program gets around this problem (albeit in a limited and rather unsatisfactory way) by making use of another MOS routine, called OSWRCH:

10 OSBYTE=&FFF4 20 OSWRCH=&FFEE 30 P%=&3500 40 [ 50 LDA#129 60 LDX#100 70 LDY#0