Home » CEEFAX disks » telesoftware3.adl » 17_10_87/T\OSB01
17_10_87/T\OSB01
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » CEEFAX disks » telesoftware3.adl |
Filename: | 17_10_87/T\OSB01 |
Read OK: | ✔ |
File size: | 3372 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
OSBITS- An Exploration of the BBC Micro at Machine Level by Programmer ........................................................... Part 1: The BBC Assembler. BBC BASIC is not the only language you get with your BBC Micro. Built into the BASIC language ROM is an assembler. This is the program that helps you to program using machine code in the same way that the BASIC chip itself in your machine helps you to program in BASIC. Programming a computer in machine code means giving the machine commands in the number code it directly understands. Generally when people talk about programming in machine code they really mean using an assembler. The assembler takes your program, written in 'assembly language', and translates it into machine code. Your original assembly language program is called your 'source code'. Once the assembler has translated your source into machine code and 'assembled' it into memory you no longer need the source. You could throw it away and the chunk of machine code would still do its job all by itself. This can make for faster and more efficient programs than in BASIC for two reasons. Firstly you are writing the program in a form very close to the form in which the machine actually computes. Secondly BASIC stays in the memory and is translated into machine code line by line, command by command, as the program runs. Each command is first turned into machine instructions and then executed, which is time consuming. BBC BASIC is called an 'interpreted' language because it works in this way and the assembler, which does the translation before, rather than during, executing the code is said to be 'compiled'. Generally compiled languages are faster that interpreted ones. Besides wanting a faster program than BASIC there are some things that can only be done in machine code. These are explorations of the very innards of the computer, and we will try some of these later in the course. (Personally I find them more fun that just being able to multiply faster!) It is possible to write the numbers of machine code directly into memory, but actually entering the numbers that tell the computer to add the contents of two memory locations together (for example) is a little error-prone. The assembler, which allows mnemonics and address labels to be used, clarifies this process. Here's our example, which adds 5 to 32 and puts the result into memory location &2021: In machine code In BBC assembler &A9 &20 LDA #&20 Put &20 in the accumulator &18 CLC Clear the carry flag &69 &05 ADC #&05 Add 5 (with carry) &85 &21 &20 STA result Store in memory labelled 'result' (&2021) Now at this stage the LDA/CLC/ADC bits in the middle may be just as obscure as those numbers at the left, however I hope you will agree that LDA is easier to remember than &A9, especially since the code to put a number in the accumulator changes depending on whether the number is put in directly (as here) or loaded from memory, and where in memory, and how you get there! In fact LDA can represent 8 different machine code instructions depending on exactly what you want to do. The assembler sorts out which one is appropriate. (Incidentally, putting a & in front of a number is the way you tell BBC BASIC that a number is in base 16, hexadecimal, instead of base 10, decimal. The accumulator is a number store in the microprocessor with which we can do arithmetic.) LDA is a mnemonic, standing for LoaD the Accumulator. When you run an assembly language program it takes the mnemonics and labels and numbers and converts them into the appropriate machine code and assembles the code into the section of memory you require. The BBC assembler is actually part of BBC BASIC. You use it from BASIC which gives you certain advantages. As we will see later you can use the structure of BASIC to help your assembler programming and you can also use BASIC commands within the assembler. For example if you want to load the accumulator with the ASCII code for a space you can use any of these methods: LDA #&20 LDA #32 LDA #ASC(" ") char%=32 LDA char% They all mean exactly the same thing. The names with which you label memory locations in your assembler program are BASIC variables and follow the same rules. This means you can use long and clear label names if you want to, and since the source code is not needed in the machine when you run the machine code the length of your variable names does not affect the length of your program, or its speed, unlike BASIC. To set up the assembler you should have a piece of BASIC like this: 10 REM Assembler set-up example 20 30 DIM code% 256 40 50 FOR pass% = 0 TO 3 STEP 3 60 P% = code% 70 [OPT pass% 80 ...... the first line of assembler 490 ...... the last line of assembler 500 ] 510 NEXT In line 30 we are allocating some memory in which to assemble the machine code with the alternative use for the DIM statement. The soft loving protection of BASIC is not provided in machine code so the assembler will not allocate memory for you nor will it stop you allocating yourself a silly piece of memory. DIM code% 256 claws back a little help from BASIC by taking 256 bytes of memory starting at the address now held in the variable code%. BASIC will not overwrite this block of memory but it will also not stop you trying to use more than you asked for, although usually the assembly will fail. By silly memory I mean things like accidentally assembling the code into the space in which BASIC is storing your source code, or putting it into a crucial part of the computer's work space. Tricks like this will certainly crash the machine or lose you your source code, but at least the computer won't explode! (Honest!) The code is assembled in two passes, hence the FOR/NEXT loop. This loop, by setting a variable pass% is instructing the assembler to work in a certain way by setting an OPT function (not to be confused with *OPT) at the start of the code. The general idea is that during the first pass the assembler will learn where all the labelled addresses are and in the second pass will place those addresses into the code. During the first pass (with OPT=0) error trapping is turned off; otherwise a label pointing to a piece of memory later in the program would cause a 'no such variable' error. Also the assembler is instructed not to list the assembly to screen in the first pass. In the second pass (with OPT=3) error trapping is turned on and a listing is produced. This listing of the assembly is optional but useful. P%, set equal to code% in line 60, is a BASIC variable which is tied to the value held in one of the microprocessor's registers or number stores, called the program counter. As your code is assembled the assembler sets P% to the address of the next piece of code to be assembled. At the beginning of each pass of the assembly P% is reset to the start of your chunk of memory. That is why P% is set inside the FOR/NEXT loop. When your machine code is executed, fancy machine code jargon for 'run', the real program counter in the microprocessor keeps track of the next command to be carried out. In other words P% keeps track of the addresses of instructions during assembly in the same way the program counter proper does during execution. The square brackets in lines 70 and 500 mark the start and finish of the assembler in your BASIC program. In mode 7 they come out as arrows but mean the same thing. Here's a little more code: 100 .first 110 LDA #32 \ this is a comment 120 CLC:ADC#20:STA &70 At line 100 is a label. It is simply a variable name that will hold the address at this point. The assembler knows it's a label because you have put a full stop in front of it. It is important to remember that in assembler you store a number at an address and the address is often held as a variable. Don't think of the number as being stored in the variable itself. The second part of line 110 is a comment. Anything following a back-slash is ignored by the assembler, like REM in BASIC. Comment your programs liberally! Layout of the assembly program is up to you. It is legal to join statements with colons just like BASIC, but there is no real benefit and it reduces the readability of your source code. You can put labels on the same line as statements but my personal preference is to put the labels on separate lines. The program B/osb01 in this telesoftware transmission is a simple assembler program to print out a message to the screen, a sort of confidence test. This is how it works: 10REM OSbits Module B/osb01 20REM Introduction to the BBC Assembler 30REM Version 1.0 - 17.8.86 40 It's always a good idea to identify your programs and put a version number and date on them. 50 *KEY1MO.3|M|NL.|M 60 I always work in Mode 3 for assembler. This gives plenty of room for comments and also things like the backslash and square brackets come out right, which they don't in Mode 7. So I set up function key 1 to give me a listing in Mode 3. 70 osasci=&FFE3 OSASCI is one of a set of operating system routines built into the BBC micro. It starts at address &FFE3. I'll be dealing with operating system routines in detail later. OSASCI takes the number in the Accumulator (which I'll call A) and sends it to the screen, exactly like VDU ?A would in BASIC if you could read the contents of the accumulator with a ?. (The Accumulator and the X and Y registers are the three places to store and manipulate numbers that are actually within the microprocessor, again more later.) The variable is in lower case because I give all my assembler variables lower case names. I find it aids readability and keeps you completely clear of any problems of clashes with BASIC reserved words. 80 code% = &3000 90 100 FOR pass%=0 TO 3 STEP 3 110 P%=code% 120 130 [OPT pass% 140 LDX #0 150 This sets up the assembly and puts a zero into the X register, which we will use as a counter. Here we will assemble the code at address &3000, which should be safe in Modes 3 and 7, rather than let BASIC find some space. This is simply so that the listing will be predictable when we compare results at the end! 160 .loop 170 LDA text,X LDA text,X is the start of our loop (labelled 'loop') to print out characters taken from a string stored starting at address 'text'. LoaD the Accumulator with the number stored at the address given by 'text'+X. 180 JSR osasci 190 INX Do a VDU ?A and then INcrease X by one. OSASCI is a subroutine and JSR means Jump to SubRoutine and then come back. A subroutine is a self-contained chunk of code (a bit like a procedure in BBC BASIC) starting at the address to which you JSR. It always ends with an RTS command (meaning ReTurn from Subroutine). 200 CMP #13 210 BNE loop 220 CoMPare the contents of A with 13 and then Branch if Not Equal back to 'loop'. (This is only a rough description of what CMP/BNE actually means.) 230 RTS 240 Our little machine code programme behaves as if it were a subroutine called from BASIC so at the end of the active part of the program we ReTurn from the Subroutine. Try deleting this line, you will have to press BREAK and then type OLD to recover after you call your code if you do! 250 .text 260 ] 270 NEXT 280 290 $P%="Hello World, this is machine code!" 300 CALL code% I've put a string just after the machine code by using the $ indirection operator. This puts the string in memory at P% followed by a carriage return (ASCII 13). There are other ways of doing this as we'll see later. Since the label 'text' was at the end of the assembler part of the program it will have the value of P% at this point. Finally we CALL the machine code at code% and, lo, there is the message printed out. Ignoring the comments on each line in the assembler code in B/osb01, it should look like this: >RUN 3000 OPT pass% 3000 A2 00 LDX #0 3002 3002 .loop 3002 BD 0E 30 LDA text,X 3005 20 E3 FF JSR osasci 3008 E8 INX 3009 C9 0D CMP #13 300B D0 F5 BNE loop 300D 300D 60 RTS 300E 300E .text Hello World, this is machine code! > Those numbers down the left, 3000 and so on, are the program counter settings as the assembly was carried out. The numbers between the program counter values and the nmemonics and labels are the actual machine code numbers poked into memory. So you see, you can do it in assembler. I hope you will now know what an assembler is, how it is different from BASIC, and why you might want to use it to write machine code programs. You should know how to set up the BBC assembler as part of a BASIC program and will have assembled a short piece of code which prints out a message. Next week I'll explain some basics of binary arithmetic and we'll try some addition and subtraction.
00000000 0d 4f 53 42 49 54 53 1a 2d 20 41 6e 20 45 78 70 |.OSBITS.- An Exp| 00000010 6c 6f 72 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 |loration of the | 00000020 42 42 43 20 4d 69 63 72 6f 20 61 74 20 4d 61 63 |BBC Micro at Mac| 00000030 68 69 6e 65 20 4c 65 76 65 6c 0d 0d 62 79 20 50 |hine Level..by P| 00000040 72 6f 67 72 61 6d 6d 65 72 0d 0d 2e 2e 2e 2e 2e |rogrammer.......| 00000050 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e |................| * 00000080 2e 2e 2e 2e 2e 2e 0d 0d 0d 0d 50 61 72 74 20 31 |..........Part 1| 00000090 3a 20 20 20 20 54 68 65 20 42 42 43 20 41 73 73 |: The BBC Ass| 000000a0 65 6d 62 6c 65 72 2e 0d 0d 0d 42 42 43 20 42 41 |embler....BBC BA| 000000b0 53 49 43 20 69 73 20 6e 6f 74 20 74 68 65 20 6f |SIC is not the o| 000000c0 6e 6c 79 20 6c 61 6e 67 75 61 67 65 20 79 6f 75 |nly language you| 000000d0 20 67 65 74 20 77 69 74 68 20 79 6f 75 72 20 42 | get with your B| 000000e0 42 43 0d 4d 69 63 72 6f 2e 20 20 42 75 69 6c 74 |BC.Micro. Built| 000000f0 20 69 6e 74 6f 20 74 68 65 20 42 41 53 49 43 20 | into the BASIC | 00000100 6c 61 6e 67 75 61 67 65 20 52 4f 4d 20 69 73 20 |language ROM is | 00000110 61 6e 20 61 73 73 65 6d 62 6c 65 72 2e 20 0d 54 |an assembler. .T| 00000120 68 69 73 20 69 73 20 74 68 65 20 70 72 6f 67 72 |his is the progr| 00000130 61 6d 20 74 68 61 74 20 68 65 6c 70 73 20 79 6f |am that helps yo| 00000140 75 20 74 6f 20 70 72 6f 67 72 61 6d 20 75 73 69 |u to program usi| 00000150 6e 67 20 6d 61 63 68 69 6e 65 0d 63 6f 64 65 20 |ng machine.code | 00000160 69 6e 20 74 68 65 20 73 61 6d 65 20 77 61 79 20 |in the same way | 00000170 74 68 61 74 20 74 68 65 20 42 41 53 49 43 20 63 |that the BASIC c| 00000180 68 69 70 20 69 74 73 65 6c 66 20 69 6e 20 79 6f |hip itself in yo| 00000190 75 72 0d 6d 61 63 68 69 6e 65 20 68 65 6c 70 73 |ur.machine helps| 000001a0 20 79 6f 75 20 74 6f 20 70 72 6f 67 72 61 6d 20 | you to program | 000001b0 69 6e 20 42 41 53 49 43 2e 0d 0d 50 72 6f 67 72 |in BASIC...Progr| 000001c0 61 6d 6d 69 6e 67 20 61 20 63 6f 6d 70 75 74 65 |amming a compute| 000001d0 72 20 69 6e 20 6d 61 63 68 69 6e 65 20 63 6f 64 |r in machine cod| 000001e0 65 20 6d 65 61 6e 73 20 67 69 76 69 6e 67 20 74 |e means giving t| 000001f0 68 65 0d 6d 61 63 68 69 6e 65 20 63 6f 6d 6d 61 |he.machine comma| 00000200 6e 64 73 20 69 6e 20 74 68 65 20 6e 75 6d 62 65 |nds in the numbe| 00000210 72 20 63 6f 64 65 20 69 74 20 64 69 72 65 63 74 |r code it direct| 00000220 6c 79 20 75 6e 64 65 72 73 74 61 6e 64 73 2e 20 |ly understands. | 00000230 0d 47 65 6e 65 72 61 6c 6c 79 20 77 68 65 6e 20 |.Generally when | 00000240 70 65 6f 70 6c 65 20 74 61 6c 6b 20 61 62 6f 75 |people talk abou| 00000250 74 20 70 72 6f 67 72 61 6d 6d 69 6e 67 20 69 6e |t programming in| 00000260 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 0d 74 68 | machine code.th| 00000270 65 79 20 72 65 61 6c 6c 79 20 6d 65 61 6e 20 75 |ey really mean u| 00000280 73 69 6e 67 20 61 6e 20 61 73 73 65 6d 62 6c 65 |sing an assemble| 00000290 72 2e 20 20 54 68 65 20 61 73 73 65 6d 62 6c 65 |r. The assemble| 000002a0 72 20 74 61 6b 65 73 0d 79 6f 75 72 20 70 72 6f |r takes.your pro| 000002b0 67 72 61 6d 2c 20 77 72 69 74 74 65 6e 20 69 6e |gram, written in| 000002c0 20 27 61 73 73 65 6d 62 6c 79 20 6c 61 6e 67 75 | 'assembly langu| 000002d0 61 67 65 27 2c 20 61 6e 64 20 74 72 61 6e 73 6c |age', and transl| 000002e0 61 74 65 73 0d 69 74 20 69 6e 74 6f 20 6d 61 63 |ates.it into mac| 000002f0 68 69 6e 65 20 63 6f 64 65 2e 20 20 59 6f 75 72 |hine code. Your| 00000300 20 6f 72 69 67 69 6e 61 6c 20 61 73 73 65 6d 62 | original assemb| 00000310 6c 79 20 6c 61 6e 67 75 61 67 65 0d 70 72 6f 67 |ly language.prog| 00000320 72 61 6d 20 69 73 20 63 61 6c 6c 65 64 20 79 6f |ram is called yo| 00000330 75 72 20 27 73 6f 75 72 63 65 20 63 6f 64 65 27 |ur 'source code'| 00000340 2e 20 20 4f 6e 63 65 20 74 68 65 20 61 73 73 65 |. Once the asse| 00000350 6d 62 6c 65 72 0d 68 61 73 20 74 72 61 6e 73 6c |mbler.has transl| 00000360 61 74 65 64 20 79 6f 75 72 20 73 6f 75 72 63 65 |ated your source| 00000370 20 69 6e 74 6f 20 6d 61 63 68 69 6e 65 20 63 6f | into machine co| 00000380 64 65 20 61 6e 64 20 27 61 73 73 65 6d 62 6c 65 |de and 'assemble| 00000390 64 27 0d 69 74 20 69 6e 74 6f 20 6d 65 6d 6f 72 |d'.it into memor| 000003a0 79 20 79 6f 75 20 6e 6f 20 6c 6f 6e 67 65 72 20 |y you no longer | 000003b0 6e 65 65 64 20 74 68 65 20 73 6f 75 72 63 65 2e |need the source.| 000003c0 20 20 59 6f 75 20 63 6f 75 6c 64 0d 74 68 72 6f | You could.thro| 000003d0 77 20 69 74 20 61 77 61 79 20 61 6e 64 20 74 68 |w it away and th| 000003e0 65 20 63 68 75 6e 6b 20 6f 66 20 6d 61 63 68 69 |e chunk of machi| 000003f0 6e 65 20 63 6f 64 65 20 77 6f 75 6c 64 20 73 74 |ne code would st| 00000400 69 6c 6c 20 64 6f 0d 69 74 73 20 6a 6f 62 20 61 |ill do.its job a| 00000410 6c 6c 20 62 79 20 69 74 73 65 6c 66 2e 0d 0d 54 |ll by itself...T| 00000420 68 69 73 20 63 61 6e 20 6d 61 6b 65 20 66 6f 72 |his can make for| 00000430 20 66 61 73 74 65 72 20 61 6e 64 20 6d 6f 72 65 | faster and more| 00000440 20 65 66 66 69 63 69 65 6e 74 20 70 72 6f 67 72 | efficient progr| 00000450 61 6d 73 20 74 68 61 6e 20 69 6e 0d 42 41 53 49 |ams than in.BASI| 00000460 43 20 66 6f 72 20 74 77 6f 20 72 65 61 73 6f 6e |C for two reason| 00000470 73 2e 20 20 46 69 72 73 74 6c 79 20 79 6f 75 20 |s. Firstly you | 00000480 61 72 65 20 77 72 69 74 69 6e 67 20 74 68 65 20 |are writing the | 00000490 70 72 6f 67 72 61 6d 0d 69 6e 20 61 20 66 6f 72 |program.in a for| 000004a0 6d 20 76 65 72 79 20 63 6c 6f 73 65 20 74 6f 20 |m very close to | 000004b0 74 68 65 20 66 6f 72 6d 20 69 6e 20 77 68 69 63 |the form in whic| 000004c0 68 20 74 68 65 20 6d 61 63 68 69 6e 65 20 61 63 |h the machine ac| 000004d0 74 75 61 6c 6c 79 0d 63 6f 6d 70 75 74 65 73 2e |tually.computes.| 000004e0 20 20 53 65 63 6f 6e 64 6c 79 20 42 41 53 49 43 | Secondly BASIC| 000004f0 20 73 74 61 79 73 20 69 6e 20 74 68 65 20 6d 65 | stays in the me| 00000500 6d 6f 72 79 20 61 6e 64 20 69 73 0d 74 72 61 6e |mory and is.tran| 00000510 73 6c 61 74 65 64 20 69 6e 74 6f 20 6d 61 63 68 |slated into mach| 00000520 69 6e 65 20 63 6f 64 65 20 6c 69 6e 65 20 62 79 |ine code line by| 00000530 20 6c 69 6e 65 2c 20 63 6f 6d 6d 61 6e 64 20 62 | line, command b| 00000540 79 0d 63 6f 6d 6d 61 6e 64 2c 20 61 73 20 74 68 |y.command, as th| 00000550 65 20 70 72 6f 67 72 61 6d 20 72 75 6e 73 2e 20 |e program runs. | 00000560 20 45 61 63 68 20 63 6f 6d 6d 61 6e 64 20 69 73 | Each command is| 00000570 20 66 69 72 73 74 20 74 75 72 6e 65 64 0d 69 6e | first turned.in| 00000580 74 6f 20 6d 61 63 68 69 6e 65 20 69 6e 73 74 72 |to machine instr| 00000590 75 63 74 69 6f 6e 73 20 61 6e 64 20 74 68 65 6e |uctions and then| 000005a0 20 65 78 65 63 75 74 65 64 2c 20 77 68 69 63 68 | executed, which| 000005b0 20 69 73 20 74 69 6d 65 0d 63 6f 6e 73 75 6d 69 | is time.consumi| 000005c0 6e 67 2e 20 20 42 42 43 20 42 41 53 49 43 20 69 |ng. BBC BASIC i| 000005d0 73 20 63 61 6c 6c 65 64 20 61 6e 20 27 69 6e 74 |s called an 'int| 000005e0 65 72 70 72 65 74 65 64 27 20 6c 61 6e 67 75 61 |erpreted' langua| 000005f0 67 65 0d 62 65 63 61 75 73 65 20 69 74 20 77 6f |ge.because it wo| 00000600 72 6b 73 20 69 6e 20 74 68 69 73 20 77 61 79 20 |rks in this way | 00000610 61 6e 64 20 74 68 65 20 61 73 73 65 6d 62 6c 65 |and the assemble| 00000620 72 2c 20 77 68 69 63 68 20 64 6f 65 73 0d 74 68 |r, which does.th| 00000630 65 20 74 72 61 6e 73 6c 61 74 69 6f 6e 20 62 65 |e translation be| 00000640 66 6f 72 65 2c 20 72 61 74 68 65 72 20 74 68 61 |fore, rather tha| 00000650 6e 20 64 75 72 69 6e 67 2c 20 65 78 65 63 75 74 |n during, execut| 00000660 69 6e 67 20 74 68 65 0d 63 6f 64 65 20 69 73 20 |ing the.code is | 00000670 73 61 69 64 20 74 6f 20 62 65 20 27 63 6f 6d 70 |said to be 'comp| 00000680 69 6c 65 64 27 2e 20 20 47 65 6e 65 72 61 6c 6c |iled'. Generall| 00000690 79 20 63 6f 6d 70 69 6c 65 64 20 6c 61 6e 67 75 |y compiled langu| 000006a0 61 67 65 73 0d 61 72 65 20 66 61 73 74 65 72 20 |ages.are faster | 000006b0 74 68 61 74 20 69 6e 74 65 72 70 72 65 74 65 64 |that interpreted| 000006c0 20 6f 6e 65 73 2e 0d 0d 42 65 73 69 64 65 73 20 | ones...Besides | 000006d0 77 61 6e 74 69 6e 67 20 61 20 66 61 73 74 65 72 |wanting a faster| 000006e0 20 70 72 6f 67 72 61 6d 20 74 68 61 6e 20 42 41 | program than BA| 000006f0 53 49 43 20 74 68 65 72 65 20 61 72 65 20 73 6f |SIC there are so| 00000700 6d 65 0d 74 68 69 6e 67 73 20 74 68 61 74 20 63 |me.things that c| 00000710 61 6e 20 6f 6e 6c 79 20 62 65 20 64 6f 6e 65 20 |an only be done | 00000720 69 6e 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 2e |in machine code.| 00000730 20 20 54 68 65 73 65 20 61 72 65 0d 65 78 70 6c | These are.expl| 00000740 6f 72 61 74 69 6f 6e 73 20 6f 66 20 74 68 65 20 |orations of the | 00000750 76 65 72 79 20 69 6e 6e 61 72 64 73 20 6f 66 20 |very innards of | 00000760 74 68 65 20 63 6f 6d 70 75 74 65 72 2c 20 61 6e |the computer, an| 00000770 64 20 77 65 0d 77 69 6c 6c 20 74 72 79 20 73 6f |d we.will try so| 00000780 6d 65 20 6f 66 20 74 68 65 73 65 20 6c 61 74 65 |me of these late| 00000790 72 20 69 6e 20 74 68 65 20 63 6f 75 72 73 65 2e |r in the course.| 000007a0 20 20 28 50 65 72 73 6f 6e 61 6c 6c 79 20 49 0d | (Personally I.| 000007b0 66 69 6e 64 20 74 68 65 6d 20 6d 6f 72 65 20 66 |find them more f| 000007c0 75 6e 20 74 68 61 74 20 6a 75 73 74 20 62 65 69 |un that just bei| 000007d0 6e 67 20 61 62 6c 65 20 74 6f 20 6d 75 6c 74 69 |ng able to multi| 000007e0 70 6c 79 20 66 61 73 74 65 72 21 29 0d 0d 49 74 |ply faster!)..It| 000007f0 20 69 73 20 70 6f 73 73 69 62 6c 65 20 74 6f 20 | is possible to | 00000800 77 72 69 74 65 20 74 68 65 20 6e 75 6d 62 65 72 |write the number| 00000810 73 20 6f 66 20 6d 61 63 68 69 6e 65 20 63 6f 64 |s of machine cod| 00000820 65 20 64 69 72 65 63 74 6c 79 0d 69 6e 74 6f 20 |e directly.into | 00000830 6d 65 6d 6f 72 79 2c 20 62 75 74 20 61 63 74 75 |memory, but actu| 00000840 61 6c 6c 79 20 65 6e 74 65 72 69 6e 67 20 74 68 |ally entering th| 00000850 65 20 6e 75 6d 62 65 72 73 20 74 68 61 74 20 74 |e numbers that t| 00000860 65 6c 6c 20 74 68 65 0d 63 6f 6d 70 75 74 65 72 |ell the.computer| 00000870 20 74 6f 20 61 64 64 20 74 68 65 20 63 6f 6e 74 | to add the cont| 00000880 65 6e 74 73 20 6f 66 20 74 77 6f 20 6d 65 6d 6f |ents of two memo| 00000890 72 79 20 6c 6f 63 61 74 69 6f 6e 73 0d 74 6f 67 |ry locations.tog| 000008a0 65 74 68 65 72 20 28 66 6f 72 20 65 78 61 6d 70 |ether (for examp| 000008b0 6c 65 29 20 69 73 20 61 20 6c 69 74 74 6c 65 20 |le) is a little | 000008c0 65 72 72 6f 72 2d 70 72 6f 6e 65 2e 20 20 54 68 |error-prone. Th| 000008d0 65 0d 61 73 73 65 6d 62 6c 65 72 2c 20 77 68 69 |e.assembler, whi| 000008e0 63 68 20 61 6c 6c 6f 77 73 20 6d 6e 65 6d 6f 6e |ch allows mnemon| 000008f0 69 63 73 20 61 6e 64 20 61 64 64 72 65 73 73 20 |ics and address | 00000900 6c 61 62 65 6c 73 20 74 6f 20 62 65 0d 75 73 65 |labels to be.use| 00000910 64 2c 20 63 6c 61 72 69 66 69 65 73 20 74 68 69 |d, clarifies thi| 00000920 73 20 70 72 6f 63 65 73 73 2e 0d 0d 48 65 72 65 |s process...Here| 00000930 27 73 20 6f 75 72 20 65 78 61 6d 70 6c 65 2c 20 |'s our example, | 00000940 77 68 69 63 68 20 61 64 64 73 20 35 20 74 6f 20 |which adds 5 to | 00000950 33 32 20 61 6e 64 20 70 75 74 73 20 74 68 65 20 |32 and puts the | 00000960 72 65 73 75 6c 74 0d 69 6e 74 6f 20 6d 65 6d 6f |result.into memo| 00000970 72 79 20 6c 6f 63 61 74 69 6f 6e 20 26 32 30 32 |ry location &202| 00000980 31 3a 0d 0d 49 6e 20 6d 61 63 68 69 6e 65 20 63 |1:..In machine c| 00000990 6f 64 65 20 20 49 6e 20 42 42 43 20 61 73 73 65 |ode In BBC asse| 000009a0 6d 62 6c 65 72 0d 0d 26 41 39 20 26 32 30 20 20 |mbler..&A9 &20 | 000009b0 20 20 20 20 20 20 20 20 4c 44 41 20 23 26 32 30 | LDA #&20| 000009c0 20 20 20 20 20 20 20 50 75 74 20 26 32 30 20 69 | Put &20 i| 000009d0 6e 20 74 68 65 20 61 63 63 75 6d 75 6c 61 74 6f |n the accumulato| 000009e0 72 0d 26 31 38 20 20 20 20 20 20 20 20 20 20 20 |r.&18 | 000009f0 20 20 20 43 4c 43 20 20 20 20 20 20 20 20 20 20 | CLC | 00000a00 20 20 43 6c 65 61 72 20 74 68 65 20 63 61 72 72 | Clear the carr| 00000a10 79 20 66 6c 61 67 0d 26 36 39 20 26 30 35 20 20 |y flag.&69 &05 | 00000a20 20 20 20 20 20 20 20 20 41 44 43 20 23 26 30 35 | ADC #&05| 00000a30 20 20 20 20 20 20 20 41 64 64 20 35 20 28 77 69 | Add 5 (wi| 00000a40 74 68 20 63 61 72 72 79 29 0d 26 38 35 20 26 32 |th carry).&85 &2| 00000a50 31 20 26 32 30 20 20 20 20 20 20 53 54 41 20 72 |1 &20 STA r| 00000a60 65 73 75 6c 74 20 20 20 20 20 53 74 6f 72 65 20 |esult Store | 00000a70 69 6e 20 6d 65 6d 6f 72 79 20 6c 61 62 65 6c 6c |in memory labell| 00000a80 65 64 0d 09 09 09 09 20 20 20 20 20 20 20 20 20 |ed..... | 00000a90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000aa0 20 20 20 27 72 65 73 75 6c 74 27 20 28 26 32 30 | 'result' (&20| 00000ab0 32 31 29 0d 0d 4e 6f 77 20 61 74 20 74 68 69 73 |21)..Now at this| 00000ac0 20 73 74 61 67 65 20 74 68 65 20 4c 44 41 2f 43 | stage the LDA/C| 00000ad0 4c 43 2f 41 44 43 20 62 69 74 73 20 69 6e 20 74 |LC/ADC bits in t| 00000ae0 68 65 20 6d 69 64 64 6c 65 20 6d 61 79 20 62 65 |he middle may be| 00000af0 0d 6a 75 73 74 20 61 73 20 6f 62 73 63 75 72 65 |.just as obscure| 00000b00 20 61 73 20 74 68 6f 73 65 20 6e 75 6d 62 65 72 | as those number| 00000b10 73 20 61 74 20 74 68 65 20 6c 65 66 74 2c 20 68 |s at the left, h| 00000b20 6f 77 65 76 65 72 20 49 20 68 6f 70 65 0d 79 6f |owever I hope.yo| 00000b30 75 20 77 69 6c 6c 20 61 67 72 65 65 20 74 68 61 |u will agree tha| 00000b40 74 20 4c 44 41 20 69 73 20 65 61 73 69 65 72 20 |t LDA is easier | 00000b50 74 6f 20 72 65 6d 65 6d 62 65 72 20 74 68 61 6e |to remember than| 00000b60 20 26 41 39 2c 0d 65 73 70 65 63 69 61 6c 6c 79 | &A9,.especially| 00000b70 20 73 69 6e 63 65 20 74 68 65 20 63 6f 64 65 20 | since the code | 00000b80 74 6f 20 70 75 74 20 61 20 6e 75 6d 62 65 72 20 |to put a number | 00000b90 69 6e 20 74 68 65 20 61 63 63 75 6d 75 6c 61 74 |in the accumulat| 00000ba0 6f 72 0d 63 68 61 6e 67 65 73 20 64 65 70 65 6e |or.changes depen| 00000bb0 64 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 20 |ding on whether | 00000bc0 74 68 65 20 6e 75 6d 62 65 72 20 69 73 20 70 75 |the number is pu| 00000bd0 74 20 69 6e 20 64 69 72 65 63 74 6c 79 0d 28 61 |t in directly.(a| 00000be0 73 20 68 65 72 65 29 20 6f 72 20 6c 6f 61 64 65 |s here) or loade| 00000bf0 64 20 66 72 6f 6d 20 6d 65 6d 6f 72 79 2c 20 61 |d from memory, a| 00000c00 6e 64 20 77 68 65 72 65 20 69 6e 20 6d 65 6d 6f |nd where in memo| 00000c10 72 79 2c 20 61 6e 64 0d 68 6f 77 20 79 6f 75 20 |ry, and.how you | 00000c20 67 65 74 20 74 68 65 72 65 21 20 20 49 6e 20 66 |get there! In f| 00000c30 61 63 74 20 4c 44 41 20 63 61 6e 20 72 65 70 72 |act LDA can repr| 00000c40 65 73 65 6e 74 20 38 20 64 69 66 66 65 72 65 6e |esent 8 differen| 00000c50 74 0d 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 69 |t.machine code i| 00000c60 6e 73 74 72 75 63 74 69 6f 6e 73 20 64 65 70 65 |nstructions depe| 00000c70 6e 64 69 6e 67 20 6f 6e 20 65 78 61 63 74 6c 79 |nding on exactly| 00000c80 20 77 68 61 74 20 79 6f 75 20 77 61 6e 74 0d 74 | what you want.t| 00000c90 6f 20 64 6f 2e 20 20 54 68 65 20 61 73 73 65 6d |o do. The assem| 00000ca0 62 6c 65 72 20 73 6f 72 74 73 20 6f 75 74 20 77 |bler sorts out w| 00000cb0 68 69 63 68 20 6f 6e 65 20 69 73 20 61 70 70 72 |hich one is appr| 00000cc0 6f 70 72 69 61 74 65 2e 0d 28 49 6e 63 69 64 65 |opriate..(Incide| 00000cd0 6e 74 61 6c 6c 79 2c 20 70 75 74 74 69 6e 67 20 |ntally, putting | 00000ce0 61 20 26 20 69 6e 20 66 72 6f 6e 74 20 6f 66 20 |a & in front of | 00000cf0 61 20 6e 75 6d 62 65 72 20 69 73 20 74 68 65 20 |a number is the | 00000d00 77 61 79 0d 79 6f 75 20 74 65 6c 6c 20 42 42 43 |way.you tell BBC| 00000d10 20 42 41 53 49 43 20 74 68 61 74 20 61 20 6e 75 | BASIC that a nu| 00000d20 6d 62 65 72 20 69 73 20 69 6e 20 62 61 73 65 20 |mber is in base | 00000d30 31 36 2c 20 68 65 78 61 64 65 63 69 6d 61 6c 2c |16, hexadecimal,| 00000d40 0d 69 6e 73 74 65 61 64 20 6f 66 20 62 61 73 65 |.instead of base| 00000d50 20 31 30 2c 20 64 65 63 69 6d 61 6c 2e 20 20 54 | 10, decimal. T| 00000d60 68 65 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 69 |he accumulator i| 00000d70 73 20 61 20 6e 75 6d 62 65 72 0d 73 74 6f 72 65 |s a number.store| 00000d80 20 69 6e 20 74 68 65 20 6d 69 63 72 6f 70 72 6f | in the micropro| 00000d90 63 65 73 73 6f 72 20 77 69 74 68 20 77 68 69 63 |cessor with whic| 00000da0 68 20 77 65 20 63 61 6e 20 64 6f 0d 61 72 69 74 |h we can do.arit| 00000db0 68 6d 65 74 69 63 2e 29 0d 0d 4c 44 41 20 69 73 |hmetic.)..LDA is| 00000dc0 20 61 20 6d 6e 65 6d 6f 6e 69 63 2c 20 73 74 61 | a mnemonic, sta| 00000dd0 6e 64 69 6e 67 20 66 6f 72 20 4c 6f 61 44 20 74 |nding for LoaD t| 00000de0 68 65 20 41 63 63 75 6d 75 6c 61 74 6f 72 2e 20 |he Accumulator. | 00000df0 20 57 68 65 6e 0d 79 6f 75 20 72 75 6e 20 61 6e | When.you run an| 00000e00 20 61 73 73 65 6d 62 6c 79 20 6c 61 6e 67 75 61 | assembly langua| 00000e10 67 65 20 70 72 6f 67 72 61 6d 20 69 74 20 74 61 |ge program it ta| 00000e20 6b 65 73 20 74 68 65 20 6d 6e 65 6d 6f 6e 69 63 |kes the mnemonic| 00000e30 73 0d 61 6e 64 20 6c 61 62 65 6c 73 20 61 6e 64 |s.and labels and| 00000e40 20 6e 75 6d 62 65 72 73 20 61 6e 64 20 63 6f 6e | numbers and con| 00000e50 76 65 72 74 73 20 74 68 65 6d 20 69 6e 74 6f 20 |verts them into | 00000e60 74 68 65 0d 61 70 70 72 6f 70 72 69 61 74 65 20 |the.appropriate | 00000e70 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 61 6e 64 |machine code and| 00000e80 20 61 73 73 65 6d 62 6c 65 73 20 74 68 65 20 63 | assembles the c| 00000e90 6f 64 65 20 69 6e 74 6f 20 74 68 65 0d 73 65 63 |ode into the.sec| 00000ea0 74 69 6f 6e 20 6f 66 20 6d 65 6d 6f 72 79 20 79 |tion of memory y| 00000eb0 6f 75 20 72 65 71 75 69 72 65 2e 0d 0d 54 68 65 |ou require...The| 00000ec0 20 42 42 43 20 61 73 73 65 6d 62 6c 65 72 20 69 | BBC assembler i| 00000ed0 73 20 61 63 74 75 61 6c 6c 79 20 70 61 72 74 20 |s actually part | 00000ee0 6f 66 20 42 42 43 20 42 41 53 49 43 2e 20 20 59 |of BBC BASIC. Y| 00000ef0 6f 75 20 75 73 65 20 69 74 0d 66 72 6f 6d 20 42 |ou use it.from B| 00000f00 41 53 49 43 20 77 68 69 63 68 20 67 69 76 65 73 |ASIC which gives| 00000f10 20 79 6f 75 20 63 65 72 74 61 69 6e 20 61 64 76 | you certain adv| 00000f20 61 6e 74 61 67 65 73 2e 20 20 41 73 20 77 65 20 |antages. As we | 00000f30 77 69 6c 6c 0d 73 65 65 20 6c 61 74 65 72 20 79 |will.see later y| 00000f40 6f 75 20 63 61 6e 20 75 73 65 20 74 68 65 20 73 |ou can use the s| 00000f50 74 72 75 63 74 75 72 65 20 6f 66 20 42 41 53 49 |tructure of BASI| 00000f60 43 20 74 6f 20 68 65 6c 70 20 79 6f 75 72 0d 61 |C to help your.a| 00000f70 73 73 65 6d 62 6c 65 72 20 70 72 6f 67 72 61 6d |ssembler program| 00000f80 6d 69 6e 67 20 61 6e 64 20 79 6f 75 20 63 61 6e |ming and you can| 00000f90 20 61 6c 73 6f 20 75 73 65 20 42 41 53 49 43 20 | also use BASIC | 00000fa0 63 6f 6d 6d 61 6e 64 73 0d 77 69 74 68 69 6e 20 |commands.within | 00000fb0 74 68 65 20 61 73 73 65 6d 62 6c 65 72 2e 20 20 |the assembler. | 00000fc0 46 6f 72 20 65 78 61 6d 70 6c 65 20 69 66 20 79 |For example if y| 00000fd0 6f 75 20 77 61 6e 74 20 74 6f 20 6c 6f 61 64 20 |ou want to load | 00000fe0 74 68 65 0d 61 63 63 75 6d 75 6c 61 74 6f 72 20 |the.accumulator | 00000ff0 77 69 74 68 20 74 68 65 20 41 53 43 49 49 20 63 |with the ASCII c| 00001000 6f 64 65 20 66 6f 72 20 61 20 73 70 61 63 65 20 |ode for a space | 00001010 79 6f 75 20 63 61 6e 20 75 73 65 20 61 6e 79 0d |you can use any.| 00001020 6f 66 20 74 68 65 73 65 20 6d 65 74 68 6f 64 73 |of these methods| 00001030 3a 20 0d 0d 20 20 20 20 20 20 20 20 20 20 20 20 |: .. | 00001040 20 20 20 20 20 4c 44 41 20 23 26 32 30 0d 0d 20 | LDA #&20.. | 00001050 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00001060 4c 44 41 20 23 33 32 20 0d 0d 20 20 20 20 20 20 |LDA #32 .. | 00001070 20 20 20 20 20 20 20 20 20 20 20 4c 44 41 20 23 | LDA #| 00001080 41 53 43 28 22 20 22 29 0d 0d 20 20 20 20 20 20 |ASC(" ").. | 00001090 20 20 20 20 20 20 20 20 20 20 20 63 68 61 72 25 | char%| 000010a0 3d 33 32 0d 20 20 20 20 20 20 20 20 20 20 20 20 |=32. | 000010b0 20 20 20 20 20 4c 44 41 20 63 68 61 72 25 0d 0d | LDA char%..| 000010c0 54 68 65 79 20 61 6c 6c 20 6d 65 61 6e 20 65 78 |They all mean ex| 000010d0 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65 20 74 |actly the same t| 000010e0 68 69 6e 67 2e 0d 0d 54 68 65 20 6e 61 6d 65 73 |hing...The names| 000010f0 20 77 69 74 68 20 77 68 69 63 68 20 79 6f 75 20 | with which you | 00001100 6c 61 62 65 6c 20 6d 65 6d 6f 72 79 20 6c 6f 63 |label memory loc| 00001110 61 74 69 6f 6e 73 20 69 6e 20 79 6f 75 72 0d 61 |ations in your.a| 00001120 73 73 65 6d 62 6c 65 72 20 70 72 6f 67 72 61 6d |ssembler program| 00001130 20 61 72 65 20 42 41 53 49 43 20 76 61 72 69 61 | are BASIC varia| 00001140 62 6c 65 73 20 61 6e 64 20 66 6f 6c 6c 6f 77 20 |bles and follow | 00001150 74 68 65 20 73 61 6d 65 0d 72 75 6c 65 73 2e 20 |the same.rules. | 00001160 20 54 68 69 73 20 6d 65 61 6e 73 20 79 6f 75 20 | This means you | 00001170 63 61 6e 20 75 73 65 20 6c 6f 6e 67 20 61 6e 64 |can use long and| 00001180 20 63 6c 65 61 72 20 6c 61 62 65 6c 20 6e 61 6d | clear label nam| 00001190 65 73 20 69 66 0d 79 6f 75 20 77 61 6e 74 20 74 |es if.you want t| 000011a0 6f 2c 20 61 6e 64 20 73 69 6e 63 65 20 74 68 65 |o, and since the| 000011b0 20 73 6f 75 72 63 65 20 63 6f 64 65 20 69 73 20 | source code is | 000011c0 6e 6f 74 20 6e 65 65 64 65 64 20 69 6e 20 74 68 |not needed in th| 000011d0 65 0d 6d 61 63 68 69 6e 65 20 77 68 65 6e 20 79 |e.machine when y| 000011e0 6f 75 20 72 75 6e 20 74 68 65 20 6d 61 63 68 69 |ou run the machi| 000011f0 6e 65 20 63 6f 64 65 20 74 68 65 20 6c 65 6e 67 |ne code the leng| 00001200 74 68 20 6f 66 20 79 6f 75 72 0d 76 61 72 69 61 |th of your.varia| 00001210 62 6c 65 20 6e 61 6d 65 73 20 64 6f 65 73 20 6e |ble names does n| 00001220 6f 74 20 61 66 66 65 63 74 20 74 68 65 20 6c 65 |ot affect the le| 00001230 6e 67 74 68 20 6f 66 20 79 6f 75 72 20 70 72 6f |ngth of your pro| 00001240 67 72 61 6d 2c 0d 6f 72 20 69 74 73 20 73 70 65 |gram,.or its spe| 00001250 65 64 2c 20 75 6e 6c 69 6b 65 20 42 41 53 49 43 |ed, unlike BASIC| 00001260 2e 0d 0d 54 6f 20 73 65 74 20 75 70 20 74 68 65 |...To set up the| 00001270 20 61 73 73 65 6d 62 6c 65 72 20 79 6f 75 20 73 | assembler you s| 00001280 68 6f 75 6c 64 20 68 61 76 65 20 61 20 70 69 65 |hould have a pie| 00001290 63 65 20 6f 66 20 42 41 53 49 43 0d 6c 69 6b 65 |ce of BASIC.like| 000012a0 20 74 68 69 73 3a 0d 0d 20 20 09 20 31 30 20 52 | this:.. . 10 R| 000012b0 45 4d 20 20 41 73 73 65 6d 62 6c 65 72 20 73 65 |EM Assembler se| 000012c0 74 2d 75 70 20 65 78 61 6d 70 6c 65 0d 20 20 09 |t-up example. .| 000012d0 20 32 30 20 0d 20 20 09 20 33 30 20 44 49 4d 20 | 20 . . 30 DIM | 000012e0 63 6f 64 65 25 20 32 35 36 0d 20 20 09 20 34 30 |code% 256. . 40| 000012f0 20 0d 20 20 09 20 35 30 20 46 4f 52 20 70 61 73 | . . 50 FOR pas| 00001300 73 25 20 3d 20 30 20 54 4f 20 33 20 53 54 45 50 |s% = 0 TO 3 STEP| 00001310 20 33 0d 20 20 09 20 36 30 20 50 25 20 3d 20 63 | 3. . 60 P% = c| 00001320 6f 64 65 25 0d 20 20 09 20 37 30 20 5b 4f 50 54 |ode%. . 70 [OPT| 00001330 20 70 61 73 73 25 0d 20 20 09 20 38 30 20 2e 2e | pass%. . 80 ..| 00001340 2e 2e 2e 2e 20 74 68 65 20 66 69 72 73 74 20 6c |.... the first l| 00001350 69 6e 65 20 6f 66 20 61 73 73 65 6d 62 6c 65 72 |ine of assembler| 00001360 0d 20 20 0d 20 20 09 34 39 30 20 2e 2e 2e 2e 2e |. . .490 .....| 00001370 2e 20 74 68 65 20 6c 61 73 74 20 6c 69 6e 65 20 |. the last line | 00001380 6f 66 20 61 73 73 65 6d 62 6c 65 72 0d 20 20 09 |of assembler. .| 00001390 35 30 30 20 5d 0d 20 20 09 35 31 30 20 4e 45 58 |500 ]. .510 NEX| 000013a0 54 0d 0d 49 6e 20 6c 69 6e 65 20 33 30 20 77 65 |T..In line 30 we| 000013b0 20 61 72 65 20 61 6c 6c 6f 63 61 74 69 6e 67 20 | are allocating | 000013c0 73 6f 6d 65 20 6d 65 6d 6f 72 79 20 69 6e 20 77 |some memory in w| 000013d0 68 69 63 68 20 74 6f 0d 61 73 73 65 6d 62 6c 65 |hich to.assemble| 000013e0 20 74 68 65 20 6d 61 63 68 69 6e 65 20 63 6f 64 | the machine cod| 000013f0 65 20 77 69 74 68 20 74 68 65 20 61 6c 74 65 72 |e with the alter| 00001400 6e 61 74 69 76 65 20 75 73 65 20 66 6f 72 20 74 |native use for t| 00001410 68 65 0d 44 49 4d 20 73 74 61 74 65 6d 65 6e 74 |he.DIM statement| 00001420 2e 20 20 54 68 65 20 73 6f 66 74 20 6c 6f 76 69 |. The soft lovi| 00001430 6e 67 20 70 72 6f 74 65 63 74 69 6f 6e 20 6f 66 |ng protection of| 00001440 20 42 41 53 49 43 20 69 73 20 6e 6f 74 0d 70 72 | BASIC is not.pr| 00001450 6f 76 69 64 65 64 20 69 6e 20 6d 61 63 68 69 6e |ovided in machin| 00001460 65 20 63 6f 64 65 20 73 6f 20 74 68 65 20 61 73 |e code so the as| 00001470 73 65 6d 62 6c 65 72 20 77 69 6c 6c 20 6e 6f 74 |sembler will not| 00001480 20 61 6c 6c 6f 63 61 74 65 0d 6d 65 6d 6f 72 79 | allocate.memory| 00001490 20 66 6f 72 20 79 6f 75 20 6e 6f 72 20 77 69 6c | for you nor wil| 000014a0 6c 20 69 74 20 73 74 6f 70 20 79 6f 75 20 61 6c |l it stop you al| 000014b0 6c 6f 63 61 74 69 6e 67 20 79 6f 75 72 73 65 6c |locating yoursel| 000014c0 66 20 61 0d 73 69 6c 6c 79 20 70 69 65 63 65 20 |f a.silly piece | 000014d0 6f 66 20 6d 65 6d 6f 72 79 2e 20 20 44 49 4d 20 |of memory. DIM | 000014e0 63 6f 64 65 25 20 32 35 36 20 63 6c 61 77 73 20 |code% 256 claws | 000014f0 62 61 63 6b 20 61 20 6c 69 74 74 6c 65 0d 68 65 |back a little.he| 00001500 6c 70 20 66 72 6f 6d 20 42 41 53 49 43 20 62 79 |lp from BASIC by| 00001510 20 74 61 6b 69 6e 67 20 32 35 36 20 62 79 74 65 | taking 256 byte| 00001520 73 20 6f 66 20 6d 65 6d 6f 72 79 20 73 74 61 72 |s of memory star| 00001530 74 69 6e 67 20 61 74 0d 74 68 65 20 61 64 64 72 |ting at.the addr| 00001540 65 73 73 20 6e 6f 77 20 68 65 6c 64 20 69 6e 20 |ess now held in | 00001550 74 68 65 20 76 61 72 69 61 62 6c 65 20 63 6f 64 |the variable cod| 00001560 65 25 2e 20 20 42 41 53 49 43 20 77 69 6c 6c 20 |e%. BASIC will | 00001570 6e 6f 74 0d 6f 76 65 72 77 72 69 74 65 20 74 68 |not.overwrite th| 00001580 69 73 20 62 6c 6f 63 6b 20 6f 66 20 6d 65 6d 6f |is block of memo| 00001590 72 79 20 62 75 74 20 69 74 20 77 69 6c 6c 20 61 |ry but it will a| 000015a0 6c 73 6f 20 6e 6f 74 20 73 74 6f 70 20 79 6f 75 |lso not stop you| 000015b0 0d 74 72 79 69 6e 67 20 74 6f 20 75 73 65 20 6d |.trying to use m| 000015c0 6f 72 65 20 74 68 61 6e 20 79 6f 75 20 61 73 6b |ore than you ask| 000015d0 65 64 20 66 6f 72 2c 20 61 6c 74 68 6f 75 67 68 |ed for, although| 000015e0 20 75 73 75 61 6c 6c 79 20 74 68 65 0d 61 73 73 | usually the.ass| 000015f0 65 6d 62 6c 79 20 77 69 6c 6c 20 66 61 69 6c 2e |embly will fail.| 00001600 0d 0d 42 79 20 73 69 6c 6c 79 20 6d 65 6d 6f 72 |..By silly memor| 00001610 79 20 49 20 6d 65 61 6e 20 74 68 69 6e 67 73 20 |y I mean things | 00001620 6c 69 6b 65 20 61 63 63 69 64 65 6e 74 61 6c 6c |like accidentall| 00001630 79 20 61 73 73 65 6d 62 6c 69 6e 67 0d 74 68 65 |y assembling.the| 00001640 20 63 6f 64 65 20 69 6e 74 6f 20 74 68 65 20 73 | code into the s| 00001650 70 61 63 65 20 69 6e 20 77 68 69 63 68 20 42 41 |pace in which BA| 00001660 53 49 43 20 69 73 20 73 74 6f 72 69 6e 67 20 79 |SIC is storing y| 00001670 6f 75 72 0d 73 6f 75 72 63 65 20 63 6f 64 65 2c |our.source code,| 00001680 20 6f 72 20 70 75 74 74 69 6e 67 20 69 74 20 69 | or putting it i| 00001690 6e 74 6f 20 61 20 63 72 75 63 69 61 6c 20 70 61 |nto a crucial pa| 000016a0 72 74 20 6f 66 20 74 68 65 0d 63 6f 6d 70 75 74 |rt of the.comput| 000016b0 65 72 27 73 20 77 6f 72 6b 20 73 70 61 63 65 2e |er's work space.| 000016c0 20 20 54 72 69 63 6b 73 20 6c 69 6b 65 20 74 68 | Tricks like th| 000016d0 69 73 20 77 69 6c 6c 20 63 65 72 74 61 69 6e 6c |is will certainl| 000016e0 79 0d 63 72 61 73 68 20 74 68 65 20 6d 61 63 68 |y.crash the mach| 000016f0 69 6e 65 20 6f 72 20 6c 6f 73 65 20 79 6f 75 20 |ine or lose you | 00001700 79 6f 75 72 20 73 6f 75 72 63 65 20 63 6f 64 65 |your source code| 00001710 2c 20 62 75 74 20 61 74 20 6c 65 61 73 74 0d 74 |, but at least.t| 00001720 68 65 20 63 6f 6d 70 75 74 65 72 20 77 6f 6e 27 |he computer won'| 00001730 74 20 65 78 70 6c 6f 64 65 21 20 20 28 48 6f 6e |t explode! (Hon| 00001740 65 73 74 21 29 0d 0d 54 68 65 20 63 6f 64 65 20 |est!)..The code | 00001750 69 73 20 61 73 73 65 6d 62 6c 65 64 20 69 6e 20 |is assembled in | 00001760 74 77 6f 20 70 61 73 73 65 73 2c 20 68 65 6e 63 |two passes, henc| 00001770 65 20 74 68 65 20 46 4f 52 2f 4e 45 58 54 0d 6c |e the FOR/NEXT.l| 00001780 6f 6f 70 2e 20 20 54 68 69 73 20 6c 6f 6f 70 2c |oop. This loop,| 00001790 20 62 79 20 73 65 74 74 69 6e 67 20 61 20 76 61 | by setting a va| 000017a0 72 69 61 62 6c 65 20 70 61 73 73 25 20 69 73 20 |riable pass% is | 000017b0 69 6e 73 74 72 75 63 74 69 6e 67 0d 74 68 65 20 |instructing.the | 000017c0 61 73 73 65 6d 62 6c 65 72 20 74 6f 20 77 6f 72 |assembler to wor| 000017d0 6b 20 69 6e 20 61 20 63 65 72 74 61 69 6e 20 77 |k in a certain w| 000017e0 61 79 20 62 79 20 73 65 74 74 69 6e 67 20 61 6e |ay by setting an| 000017f0 20 4f 50 54 0d 66 75 6e 63 74 69 6f 6e 20 28 6e | OPT.function (n| 00001800 6f 74 20 74 6f 20 62 65 20 63 6f 6e 66 75 73 65 |ot to be confuse| 00001810 64 20 77 69 74 68 20 2a 4f 50 54 29 20 61 74 20 |d with *OPT) at | 00001820 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 68 65 |the start of the| 00001830 0d 63 6f 64 65 2e 20 20 54 68 65 20 67 65 6e 65 |.code. The gene| 00001840 72 61 6c 20 69 64 65 61 20 69 73 20 74 68 61 74 |ral idea is that| 00001850 20 64 75 72 69 6e 67 20 74 68 65 20 66 69 72 73 | during the firs| 00001860 74 20 70 61 73 73 20 74 68 65 0d 61 73 73 65 6d |t pass the.assem| 00001870 62 6c 65 72 20 77 69 6c 6c 20 6c 65 61 72 6e 20 |bler will learn | 00001880 77 68 65 72 65 20 61 6c 6c 20 74 68 65 20 6c 61 |where all the la| 00001890 62 65 6c 6c 65 64 20 61 64 64 72 65 73 73 65 73 |belled addresses| 000018a0 20 61 72 65 0d 61 6e 64 20 69 6e 20 74 68 65 20 | are.and in the | 000018b0 73 65 63 6f 6e 64 20 70 61 73 73 20 77 69 6c 6c |second pass will| 000018c0 20 70 6c 61 63 65 20 74 68 6f 73 65 20 61 64 64 | place those add| 000018d0 72 65 73 73 65 73 20 69 6e 74 6f 20 74 68 65 0d |resses into the.| 000018e0 63 6f 64 65 2e 20 20 44 75 72 69 6e 67 20 74 68 |code. During th| 000018f0 65 20 66 69 72 73 74 20 70 61 73 73 20 28 77 69 |e first pass (wi| 00001900 74 68 20 4f 50 54 3d 30 29 20 65 72 72 6f 72 20 |th OPT=0) error | 00001910 74 72 61 70 70 69 6e 67 20 69 73 0d 74 75 72 6e |trapping is.turn| 00001920 65 64 20 6f 66 66 3b 20 6f 74 68 65 72 77 69 73 |ed off; otherwis| 00001930 65 20 61 20 6c 61 62 65 6c 20 70 6f 69 6e 74 69 |e a label pointi| 00001940 6e 67 20 74 6f 20 61 20 70 69 65 63 65 20 6f 66 |ng to a piece of| 00001950 20 6d 65 6d 6f 72 79 0d 6c 61 74 65 72 20 69 6e | memory.later in| 00001960 20 74 68 65 20 70 72 6f 67 72 61 6d 20 77 6f 75 | the program wou| 00001970 6c 64 20 63 61 75 73 65 20 61 20 27 6e 6f 20 73 |ld cause a 'no s| 00001980 75 63 68 20 76 61 72 69 61 62 6c 65 27 20 65 72 |uch variable' er| 00001990 72 6f 72 2e 20 0d 41 6c 73 6f 20 74 68 65 20 61 |ror. .Also the a| 000019a0 73 73 65 6d 62 6c 65 72 20 69 73 20 69 6e 73 74 |ssembler is inst| 000019b0 72 75 63 74 65 64 20 6e 6f 74 20 74 6f 20 6c 69 |ructed not to li| 000019c0 73 74 20 74 68 65 20 61 73 73 65 6d 62 6c 79 20 |st the assembly | 000019d0 74 6f 0d 73 63 72 65 65 6e 20 69 6e 20 74 68 65 |to.screen in the| 000019e0 20 66 69 72 73 74 20 70 61 73 73 2e 20 20 49 6e | first pass. In| 000019f0 20 74 68 65 20 73 65 63 6f 6e 64 20 70 61 73 73 | the second pass| 00001a00 20 28 77 69 74 68 20 4f 50 54 3d 33 29 0d 65 72 | (with OPT=3).er| 00001a10 72 6f 72 20 74 72 61 70 70 69 6e 67 20 69 73 20 |ror trapping is | 00001a20 74 75 72 6e 65 64 20 6f 6e 20 61 6e 64 20 61 20 |turned on and a | 00001a30 6c 69 73 74 69 6e 67 20 69 73 20 70 72 6f 64 75 |listing is produ| 00001a40 63 65 64 2e 20 20 54 68 69 73 0d 6c 69 73 74 69 |ced. This.listi| 00001a50 6e 67 20 6f 66 20 74 68 65 20 61 73 73 65 6d 62 |ng of the assemb| 00001a60 6c 79 20 69 73 20 6f 70 74 69 6f 6e 61 6c 20 62 |ly is optional b| 00001a70 75 74 20 75 73 65 66 75 6c 2e 0d 0d 50 25 2c 20 |ut useful...P%, | 00001a80 73 65 74 20 65 71 75 61 6c 20 74 6f 20 63 6f 64 |set equal to cod| 00001a90 65 25 20 69 6e 20 6c 69 6e 65 20 36 30 2c 20 69 |e% in line 60, i| 00001aa0 73 20 61 20 42 41 53 49 43 20 76 61 72 69 61 62 |s a BASIC variab| 00001ab0 6c 65 20 77 68 69 63 68 0d 69 73 20 74 69 65 64 |le which.is tied| 00001ac0 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 68 65 | to the value he| 00001ad0 6c 64 20 69 6e 20 6f 6e 65 20 6f 66 20 74 68 65 |ld in one of the| 00001ae0 20 6d 69 63 72 6f 70 72 6f 63 65 73 73 6f 72 27 | microprocessor'| 00001af0 73 0d 72 65 67 69 73 74 65 72 73 20 6f 72 20 6e |s.registers or n| 00001b00 75 6d 62 65 72 20 73 74 6f 72 65 73 2c 20 63 61 |umber stores, ca| 00001b10 6c 6c 65 64 20 74 68 65 20 70 72 6f 67 72 61 6d |lled the program| 00001b20 20 63 6f 75 6e 74 65 72 2e 20 20 41 73 0d 79 6f | counter. As.yo| 00001b30 75 72 20 63 6f 64 65 20 69 73 20 61 73 73 65 6d |ur code is assem| 00001b40 62 6c 65 64 20 74 68 65 20 61 73 73 65 6d 62 6c |bled the assembl| 00001b50 65 72 20 73 65 74 73 20 50 25 20 74 6f 20 74 68 |er sets P% to th| 00001b60 65 20 61 64 64 72 65 73 73 0d 6f 66 20 74 68 65 |e address.of the| 00001b70 20 6e 65 78 74 20 70 69 65 63 65 20 6f 66 20 63 | next piece of c| 00001b80 6f 64 65 20 74 6f 20 62 65 20 61 73 73 65 6d 62 |ode to be assemb| 00001b90 6c 65 64 2e 20 20 41 74 20 74 68 65 20 62 65 67 |led. At the beg| 00001ba0 69 6e 6e 69 6e 67 0d 6f 66 20 65 61 63 68 20 70 |inning.of each p| 00001bb0 61 73 73 20 6f 66 20 74 68 65 20 61 73 73 65 6d |ass of the assem| 00001bc0 62 6c 79 20 50 25 20 69 73 20 72 65 73 65 74 20 |bly P% is reset | 00001bd0 74 6f 20 74 68 65 20 73 74 61 72 74 20 6f 66 0d |to the start of.| 00001be0 79 6f 75 72 20 63 68 75 6e 6b 20 6f 66 20 6d 65 |your chunk of me| 00001bf0 6d 6f 72 79 2e 20 20 54 68 61 74 20 69 73 20 77 |mory. That is w| 00001c00 68 79 20 50 25 20 69 73 20 73 65 74 20 69 6e 73 |hy P% is set ins| 00001c10 69 64 65 20 74 68 65 0d 46 4f 52 2f 4e 45 58 54 |ide the.FOR/NEXT| 00001c20 20 6c 6f 6f 70 2e 20 20 57 68 65 6e 20 79 6f 75 | loop. When you| 00001c30 72 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 69 |r machine code i| 00001c40 73 20 65 78 65 63 75 74 65 64 2c 20 66 61 6e 63 |s executed, fanc| 00001c50 79 0d 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 6a |y.machine code j| 00001c60 61 72 67 6f 6e 20 66 6f 72 20 27 72 75 6e 27 2c |argon for 'run',| 00001c70 20 74 68 65 20 72 65 61 6c 20 70 72 6f 67 72 61 | the real progra| 00001c80 6d 20 63 6f 75 6e 74 65 72 20 69 6e 0d 74 68 65 |m counter in.the| 00001c90 20 6d 69 63 72 6f 70 72 6f 63 65 73 73 6f 72 20 | microprocessor | 00001ca0 6b 65 65 70 73 20 74 72 61 63 6b 20 6f 66 20 74 |keeps track of t| 00001cb0 68 65 20 6e 65 78 74 20 63 6f 6d 6d 61 6e 64 20 |he next command | 00001cc0 74 6f 20 62 65 0d 63 61 72 72 69 65 64 20 6f 75 |to be.carried ou| 00001cd0 74 2e 20 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 |t. In other wor| 00001ce0 64 73 20 50 25 20 6b 65 65 70 73 20 74 72 61 63 |ds P% keeps trac| 00001cf0 6b 20 6f 66 20 74 68 65 20 61 64 64 72 65 73 73 |k of the address| 00001d00 65 73 0d 6f 66 20 69 6e 73 74 72 75 63 74 69 6f |es.of instructio| 00001d10 6e 73 20 64 75 72 69 6e 67 20 61 73 73 65 6d 62 |ns during assemb| 00001d20 6c 79 20 69 6e 20 74 68 65 20 73 61 6d 65 20 77 |ly in the same w| 00001d30 61 79 20 74 68 65 20 70 72 6f 67 72 61 6d 0d 63 |ay the program.c| 00001d40 6f 75 6e 74 65 72 20 70 72 6f 70 65 72 20 64 6f |ounter proper do| 00001d50 65 73 20 64 75 72 69 6e 67 20 65 78 65 63 75 74 |es during execut| 00001d60 69 6f 6e 2e 0d 0d 54 68 65 20 73 71 75 61 72 65 |ion...The square| 00001d70 20 62 72 61 63 6b 65 74 73 20 69 6e 20 6c 69 6e | brackets in lin| 00001d80 65 73 20 37 30 20 61 6e 64 20 35 30 30 20 6d 61 |es 70 and 500 ma| 00001d90 72 6b 20 74 68 65 20 73 74 61 72 74 20 61 6e 64 |rk the start and| 00001da0 0d 66 69 6e 69 73 68 20 6f 66 20 74 68 65 20 61 |.finish of the a| 00001db0 73 73 65 6d 62 6c 65 72 20 69 6e 20 79 6f 75 72 |ssembler in your| 00001dc0 20 42 41 53 49 43 20 70 72 6f 67 72 61 6d 2e 20 | BASIC program. | 00001dd0 20 49 6e 20 6d 6f 64 65 20 37 0d 74 68 65 79 20 | In mode 7.they | 00001de0 63 6f 6d 65 20 6f 75 74 20 61 73 20 61 72 72 6f |come out as arro| 00001df0 77 73 20 62 75 74 20 6d 65 61 6e 20 74 68 65 20 |ws but mean the | 00001e00 73 61 6d 65 20 74 68 69 6e 67 2e 0d 0d 48 65 72 |same thing...Her| 00001e10 65 27 73 20 61 20 6c 69 74 74 6c 65 20 6d 6f 72 |e's a little mor| 00001e20 65 20 63 6f 64 65 3a 0d 0d 20 20 09 31 30 30 20 |e code:.. .100 | 00001e30 2e 66 69 72 73 74 0d 20 20 09 31 31 30 20 4c 44 |.first. .110 LD| 00001e40 41 20 23 33 32 09 20 20 20 20 20 20 20 20 20 20 |A #32. | 00001e50 20 20 20 20 09 5c 20 74 68 69 73 20 69 73 20 61 | .\ this is a| 00001e60 20 63 6f 6d 6d 65 6e 74 0d 20 20 09 31 32 30 20 | comment. .120 | 00001e70 43 4c 43 3a 41 44 43 23 32 30 3a 53 54 41 20 26 |CLC:ADC#20:STA &| 00001e80 37 30 0d 0d 41 74 20 6c 69 6e 65 20 31 30 30 20 |70..At line 100 | 00001e90 69 73 20 61 20 6c 61 62 65 6c 2e 20 20 49 74 20 |is a label. It | 00001ea0 69 73 20 73 69 6d 70 6c 79 20 61 20 76 61 72 69 |is simply a vari| 00001eb0 61 62 6c 65 20 6e 61 6d 65 20 74 68 61 74 0d 77 |able name that.w| 00001ec0 69 6c 6c 20 68 6f 6c 64 20 74 68 65 20 61 64 64 |ill hold the add| 00001ed0 72 65 73 73 20 61 74 20 74 68 69 73 20 70 6f 69 |ress at this poi| 00001ee0 6e 74 2e 20 20 54 68 65 20 61 73 73 65 6d 62 6c |nt. The assembl| 00001ef0 65 72 20 6b 6e 6f 77 73 0d 69 74 27 73 20 61 20 |er knows.it's a | 00001f00 6c 61 62 65 6c 20 62 65 63 61 75 73 65 20 79 6f |label because yo| 00001f10 75 20 68 61 76 65 20 70 75 74 20 61 20 66 75 6c |u have put a ful| 00001f20 6c 20 73 74 6f 70 20 69 6e 20 66 72 6f 6e 74 20 |l stop in front | 00001f30 6f 66 0d 69 74 2e 20 20 49 74 20 69 73 20 69 6d |of.it. It is im| 00001f40 70 6f 72 74 61 6e 74 20 74 6f 20 72 65 6d 65 6d |portant to remem| 00001f50 62 65 72 20 74 68 61 74 20 69 6e 20 61 73 73 65 |ber that in asse| 00001f60 6d 62 6c 65 72 20 79 6f 75 20 73 74 6f 72 65 0d |mbler you store.| 00001f70 61 20 6e 75 6d 62 65 72 20 61 74 20 61 6e 20 61 |a number at an a| 00001f80 64 64 72 65 73 73 20 61 6e 64 20 74 68 65 20 61 |ddress and the a| 00001f90 64 64 72 65 73 73 20 69 73 20 6f 66 74 65 6e 20 |ddress is often | 00001fa0 68 65 6c 64 20 61 73 20 61 0d 76 61 72 69 61 62 |held as a.variab| 00001fb0 6c 65 2e 20 20 44 6f 6e 27 74 20 74 68 69 6e 6b |le. Don't think| 00001fc0 20 6f 66 20 74 68 65 20 6e 75 6d 62 65 72 20 61 | of the number a| 00001fd0 73 20 62 65 69 6e 67 20 73 74 6f 72 65 64 20 69 |s being stored i| 00001fe0 6e 20 74 68 65 0d 76 61 72 69 61 62 6c 65 20 69 |n the.variable i| 00001ff0 74 73 65 6c 66 2e 0d 0d 54 68 65 20 73 65 63 6f |tself...The seco| 00002000 6e 64 20 70 61 72 74 20 6f 66 20 6c 69 6e 65 20 |nd part of line | 00002010 31 31 30 20 69 73 20 61 20 63 6f 6d 6d 65 6e 74 |110 is a comment| 00002020 2e 20 20 41 6e 79 74 68 69 6e 67 0d 66 6f 6c 6c |. Anything.foll| 00002030 6f 77 69 6e 67 20 61 20 62 61 63 6b 2d 73 6c 61 |owing a back-sla| 00002040 73 68 20 69 73 20 69 67 6e 6f 72 65 64 20 62 79 |sh is ignored by| 00002050 20 74 68 65 20 61 73 73 65 6d 62 6c 65 72 2c 20 | the assembler, | 00002060 6c 69 6b 65 20 52 45 4d 0d 69 6e 20 42 41 53 49 |like REM.in BASI| 00002070 43 2e 20 20 43 6f 6d 6d 65 6e 74 20 79 6f 75 72 |C. Comment your| 00002080 20 70 72 6f 67 72 61 6d 73 20 6c 69 62 65 72 61 | programs libera| 00002090 6c 6c 79 21 0d 0d 4c 61 79 6f 75 74 20 6f 66 20 |lly!..Layout of | 000020a0 74 68 65 20 61 73 73 65 6d 62 6c 79 20 70 72 6f |the assembly pro| 000020b0 67 72 61 6d 20 69 73 20 75 70 20 74 6f 20 79 6f |gram is up to yo| 000020c0 75 2e 20 20 49 74 20 69 73 20 6c 65 67 61 6c 20 |u. It is legal | 000020d0 74 6f 0d 6a 6f 69 6e 20 73 74 61 74 65 6d 65 6e |to.join statemen| 000020e0 74 73 20 77 69 74 68 20 63 6f 6c 6f 6e 73 20 6a |ts with colons j| 000020f0 75 73 74 20 6c 69 6b 65 20 42 41 53 49 43 2c 20 |ust like BASIC, | 00002100 62 75 74 20 74 68 65 72 65 20 69 73 20 6e 6f 0d |but there is no.| 00002110 72 65 61 6c 20 62 65 6e 65 66 69 74 20 61 6e 64 |real benefit and| 00002120 20 69 74 20 72 65 64 75 63 65 73 20 74 68 65 20 | it reduces the | 00002130 72 65 61 64 61 62 69 6c 69 74 79 20 6f 66 20 79 |readability of y| 00002140 6f 75 72 20 73 6f 75 72 63 65 0d 63 6f 64 65 2e |our source.code.| 00002150 20 20 59 6f 75 20 63 61 6e 20 70 75 74 20 6c 61 | You can put la| 00002160 62 65 6c 73 20 6f 6e 20 74 68 65 20 73 61 6d 65 |bels on the same| 00002170 20 6c 69 6e 65 20 61 73 20 73 74 61 74 65 6d 65 | line as stateme| 00002180 6e 74 73 20 62 75 74 0d 6d 79 20 70 65 72 73 6f |nts but.my perso| 00002190 6e 61 6c 20 70 72 65 66 65 72 65 6e 63 65 20 69 |nal preference i| 000021a0 73 20 74 6f 20 70 75 74 20 74 68 65 20 6c 61 62 |s to put the lab| 000021b0 65 6c 73 20 6f 6e 20 73 65 70 61 72 61 74 65 0d |els on separate.| 000021c0 6c 69 6e 65 73 2e 0d 0d 54 68 65 20 70 72 6f 67 |lines...The prog| 000021d0 72 61 6d 20 42 2f 6f 73 62 30 31 20 69 6e 20 74 |ram B/osb01 in t| 000021e0 68 69 73 20 74 65 6c 65 73 6f 66 74 77 61 72 65 |his telesoftware| 000021f0 20 74 72 61 6e 73 6d 69 73 73 69 6f 6e 20 69 73 | transmission is| 00002200 20 61 0d 73 69 6d 70 6c 65 20 61 73 73 65 6d 62 | a.simple assemb| 00002210 6c 65 72 20 70 72 6f 67 72 61 6d 20 74 6f 20 70 |ler program to p| 00002220 72 69 6e 74 20 6f 75 74 20 61 20 6d 65 73 73 61 |rint out a messa| 00002230 67 65 20 74 6f 20 74 68 65 0d 73 63 72 65 65 6e |ge to the.screen| 00002240 2c 20 61 20 73 6f 72 74 20 6f 66 20 63 6f 6e 66 |, a sort of conf| 00002250 69 64 65 6e 63 65 20 74 65 73 74 2e 20 20 54 68 |idence test. Th| 00002260 69 73 20 69 73 20 68 6f 77 20 69 74 20 77 6f 72 |is is how it wor| 00002270 6b 73 3a 0d 0d 20 20 20 31 30 52 45 4d 20 20 4f |ks:.. 10REM O| 00002280 53 62 69 74 73 20 4d 6f 64 75 6c 65 20 42 2f 6f |Sbits Module B/o| 00002290 73 62 30 31 0d 20 20 20 32 30 52 45 4d 20 20 49 |sb01. 20REM I| 000022a0 6e 74 72 6f 64 75 63 74 69 6f 6e 20 74 6f 20 74 |ntroduction to t| 000022b0 68 65 20 42 42 43 20 41 73 73 65 6d 62 6c 65 72 |he BBC Assembler| 000022c0 0d 20 20 20 33 30 52 45 4d 20 20 56 65 72 73 69 |. 30REM Versi| 000022d0 6f 6e 20 31 2e 30 20 2d 20 31 37 2e 38 2e 38 36 |on 1.0 - 17.8.86| 000022e0 0d 20 20 20 34 30 0d 0d 49 74 27 73 20 61 6c 77 |. 40..It's alw| 000022f0 61 79 73 20 61 20 67 6f 6f 64 20 69 64 65 61 20 |ays a good idea | 00002300 74 6f 20 69 64 65 6e 74 69 66 79 20 79 6f 75 72 |to identify your| 00002310 20 70 72 6f 67 72 61 6d 73 20 61 6e 64 20 70 75 | programs and pu| 00002320 74 20 61 0d 76 65 72 73 69 6f 6e 20 6e 75 6d 62 |t a.version numb| 00002330 65 72 20 61 6e 64 20 64 61 74 65 20 6f 6e 20 74 |er and date on t| 00002340 68 65 6d 2e 0d 0d 20 20 20 35 30 20 2a 4b 45 59 |hem... 50 *KEY| 00002350 31 4d 4f 2e 33 7c 4d 7c 4e 4c 2e 7c 4d 0d 20 20 |1MO.3|M|NL.|M. | 00002360 20 36 30 20 0d 0d 49 20 61 6c 77 61 79 73 20 77 | 60 ..I always w| 00002370 6f 72 6b 20 69 6e 20 4d 6f 64 65 20 33 20 66 6f |ork in Mode 3 fo| 00002380 72 20 61 73 73 65 6d 62 6c 65 72 2e 20 20 54 68 |r assembler. Th| 00002390 69 73 20 67 69 76 65 73 20 70 6c 65 6e 74 79 20 |is gives plenty | 000023a0 6f 66 0d 72 6f 6f 6d 20 66 6f 72 20 63 6f 6d 6d |of.room for comm| 000023b0 65 6e 74 73 20 61 6e 64 20 61 6c 73 6f 20 74 68 |ents and also th| 000023c0 69 6e 67 73 20 6c 69 6b 65 20 74 68 65 20 62 61 |ings like the ba| 000023d0 63 6b 73 6c 61 73 68 20 61 6e 64 0d 73 71 75 61 |ckslash and.squa| 000023e0 72 65 20 62 72 61 63 6b 65 74 73 20 63 6f 6d 65 |re brackets come| 000023f0 20 6f 75 74 20 72 69 67 68 74 2c 20 77 68 69 63 | out right, whic| 00002400 68 20 74 68 65 79 20 64 6f 6e 27 74 20 69 6e 20 |h they don't in | 00002410 4d 6f 64 65 20 37 2e 0d 53 6f 20 49 20 73 65 74 |Mode 7..So I set| 00002420 20 75 70 20 66 75 6e 63 74 69 6f 6e 20 6b 65 79 | up function key| 00002430 20 31 20 74 6f 20 67 69 76 65 20 6d 65 20 61 20 | 1 to give me a | 00002440 6c 69 73 74 69 6e 67 20 69 6e 20 4d 6f 64 65 20 |listing in Mode | 00002450 33 2e 0d 0d 20 20 20 37 30 20 6f 73 61 73 63 69 |3... 70 osasci| 00002460 3d 26 46 46 45 33 0d 0d 4f 53 41 53 43 49 20 69 |=&FFE3..OSASCI i| 00002470 73 20 6f 6e 65 20 6f 66 20 61 20 73 65 74 20 6f |s one of a set o| 00002480 66 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 |f operating syst| 00002490 65 6d 20 72 6f 75 74 69 6e 65 73 20 62 75 69 6c |em routines buil| 000024a0 74 0d 69 6e 74 6f 20 74 68 65 20 42 42 43 20 6d |t.into the BBC m| 000024b0 69 63 72 6f 2e 20 20 49 74 20 73 74 61 72 74 73 |icro. It starts| 000024c0 20 61 74 20 61 64 64 72 65 73 73 20 26 46 46 45 | at address &FFE| 000024d0 33 2e 20 20 49 27 6c 6c 20 62 65 0d 64 65 61 6c |3. I'll be.deal| 000024e0 69 6e 67 20 77 69 74 68 20 6f 70 65 72 61 74 69 |ing with operati| 000024f0 6e 67 20 73 79 73 74 65 6d 20 72 6f 75 74 69 6e |ng system routin| 00002500 65 73 20 69 6e 20 64 65 74 61 69 6c 20 6c 61 74 |es in detail lat| 00002510 65 72 2e 20 0d 4f 53 41 53 43 49 20 74 61 6b 65 |er. .OSASCI take| 00002520 73 20 74 68 65 20 6e 75 6d 62 65 72 20 69 6e 20 |s the number in | 00002530 74 68 65 20 41 63 63 75 6d 75 6c 61 74 6f 72 20 |the Accumulator | 00002540 28 77 68 69 63 68 20 49 27 6c 6c 20 63 61 6c 6c |(which I'll call| 00002550 0d 41 29 20 61 6e 64 20 73 65 6e 64 73 20 69 74 |.A) and sends it| 00002560 20 74 6f 20 74 68 65 20 73 63 72 65 65 6e 2c 20 | to the screen, | 00002570 65 78 61 63 74 6c 79 20 6c 69 6b 65 20 56 44 55 |exactly like VDU| 00002580 20 3f 41 20 77 6f 75 6c 64 20 69 6e 0d 42 41 53 | ?A would in.BAS| 00002590 49 43 20 69 66 20 79 6f 75 20 63 6f 75 6c 64 20 |IC if you could | 000025a0 72 65 61 64 20 74 68 65 20 63 6f 6e 74 65 6e 74 |read the content| 000025b0 73 20 6f 66 20 74 68 65 20 61 63 63 75 6d 75 6c |s of the accumul| 000025c0 61 74 6f 72 20 77 69 74 68 0d 61 20 3f 2e 20 20 |ator with.a ?. | 000025d0 28 54 68 65 20 41 63 63 75 6d 75 6c 61 74 6f 72 |(The Accumulator| 000025e0 20 61 6e 64 20 74 68 65 20 58 20 61 6e 64 20 59 | and the X and Y| 000025f0 20 72 65 67 69 73 74 65 72 73 20 61 72 65 20 74 | registers are t| 00002600 68 65 0d 74 68 72 65 65 20 70 6c 61 63 65 73 20 |he.three places | 00002610 74 6f 20 73 74 6f 72 65 20 61 6e 64 20 6d 61 6e |to store and man| 00002620 69 70 75 6c 61 74 65 20 6e 75 6d 62 65 72 73 20 |ipulate numbers | 00002630 74 68 61 74 20 61 72 65 0d 61 63 74 75 61 6c 6c |that are.actuall| 00002640 79 20 77 69 74 68 69 6e 20 74 68 65 20 6d 69 63 |y within the mic| 00002650 72 6f 70 72 6f 63 65 73 73 6f 72 2c 20 61 67 61 |roprocessor, aga| 00002660 69 6e 20 6d 6f 72 65 20 6c 61 74 65 72 2e 29 0d |in more later.).| 00002670 0d 54 68 65 20 76 61 72 69 61 62 6c 65 20 69 73 |.The variable is| 00002680 20 69 6e 20 6c 6f 77 65 72 20 63 61 73 65 20 62 | in lower case b| 00002690 65 63 61 75 73 65 20 49 20 67 69 76 65 20 61 6c |ecause I give al| 000026a0 6c 20 6d 79 0d 61 73 73 65 6d 62 6c 65 72 20 76 |l my.assembler v| 000026b0 61 72 69 61 62 6c 65 73 20 6c 6f 77 65 72 20 63 |ariables lower c| 000026c0 61 73 65 20 6e 61 6d 65 73 2e 20 20 49 20 66 69 |ase names. I fi| 000026d0 6e 64 20 69 74 20 61 69 64 73 0d 72 65 61 64 61 |nd it aids.reada| 000026e0 62 69 6c 69 74 79 20 61 6e 64 20 6b 65 65 70 73 |bility and keeps| 000026f0 20 79 6f 75 20 63 6f 6d 70 6c 65 74 65 6c 79 20 | you completely | 00002700 63 6c 65 61 72 20 6f 66 20 61 6e 79 20 70 72 6f |clear of any pro| 00002710 62 6c 65 6d 73 0d 6f 66 20 63 6c 61 73 68 65 73 |blems.of clashes| 00002720 20 77 69 74 68 20 42 41 53 49 43 20 72 65 73 65 | with BASIC rese| 00002730 72 76 65 64 20 77 6f 72 64 73 2e 0d 0d 20 20 20 |rved words... | 00002740 38 30 20 63 6f 64 65 25 20 3d 20 26 33 30 30 30 |80 code% = &3000| 00002750 0d 20 20 20 39 30 20 0d 20 20 31 30 30 20 46 4f |. 90 . 100 FO| 00002760 52 20 70 61 73 73 25 3d 30 20 54 4f 20 33 20 53 |R pass%=0 TO 3 S| 00002770 54 45 50 20 33 0d 20 20 31 31 30 20 50 25 3d 63 |TEP 3. 110 P%=c| 00002780 6f 64 65 25 0d 20 20 31 32 30 20 0d 20 20 31 33 |ode%. 120 . 13| 00002790 30 20 5b 4f 50 54 20 70 61 73 73 25 0d 20 20 31 |0 [OPT pass%. 1| 000027a0 34 30 20 4c 44 58 20 23 30 0d 20 20 31 35 30 20 |40 LDX #0. 150 | 000027b0 20 0d 0d 54 68 69 73 20 73 65 74 73 20 75 70 20 | ..This sets up | 000027c0 74 68 65 20 61 73 73 65 6d 62 6c 79 20 61 6e 64 |the assembly and| 000027d0 20 70 75 74 73 20 61 20 7a 65 72 6f 20 69 6e 74 | puts a zero int| 000027e0 6f 20 74 68 65 20 58 0d 72 65 67 69 73 74 65 72 |o the X.register| 000027f0 2c 20 77 68 69 63 68 20 77 65 20 77 69 6c 6c 20 |, which we will | 00002800 75 73 65 20 61 73 20 61 20 63 6f 75 6e 74 65 72 |use as a counter| 00002810 2e 20 20 48 65 72 65 20 77 65 20 77 69 6c 6c 0d |. Here we will.| 00002820 61 73 73 65 6d 62 6c 65 20 74 68 65 20 63 6f 64 |assemble the cod| 00002830 65 20 61 74 20 61 64 64 72 65 73 73 20 26 33 30 |e at address &30| 00002840 30 30 2c 20 77 68 69 63 68 20 73 68 6f 75 6c 64 |00, which should| 00002850 20 62 65 20 73 61 66 65 20 69 6e 0d 4d 6f 64 65 | be safe in.Mode| 00002860 73 20 33 20 61 6e 64 20 37 2c 20 72 61 74 68 65 |s 3 and 7, rathe| 00002870 72 20 74 68 61 6e 20 6c 65 74 20 42 41 53 49 43 |r than let BASIC| 00002880 20 66 69 6e 64 20 73 6f 6d 65 20 73 70 61 63 65 | find some space| 00002890 2e 20 20 54 68 69 73 0d 69 73 20 73 69 6d 70 6c |. This.is simpl| 000028a0 79 20 73 6f 20 74 68 61 74 20 74 68 65 20 6c 69 |y so that the li| 000028b0 73 74 69 6e 67 20 77 69 6c 6c 20 62 65 20 70 72 |sting will be pr| 000028c0 65 64 69 63 74 61 62 6c 65 20 77 68 65 6e 20 77 |edictable when w| 000028d0 65 0d 63 6f 6d 70 61 72 65 20 72 65 73 75 6c 74 |e.compare result| 000028e0 73 20 61 74 20 74 68 65 20 65 6e 64 21 0d 0d 20 |s at the end!.. | 000028f0 20 31 36 30 20 2e 6c 6f 6f 70 0d 20 20 31 37 30 | 160 .loop. 170| 00002900 20 4c 44 41 20 74 65 78 74 2c 58 0d 0d 4c 44 41 | LDA text,X..LDA| 00002910 20 74 65 78 74 2c 58 20 69 73 20 74 68 65 20 73 | text,X is the s| 00002920 74 61 72 74 20 6f 66 20 6f 75 72 20 6c 6f 6f 70 |tart of our loop| 00002930 20 28 6c 61 62 65 6c 6c 65 64 20 27 6c 6f 6f 70 | (labelled 'loop| 00002940 27 29 20 74 6f 0d 70 72 69 6e 74 20 6f 75 74 20 |') to.print out | 00002950 63 68 61 72 61 63 74 65 72 73 20 74 61 6b 65 6e |characters taken| 00002960 20 66 72 6f 6d 20 61 20 73 74 72 69 6e 67 20 73 | from a string s| 00002970 74 6f 72 65 64 20 73 74 61 72 74 69 6e 67 20 61 |tored starting a| 00002980 74 0d 61 64 64 72 65 73 73 20 27 74 65 78 74 27 |t.address 'text'| 00002990 2e 20 20 4c 6f 61 44 20 74 68 65 20 41 63 63 75 |. LoaD the Accu| 000029a0 6d 75 6c 61 74 6f 72 20 77 69 74 68 20 74 68 65 |mulator with the| 000029b0 20 6e 75 6d 62 65 72 20 73 74 6f 72 65 64 0d 61 | number stored.a| 000029c0 74 20 74 68 65 20 61 64 64 72 65 73 73 20 67 69 |t the address gi| 000029d0 76 65 6e 20 62 79 20 27 74 65 78 74 27 2b 58 2e |ven by 'text'+X.| 000029e0 0d 0d 20 20 31 38 30 20 4a 53 52 20 6f 73 61 73 |.. 180 JSR osas| 000029f0 63 69 0d 20 20 31 39 30 20 49 4e 58 0d 0d 44 6f |ci. 190 INX..Do| 00002a00 20 61 20 56 44 55 20 3f 41 20 61 6e 64 20 74 68 | a VDU ?A and th| 00002a10 65 6e 20 49 4e 63 72 65 61 73 65 20 58 20 62 79 |en INcrease X by| 00002a20 20 6f 6e 65 2e 20 20 4f 53 41 53 43 49 20 69 73 | one. OSASCI is| 00002a30 20 61 0d 73 75 62 72 6f 75 74 69 6e 65 20 61 6e | a.subroutine an| 00002a40 64 20 4a 53 52 20 6d 65 61 6e 73 20 4a 75 6d 70 |d JSR means Jump| 00002a50 20 74 6f 20 53 75 62 52 6f 75 74 69 6e 65 20 61 | to SubRoutine a| 00002a60 6e 64 20 74 68 65 6e 20 63 6f 6d 65 0d 62 61 63 |nd then come.bac| 00002a70 6b 2e 20 20 41 20 73 75 62 72 6f 75 74 69 6e 65 |k. A subroutine| 00002a80 20 69 73 20 61 20 73 65 6c 66 2d 63 6f 6e 74 61 | is a self-conta| 00002a90 69 6e 65 64 20 63 68 75 6e 6b 20 6f 66 20 63 6f |ined chunk of co| 00002aa0 64 65 20 28 61 20 62 69 74 0d 6c 69 6b 65 20 61 |de (a bit.like a| 00002ab0 20 70 72 6f 63 65 64 75 72 65 20 69 6e 20 42 42 | procedure in BB| 00002ac0 43 20 42 41 53 49 43 29 20 73 74 61 72 74 69 6e |C BASIC) startin| 00002ad0 67 20 61 74 20 74 68 65 20 61 64 64 72 65 73 73 |g at the address| 00002ae0 20 74 6f 0d 77 68 69 63 68 20 79 6f 75 20 4a 53 | to.which you JS| 00002af0 52 2e 20 20 49 74 20 61 6c 77 61 79 73 20 65 6e |R. It always en| 00002b00 64 73 20 77 69 74 68 20 61 6e 20 52 54 53 20 63 |ds with an RTS c| 00002b10 6f 6d 6d 61 6e 64 20 28 6d 65 61 6e 69 6e 67 0d |ommand (meaning.| 00002b20 52 65 54 75 72 6e 20 66 72 6f 6d 20 53 75 62 72 |ReTurn from Subr| 00002b30 6f 75 74 69 6e 65 29 2e 0d 0d 20 20 32 30 30 20 |outine)... 200 | 00002b40 43 4d 50 20 23 31 33 0d 20 20 32 31 30 20 42 4e |CMP #13. 210 BN| 00002b50 45 20 6c 6f 6f 70 0d 20 20 32 32 30 20 20 0d 0d |E loop. 220 ..| 00002b60 43 6f 4d 50 61 72 65 20 74 68 65 20 63 6f 6e 74 |CoMPare the cont| 00002b70 65 6e 74 73 20 6f 66 20 41 20 77 69 74 68 20 31 |ents of A with 1| 00002b80 33 20 61 6e 64 20 74 68 65 6e 20 42 72 61 6e 63 |3 and then Branc| 00002b90 68 20 69 66 20 4e 6f 74 0d 45 71 75 61 6c 20 62 |h if Not.Equal b| 00002ba0 61 63 6b 20 74 6f 20 27 6c 6f 6f 70 27 2e 20 20 |ack to 'loop'. | 00002bb0 28 54 68 69 73 20 69 73 20 6f 6e 6c 79 20 61 20 |(This is only a | 00002bc0 72 6f 75 67 68 20 64 65 73 63 72 69 70 74 69 6f |rough descriptio| 00002bd0 6e 20 6f 66 0d 77 68 61 74 20 43 4d 50 2f 42 4e |n of.what CMP/BN| 00002be0 45 20 61 63 74 75 61 6c 6c 79 20 6d 65 61 6e 73 |E actually means| 00002bf0 2e 29 0d 0d 20 20 32 33 30 20 52 54 53 0d 20 20 |.).. 230 RTS. | 00002c00 32 34 30 20 20 0d 0d 4f 75 72 20 6c 69 74 74 6c |240 ..Our littl| 00002c10 65 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 70 |e machine code p| 00002c20 72 6f 67 72 61 6d 6d 65 20 62 65 68 61 76 65 73 |rogramme behaves| 00002c30 20 61 73 20 69 66 20 69 74 20 77 65 72 65 20 61 | as if it were a| 00002c40 0d 73 75 62 72 6f 75 74 69 6e 65 20 63 61 6c 6c |.subroutine call| 00002c50 65 64 20 66 72 6f 6d 20 42 41 53 49 43 20 73 6f |ed from BASIC so| 00002c60 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20 74 | at the end of t| 00002c70 68 65 20 61 63 74 69 76 65 0d 70 61 72 74 20 6f |he active.part o| 00002c80 66 20 74 68 65 20 70 72 6f 67 72 61 6d 20 77 65 |f the program we| 00002c90 20 52 65 54 75 72 6e 20 66 72 6f 6d 20 74 68 65 | ReTurn from the| 00002ca0 20 53 75 62 72 6f 75 74 69 6e 65 2e 20 20 54 72 | Subroutine. Tr| 00002cb0 79 0d 64 65 6c 65 74 69 6e 67 20 74 68 69 73 20 |y.deleting this | 00002cc0 6c 69 6e 65 2c 20 79 6f 75 20 77 69 6c 6c 20 68 |line, you will h| 00002cd0 61 76 65 20 74 6f 20 70 72 65 73 73 20 42 52 45 |ave to press BRE| 00002ce0 41 4b 20 61 6e 64 20 74 68 65 6e 0d 74 79 70 65 |AK and then.type| 00002cf0 20 4f 4c 44 20 74 6f 20 72 65 63 6f 76 65 72 20 | OLD to recover | 00002d00 61 66 74 65 72 20 79 6f 75 20 63 61 6c 6c 20 79 |after you call y| 00002d10 6f 75 72 20 63 6f 64 65 20 69 66 20 79 6f 75 20 |our code if you | 00002d20 64 6f 21 0d 0d 20 20 32 35 30 20 2e 74 65 78 74 |do!.. 250 .text| 00002d30 0d 20 20 32 36 30 20 5d 0d 20 20 32 37 30 20 4e |. 260 ]. 270 N| 00002d40 45 58 54 0d 20 20 32 38 30 20 20 0d 20 20 32 39 |EXT. 280 . 29| 00002d50 30 20 24 50 25 3d 22 48 65 6c 6c 6f 20 57 6f 72 |0 $P%="Hello Wor| 00002d60 6c 64 2c 20 74 68 69 73 20 69 73 20 6d 61 63 68 |ld, this is mach| 00002d70 69 6e 65 20 63 6f 64 65 21 22 0d 20 20 33 30 30 |ine code!". 300| 00002d80 20 43 41 4c 4c 20 63 6f 64 65 25 0d 0d 49 27 76 | CALL code%..I'v| 00002d90 65 20 70 75 74 20 61 20 73 74 72 69 6e 67 20 6a |e put a string j| 00002da0 75 73 74 20 61 66 74 65 72 20 74 68 65 20 6d 61 |ust after the ma| 00002db0 63 68 69 6e 65 20 63 6f 64 65 20 62 79 20 75 73 |chine code by us| 00002dc0 69 6e 67 20 74 68 65 20 24 0d 69 6e 64 69 72 65 |ing the $.indire| 00002dd0 63 74 69 6f 6e 20 6f 70 65 72 61 74 6f 72 2e 20 |ction operator. | 00002de0 20 54 68 69 73 20 70 75 74 73 20 74 68 65 20 73 | This puts the s| 00002df0 74 72 69 6e 67 20 69 6e 20 6d 65 6d 6f 72 79 20 |tring in memory | 00002e00 61 74 20 50 25 0d 66 6f 6c 6c 6f 77 65 64 20 62 |at P%.followed b| 00002e10 79 20 61 20 63 61 72 72 69 61 67 65 20 72 65 74 |y a carriage ret| 00002e20 75 72 6e 20 28 41 53 43 49 49 20 31 33 29 2e 20 |urn (ASCII 13). | 00002e30 20 54 68 65 72 65 20 61 72 65 20 6f 74 68 65 72 | There are other| 00002e40 0d 77 61 79 73 20 6f 66 20 64 6f 69 6e 67 20 74 |.ways of doing t| 00002e50 68 69 73 20 61 73 20 77 65 27 6c 6c 20 73 65 65 |his as we'll see| 00002e60 20 6c 61 74 65 72 2e 20 20 53 69 6e 63 65 20 74 | later. Since t| 00002e70 68 65 20 6c 61 62 65 6c 0d 27 74 65 78 74 27 20 |he label.'text' | 00002e80 77 61 73 20 61 74 20 74 68 65 20 65 6e 64 20 6f |was at the end o| 00002e90 66 20 74 68 65 20 61 73 73 65 6d 62 6c 65 72 20 |f the assembler | 00002ea0 70 61 72 74 20 6f 66 20 74 68 65 20 70 72 6f 67 |part of the prog| 00002eb0 72 61 6d 0d 69 74 20 77 69 6c 6c 20 68 61 76 65 |ram.it will have| 00002ec0 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 50 25 | the value of P%| 00002ed0 20 61 74 20 74 68 69 73 20 70 6f 69 6e 74 2e 0d | at this point..| 00002ee0 0d 46 69 6e 61 6c 6c 79 20 77 65 20 43 41 4c 4c |.Finally we CALL| 00002ef0 20 74 68 65 20 6d 61 63 68 69 6e 65 20 63 6f 64 | the machine cod| 00002f00 65 20 61 74 20 63 6f 64 65 25 20 61 6e 64 2c 20 |e at code% and, | 00002f10 6c 6f 2c 20 74 68 65 72 65 20 69 73 0d 74 68 65 |lo, there is.the| 00002f20 20 6d 65 73 73 61 67 65 20 70 72 69 6e 74 65 64 | message printed| 00002f30 20 6f 75 74 2e 20 20 49 67 6e 6f 72 69 6e 67 20 | out. Ignoring | 00002f40 74 68 65 20 63 6f 6d 6d 65 6e 74 73 20 6f 6e 20 |the comments on | 00002f50 65 61 63 68 20 6c 69 6e 65 0d 69 6e 20 74 68 65 |each line.in the| 00002f60 20 61 73 73 65 6d 62 6c 65 72 20 63 6f 64 65 20 | assembler code | 00002f70 69 6e 20 42 2f 6f 73 62 30 31 2c 20 69 74 20 73 |in B/osb01, it s| 00002f80 68 6f 75 6c 64 20 6c 6f 6f 6b 20 6c 69 6b 65 20 |hould look like | 00002f90 74 68 69 73 3a 0d 0d 20 20 3e 52 55 4e 0d 20 20 |this:.. >RUN. | 00002fa0 33 30 30 30 20 20 20 20 20 20 20 20 20 20 4f 50 |3000 OP| 00002fb0 54 20 70 61 73 73 25 0d 20 20 33 30 30 30 20 41 |T pass%. 3000 A| 00002fc0 32 20 30 30 20 20 20 20 4c 44 58 20 23 30 0d 20 |2 00 LDX #0. | 00002fd0 20 33 30 30 32 0d 20 20 33 30 30 32 20 20 20 20 | 3002. 3002 | 00002fe0 20 20 20 20 20 20 2e 6c 6f 6f 70 0d 20 20 33 30 | .loop. 30| 00002ff0 30 32 20 42 44 20 30 45 20 33 30 20 4c 44 41 20 |02 BD 0E 30 LDA | 00003000 74 65 78 74 2c 58 0d 20 20 33 30 30 35 20 32 30 |text,X. 3005 20| 00003010 20 45 33 20 46 46 20 4a 53 52 20 6f 73 61 73 63 | E3 FF JSR osasc| 00003020 69 0d 20 20 33 30 30 38 20 45 38 20 20 20 20 20 |i. 3008 E8 | 00003030 20 20 49 4e 58 0d 20 20 33 30 30 39 20 43 39 20 | INX. 3009 C9 | 00003040 30 44 20 20 20 20 43 4d 50 20 23 31 33 0d 20 20 |0D CMP #13. | 00003050 33 30 30 42 20 44 30 20 46 35 20 20 20 20 42 4e |300B D0 F5 BN| 00003060 45 20 6c 6f 6f 70 0d 20 20 33 30 30 44 0d 20 20 |E loop. 300D. | 00003070 33 30 30 44 20 36 30 20 20 20 20 20 20 20 52 54 |300D 60 RT| 00003080 53 0d 20 20 33 30 30 45 0d 20 20 33 30 30 45 20 |S. 300E. 300E | 00003090 20 20 20 20 20 20 20 20 20 2e 74 65 78 74 0d 20 | .text. | 000030a0 20 48 65 6c 6c 6f 20 57 6f 72 6c 64 2c 20 74 68 | Hello World, th| 000030b0 69 73 20 69 73 20 6d 61 63 68 69 6e 65 20 63 6f |is is machine co| 000030c0 64 65 21 0d 20 20 3e 0d 0d 54 68 6f 73 65 20 6e |de!. >..Those n| 000030d0 75 6d 62 65 72 73 20 64 6f 77 6e 20 74 68 65 20 |umbers down the | 000030e0 6c 65 66 74 2c 20 33 30 30 30 20 61 6e 64 20 73 |left, 3000 and s| 000030f0 6f 20 6f 6e 2c 20 61 72 65 20 74 68 65 20 70 72 |o on, are the pr| 00003100 6f 67 72 61 6d 0d 63 6f 75 6e 74 65 72 20 73 65 |ogram.counter se| 00003110 74 74 69 6e 67 73 20 61 73 20 74 68 65 20 61 73 |ttings as the as| 00003120 73 65 6d 62 6c 79 20 77 61 73 20 63 61 72 72 69 |sembly was carri| 00003130 65 64 20 6f 75 74 2e 20 20 54 68 65 0d 6e 75 6d |ed out. The.num| 00003140 62 65 72 73 20 62 65 74 77 65 65 6e 20 74 68 65 |bers between the| 00003150 20 70 72 6f 67 72 61 6d 20 63 6f 75 6e 74 65 72 | program counter| 00003160 20 76 61 6c 75 65 73 20 61 6e 64 20 74 68 65 20 | values and the | 00003170 6e 6d 65 6d 6f 6e 69 63 73 0d 61 6e 64 20 6c 61 |nmemonics.and la| 00003180 62 65 6c 73 20 61 72 65 20 74 68 65 20 61 63 74 |bels are the act| 00003190 75 61 6c 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 |ual machine code| 000031a0 20 6e 75 6d 62 65 72 73 20 70 6f 6b 65 64 20 69 | numbers poked i| 000031b0 6e 74 6f 0d 6d 65 6d 6f 72 79 2e 0d 0d 53 6f 20 |nto.memory...So | 000031c0 79 6f 75 20 73 65 65 2c 20 79 6f 75 20 63 61 6e |you see, you can| 000031d0 20 64 6f 20 69 74 20 69 6e 20 61 73 73 65 6d 62 | do it in assemb| 000031e0 6c 65 72 2e 20 20 49 20 68 6f 70 65 20 79 6f 75 |ler. I hope you| 000031f0 20 77 69 6c 6c 20 6e 6f 77 0d 6b 6e 6f 77 20 77 | will now.know w| 00003200 68 61 74 20 61 6e 20 61 73 73 65 6d 62 6c 65 72 |hat an assembler| 00003210 20 69 73 2c 20 68 6f 77 20 69 74 20 69 73 20 64 | is, how it is d| 00003220 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 42 41 |ifferent from BA| 00003230 53 49 43 2c 0d 61 6e 64 20 77 68 79 20 79 6f 75 |SIC,.and why you| 00003240 20 6d 69 67 68 74 20 77 61 6e 74 20 74 6f 20 75 | might want to u| 00003250 73 65 20 69 74 20 74 6f 20 77 72 69 74 65 20 6d |se it to write m| 00003260 61 63 68 69 6e 65 20 63 6f 64 65 0d 70 72 6f 67 |achine code.prog| 00003270 72 61 6d 73 2e 20 20 59 6f 75 20 73 68 6f 75 6c |rams. You shoul| 00003280 64 20 6b 6e 6f 77 20 68 6f 77 20 74 6f 20 73 65 |d know how to se| 00003290 74 20 75 70 20 74 68 65 20 42 42 43 20 61 73 73 |t up the BBC ass| 000032a0 65 6d 62 6c 65 72 0d 61 73 20 70 61 72 74 20 6f |embler.as part o| 000032b0 66 20 61 20 42 41 53 49 43 20 70 72 6f 67 72 61 |f a BASIC progra| 000032c0 6d 20 61 6e 64 20 77 69 6c 6c 20 68 61 76 65 20 |m and will have | 000032d0 61 73 73 65 6d 62 6c 65 64 20 61 20 73 68 6f 72 |assembled a shor| 000032e0 74 0d 70 69 65 63 65 20 6f 66 20 63 6f 64 65 20 |t.piece of code | 000032f0 77 68 69 63 68 20 70 72 69 6e 74 73 20 6f 75 74 |which prints out| 00003300 20 61 20 6d 65 73 73 61 67 65 2e 0d 0d 4e 65 78 | a message...Nex| 00003310 74 20 77 65 65 6b 20 49 27 6c 6c 20 65 78 70 6c |t week I'll expl| 00003320 61 69 6e 20 73 6f 6d 65 20 62 61 73 69 63 73 20 |ain some basics | 00003330 6f 66 20 62 69 6e 61 72 79 20 61 72 69 74 68 6d |of binary arithm| 00003340 65 74 69 63 20 61 6e 64 0d 77 65 27 6c 6c 20 74 |etic and.we'll t| 00003350 72 79 20 73 6f 6d 65 20 61 64 64 69 74 69 6f 6e |ry some addition| 00003360 20 61 6e 64 20 73 75 62 74 72 61 63 74 69 6f 6e | and subtraction| 00003370 2e 0d |..| 00003372