Home » CEEFAX disks » telesoftware3.adl » 06_11_87/T\OSB03

06_11_87/T\OSB03

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: 06_11_87/T\OSB03
Read OK:
File size: 2885 bytes
Load address: 0000
Exec address: 0000
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

............................................................


Part 3: The Registers and Flags


By now you should know how to set up the assembler in BBC
BASIC and have some ideas about using binary arithmetic. 
What we'll cover this week is basic information about how
the microprocessor works with bytes and what you can
therefore do with it.

Let's start by looking at the useful parts of the
microprocessor.  The stores you work with that are actually
part of the microprocessor are its 6 registers.

The registers you directly affect are the Accumulator and
the X and Y register.  All your calculating is done with the
accumulator while X and Y can be used to show an offset from
a base address (as in the program in the first module) or as
counters.  You can use them as temporary stores too.

Firstly, let's deal with the accumulator.

The name comes from the way it holds the current result of
your calculation, it is accumulating the result in the same
way an accumulator bet does.  The two simplest things you
can do with it are to load it and save it.

The assembler mnemonic for loading the accumulator is LDA. 
You can only hold a number between 0 and 255 in the
accumulator, and the assembler will generate a 'byte' error
if you try to load anything bigger.  A hash (#) is used to
tell the assembler that you want to load a number directly,
e.g. LDA #32 means 'load the number 32 into the
accumulator'.  Without the hash the accumulator would be
loaded from the memory location so that LDA 32 loads with
the byte stored in memory location 32 (&20).  It's very easy
to forget the hash when loading a number directly and you
will get strange results if you do.

If you have committed this file to paper it is possible that
your printer has printed a pound sign instead of a hash,
this is a common problem in the UK.  You should try to make
sure that in answer to ASCII code 35 you get a hash, it
looks like a sharp sign in music, as printed on the number 3
key on your micro keyboard.  This will save you much bother
in dealing with assembly listings.

To store the contents of the accumulator in an address you
use STA.  STA &123 will store the accumulator contents in
address &123.  For both loading and storing you can, and
most often will, use labels.  Here are some examples:

LDA #space         Load variable 'space'
LDA pigeon_hole    Load contents of address 'pigeon_hole'
STA hideaway       Store in address 'hideaway'

The X and Y registers operate like the accumulator using the
mnemonics LDX STX LDY STY.

You can use the X and Y registers to offset your loading and
saving either directly or indirectly.  For the time being
let's just deal with direct indexing, as it is called.

LDA pigeon_hole, X    Load contents of 'pigeon_hole' + X

STA pigeon_hole, Y    Save contents in 'pigeon_hole' + Y

In the first example work out ('pigeon_hole' + X) first,
this produces a new address X away from 'pigeon_hole', and
then load from there.  Similarly with the second example.

Both the X and Y registers can be used as indices with both
LDA and STA.  This gives you a way of working through a list
in memory, like a string to be printed out, or to move a
block of memory from one place to another if the block or
the list are no larger than 256 bytes.

Similarly to the accumulator X can be used as an index to
LDY and STY and Y as an index to LDX and STX.

You can increase or decrease the X and Y registers by one,
for counting, by using INX and INY to increase and DEX and DEY
to decrease.  There is no equivalent for the accumulator in
basic 6502 assembler although INC and DEC will work on the
contents of memory locations.

The accumulator and the X and Y registers can be affected
directly by the programmer.  Indirectly you can affect the
program counter, which holds the address of the next
instruction, and the status register.

The program counter is affected by any instruction that can
move execution to a different part of the program.  There
are branches and jumps that do this.  A branch can go back
or forwards by 127 and a jump can be to anywhere in the
address space.  Rather than think of these instructions as
changing the program counter we should concentrate on what
they mean in terms of programming.

The status register has seven flags.  Each flag is a bit of
the byte held in the register.  This is where decisions can
be made since the microprocessor can be instructed to branch
to a different part of the program depending on the status
of some of the flags.


Bit 0 is the carry flag which is set on a carry during
addition and cleared by a borrow on subtraction.  In some
ways you can think of it as a ninth bit of the byte you are
working on.

BCS means Branch if the Carry flag is Set, BCC means Branch
if the Carry flag is Clear.


Bit 1 is the zero flag which is set if the result of some
operation is zero, otherwise it is cleared.

BEQ means Branch if EQual to zero, i.e. if the zero flag is
set, BNE means Branch if Not Equal to zero, i.e. if the zero
flag is clear.


The next four bits do not enter into our branching and we'll
come back to them at a later stage.

Bit 2 is the interrupt flag, set when interrupts are
disabled.

Bit 3 is the decimal flag.  When set the processor
calculates in Binary Coded Decimal.

Bit 4 is the break flag and is set during a BRK interrupt.

Bit 5 is not used.


Bit 6 is the overflow flag which is set if there is a
discrepancy between the carry between bits 6 and 7 and out
of bit 7 during addition and subtraction.

BVS means Branch if oVerflow set and BVC means Branch if
oVerflow clear.


Bit 7 is the negative flag, set if the top bit of the last
operation is set, otherwise clear.

BMI means Branch on MInus, i.e. the negative flag is set,
and BPL means Branch on PLus, i.e. the negative flag is
clear.


Finally there is the stack pointer.  The stack is a special
section of memory used by the 6502 and this register holds
the lowest significant byte (LSB) of the next free stack
memory location.  The 6502 always keeps its stack in memory
between &100 and &1FF, called Page 1.  You can read and
write to the stack pointer and the stack but we'll leave
this to later.

We shall use branching instructions to carry out the
equivalent of IF THEN ELSE instructions.  But we also need
to have the equivalent of GOTO and GOSUB and these are JMP
and JSR.

JMP elsewhere - simply jumps to the instruction stored at
'elsewhere'.  In addition you can JMP (elsewhere) which
jumps to the instruction stored at the address stored at
'elsewhere' and 'elsewhere'+1.  This is an indirect jump of
which more another time.

JSR elsewhere - jumps to the instruction stored at
'elsewhere' but the address of the instruction after the JSR
is stored on the stack and when the program reaches the next
RTS instruction it returns to that address.  The piece of
program between 'elsewhere' and the RTS is a subroutine.

One important thing to remember about subroutines is that
they can change the values held in your registers and the
settings of your flags.  It's worth noting what changes, if
any, the subroutine makes before it returns.  In a later
module I will tell you how to preserve your registers and
flags.

A final set of instructions that will be needed for
branching are CMP, CPX and CPY.  The status register flags
are set automatically under some circumstances.  For example
the zero, negative, overflow and carry flags can all be
affected after an ADC.  Another way of setting these flags
is by using CMP to compare the accumulator with either a
value in memory or directly with a number.

e.g.       CMP somewhere       or        CMP #13

In both cases the value in the accumulator is not changed
but the flags are set and so branching instructions such as
BEQ or BMI can be used.  One particular branch to remember
after a CMP is that the carry flag is set if the value in A
is greater than or equal to the value in 'somewhere' (or 13)
in the example above.  This makes BCS equivalent to a branch
if greater than or equal.  (Do not use BMI or BPL for this.)

In the program B/osb03 in this telesoftware transmission is
a routine that detects whether a key pressed is upper or
lower case, a number, punctuation or a control code and
prints out a message accordingly.  It uses an operating
system routine to read in the key press, this is OSRDCH
which is the equivalent of BASIC's GET command.  The
branching is done mainly using the carry flag and the
messages are output using indexed addressing and the OSASCI
routine for printing to the screen.

Things to note:

BCS gives a branch on greater than or equal to, not just on
greater than.

This program operates like a series of sieves, each stage
lets through fewer and fewer values in A until those left
can only be punctuation.  In this case we start sieving from
the bottom, with control codes.

Note the double labelling of 'text' and 'control'.  It takes
up no room in the assembled code of course but I hope it
makes the source code a little clearer.

The very convoluted way of putting the strings into memory
is not necessary, I will show you a more elegant way in the
next file.

In this particular piece of code you can replace every
occurrence of JSR **** followed by RTS with just a JMP ****. 
Can you see why this works?  Modify the source code to do
this and you will find it a little shorter.  It will also be
a little faster but I doubt if you will notice that. Notice
what it leads you to do between lines 740 and 870 where you
have JMPs to the next line, which can then be removed
completely.

All in all this code is written to be readable as sections
but can be shortened to be more efficient.  It is worth
going through the RTSs to see just where they return to.

When the code is running you can break out of it with
ESCAPE, which also is a control code.  Every character
pressed on the black keys will lead to a printed descriptive
line.

I hope you now have some idea of how to use the assembler
for addition and subtraction (from last week) and for
branching and jumping.  In the next module we will discuss
better ways of reserving memory for variables (in BASIC 1 as
well as in later BASICs) and where to put machine code
programs.  The first thing to look at next week will be the
way the BBC Micro's memory is organised.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
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 50 61 72 74 20 33 3a  |.........Part 3:|
00000090  20 54 68 65 20 52 65 67  69 73 74 65 72 73 20 61  | The Registers a|
000000a0  6e 64 20 46 6c 61 67 73  0d 0d 0d 42 79 20 6e 6f  |nd Flags...By no|
000000b0  77 20 79 6f 75 20 73 68  6f 75 6c 64 20 6b 6e 6f  |w you should kno|
000000c0  77 20 68 6f 77 20 74 6f  20 73 65 74 20 75 70 20  |w how to set up |
000000d0  74 68 65 20 61 73 73 65  6d 62 6c 65 72 20 69 6e  |the assembler in|
000000e0  20 42 42 43 0d 42 41 53  49 43 20 61 6e 64 20 68  | BBC.BASIC and h|
000000f0  61 76 65 20 73 6f 6d 65  20 69 64 65 61 73 20 61  |ave some ideas a|
00000100  62 6f 75 74 20 75 73 69  6e 67 20 62 69 6e 61 72  |bout using binar|
00000110  79 20 61 72 69 74 68 6d  65 74 69 63 2e 20 0d 57  |y arithmetic. .W|
00000120  68 61 74 20 77 65 27 6c  6c 20 63 6f 76 65 72 20  |hat we'll cover |
00000130  74 68 69 73 20 77 65 65  6b 20 69 73 20 62 61 73  |this week is bas|
00000140  69 63 20 69 6e 66 6f 72  6d 61 74 69 6f 6e 20 61  |ic information a|
00000150  62 6f 75 74 20 68 6f 77  0d 74 68 65 20 6d 69 63  |bout how.the mic|
00000160  72 6f 70 72 6f 63 65 73  73 6f 72 20 77 6f 72 6b  |roprocessor work|
00000170  73 20 77 69 74 68 20 62  79 74 65 73 20 61 6e 64  |s with bytes and|
00000180  20 77 68 61 74 20 79 6f  75 20 63 61 6e 0d 74 68  | what you can.th|
00000190  65 72 65 66 6f 72 65 20  64 6f 20 77 69 74 68 20  |erefore do with |
000001a0  69 74 2e 0d 0d 4c 65 74  27 73 20 73 74 61 72 74  |it...Let's start|
000001b0  20 62 79 20 6c 6f 6f 6b  69 6e 67 20 61 74 20 74  | by looking at t|
000001c0  68 65 20 75 73 65 66 75  6c 20 70 61 72 74 73 20  |he useful parts |
000001d0  6f 66 20 74 68 65 0d 6d  69 63 72 6f 70 72 6f 63  |of the.microproc|
000001e0  65 73 73 6f 72 2e 20 20  54 68 65 20 73 74 6f 72  |essor.  The stor|
000001f0  65 73 20 79 6f 75 20 77  6f 72 6b 20 77 69 74 68  |es you work with|
00000200  20 74 68 61 74 20 61 72  65 20 61 63 74 75 61 6c  | that are actual|
00000210  6c 79 0d 70 61 72 74 20  6f 66 20 74 68 65 20 6d  |ly.part of the m|
00000220  69 63 72 6f 70 72 6f 63  65 73 73 6f 72 20 61 72  |icroprocessor ar|
00000230  65 20 69 74 73 20 36 20  72 65 67 69 73 74 65 72  |e its 6 register|
00000240  73 2e 0d 0d 54 68 65 20  72 65 67 69 73 74 65 72  |s...The register|
00000250  73 20 79 6f 75 20 64 69  72 65 63 74 6c 79 20 61  |s you directly a|
00000260  66 66 65 63 74 20 61 72  65 20 74 68 65 20 41 63  |ffect are the Ac|
00000270  63 75 6d 75 6c 61 74 6f  72 20 61 6e 64 0d 74 68  |cumulator and.th|
00000280  65 20 58 20 61 6e 64 20  59 20 72 65 67 69 73 74  |e X and Y regist|
00000290  65 72 2e 20 20 41 6c 6c  20 79 6f 75 72 20 63 61  |er.  All your ca|
000002a0  6c 63 75 6c 61 74 69 6e  67 20 69 73 20 64 6f 6e  |lculating is don|
000002b0  65 20 77 69 74 68 20 74  68 65 0d 61 63 63 75 6d  |e with the.accum|
000002c0  75 6c 61 74 6f 72 20 77  68 69 6c 65 20 58 20 61  |ulator while X a|
000002d0  6e 64 20 59 20 63 61 6e  20 62 65 20 75 73 65 64  |nd Y can be used|
000002e0  20 74 6f 20 73 68 6f 77  20 61 6e 20 6f 66 66 73  | to show an offs|
000002f0  65 74 20 66 72 6f 6d 0d  61 20 62 61 73 65 20 61  |et from.a base a|
00000300  64 64 72 65 73 73 20 28  61 73 20 69 6e 20 74 68  |ddress (as in th|
00000310  65 20 70 72 6f 67 72 61  6d 20 69 6e 20 74 68 65  |e program in the|
00000320  20 66 69 72 73 74 20 6d  6f 64 75 6c 65 29 20 6f  | first module) o|
00000330  72 20 61 73 0d 63 6f 75  6e 74 65 72 73 2e 20 20  |r as.counters.  |
00000340  59 6f 75 20 63 61 6e 20  75 73 65 20 74 68 65 6d  |You can use them|
00000350  20 61 73 20 74 65 6d 70  6f 72 61 72 79 20 73 74  | as temporary st|
00000360  6f 72 65 73 20 74 6f 6f  2e 0d 0d 46 69 72 73 74  |ores too...First|
00000370  6c 79 2c 20 6c 65 74 27  73 20 64 65 61 6c 20 77  |ly, let's deal w|
00000380  69 74 68 20 74 68 65 20  61 63 63 75 6d 75 6c 61  |ith the accumula|
00000390  74 6f 72 2e 0d 0d 54 68  65 20 6e 61 6d 65 20 63  |tor...The name c|
000003a0  6f 6d 65 73 20 66 72 6f  6d 20 74 68 65 20 77 61  |omes from the wa|
000003b0  79 20 69 74 20 68 6f 6c  64 73 20 74 68 65 20 63  |y it holds the c|
000003c0  75 72 72 65 6e 74 20 72  65 73 75 6c 74 20 6f 66  |urrent result of|
000003d0  0d 79 6f 75 72 20 63 61  6c 63 75 6c 61 74 69 6f  |.your calculatio|
000003e0  6e 2c 20 69 74 20 69 73  20 61 63 63 75 6d 75 6c  |n, it is accumul|
000003f0  61 74 69 6e 67 20 74 68  65 20 72 65 73 75 6c 74  |ating the result|
00000400  20 69 6e 20 74 68 65 20  73 61 6d 65 0d 77 61 79  | in the same.way|
00000410  20 61 6e 20 61 63 63 75  6d 75 6c 61 74 6f 72 20  | an accumulator |
00000420  62 65 74 20 64 6f 65 73  2e 20 20 54 68 65 20 74  |bet does.  The t|
00000430  77 6f 20 73 69 6d 70 6c  65 73 74 20 74 68 69 6e  |wo simplest thin|
00000440  67 73 20 79 6f 75 0d 63  61 6e 20 64 6f 20 77 69  |gs you.can do wi|
00000450  74 68 20 69 74 20 61 72  65 20 74 6f 20 6c 6f 61  |th it are to loa|
00000460  64 20 69 74 20 61 6e 64  20 73 61 76 65 20 69 74  |d it and save it|
00000470  2e 0d 0d 54 68 65 20 61  73 73 65 6d 62 6c 65 72  |...The assembler|
00000480  20 6d 6e 65 6d 6f 6e 69  63 20 66 6f 72 20 6c 6f  | mnemonic for lo|
00000490  61 64 69 6e 67 20 74 68  65 20 61 63 63 75 6d 75  |ading the accumu|
000004a0  6c 61 74 6f 72 20 69 73  20 4c 44 41 2e 20 0d 59  |lator is LDA. .Y|
000004b0  6f 75 20 63 61 6e 20 6f  6e 6c 79 20 68 6f 6c 64  |ou can only hold|
000004c0  20 61 20 6e 75 6d 62 65  72 20 62 65 74 77 65 65  | a number betwee|
000004d0  6e 20 30 20 61 6e 64 20  32 35 35 20 69 6e 20 74  |n 0 and 255 in t|
000004e0  68 65 0d 61 63 63 75 6d  75 6c 61 74 6f 72 2c 20  |he.accumulator, |
000004f0  61 6e 64 20 74 68 65 20  61 73 73 65 6d 62 6c 65  |and the assemble|
00000500  72 20 77 69 6c 6c 20 67  65 6e 65 72 61 74 65 20  |r will generate |
00000510  61 20 27 62 79 74 65 27  20 65 72 72 6f 72 0d 69  |a 'byte' error.i|
00000520  66 20 79 6f 75 20 74 72  79 20 74 6f 20 6c 6f 61  |f you try to loa|
00000530  64 20 61 6e 79 74 68 69  6e 67 20 62 69 67 67 65  |d anything bigge|
00000540  72 2e 20 20 41 20 68 61  73 68 20 28 23 29 20 69  |r.  A hash (#) i|
00000550  73 20 75 73 65 64 20 74  6f 0d 74 65 6c 6c 20 74  |s used to.tell t|
00000560  68 65 20 61 73 73 65 6d  62 6c 65 72 20 74 68 61  |he assembler tha|
00000570  74 20 79 6f 75 20 77 61  6e 74 20 74 6f 20 6c 6f  |t you want to lo|
00000580  61 64 20 61 20 6e 75 6d  62 65 72 20 64 69 72 65  |ad a number dire|
00000590  63 74 6c 79 2c 0d 65 2e  67 2e 20 4c 44 41 20 23  |ctly,.e.g. LDA #|
000005a0  33 32 20 6d 65 61 6e 73  20 27 6c 6f 61 64 20 74  |32 means 'load t|
000005b0  68 65 20 6e 75 6d 62 65  72 20 33 32 20 69 6e 74  |he number 32 int|
000005c0  6f 20 74 68 65 0d 61 63  63 75 6d 75 6c 61 74 6f  |o the.accumulato|
000005d0  72 27 2e 20 20 57 69 74  68 6f 75 74 20 74 68 65  |r'.  Without the|
000005e0  20 68 61 73 68 20 74 68  65 20 61 63 63 75 6d 75  | hash the accumu|
000005f0  6c 61 74 6f 72 20 77 6f  75 6c 64 20 62 65 0d 6c  |lator would be.l|
00000600  6f 61 64 65 64 20 66 72  6f 6d 20 74 68 65 20 6d  |oaded from the m|
00000610  65 6d 6f 72 79 20 6c 6f  63 61 74 69 6f 6e 20 73  |emory location s|
00000620  6f 20 74 68 61 74 20 4c  44 41 20 33 32 20 6c 6f  |o that LDA 32 lo|
00000630  61 64 73 20 77 69 74 68  0d 74 68 65 20 62 79 74  |ads with.the byt|
00000640  65 20 73 74 6f 72 65 64  20 69 6e 20 6d 65 6d 6f  |e stored in memo|
00000650  72 79 20 6c 6f 63 61 74  69 6f 6e 20 33 32 20 28  |ry location 32 (|
00000660  26 32 30 29 2e 20 20 49  74 27 73 20 76 65 72 79  |&20).  It's very|
00000670  20 65 61 73 79 0d 74 6f  20 66 6f 72 67 65 74 20  | easy.to forget |
00000680  74 68 65 20 68 61 73 68  20 77 68 65 6e 20 6c 6f  |the hash when lo|
00000690  61 64 69 6e 67 20 61 20  6e 75 6d 62 65 72 20 64  |ading a number d|
000006a0  69 72 65 63 74 6c 79 20  61 6e 64 20 79 6f 75 0d  |irectly and you.|
000006b0  77 69 6c 6c 20 67 65 74  20 73 74 72 61 6e 67 65  |will get strange|
000006c0  20 72 65 73 75 6c 74 73  20 69 66 20 79 6f 75 20  | results if you |
000006d0  64 6f 2e 0d 0d 49 66 20  79 6f 75 20 68 61 76 65  |do...If you have|
000006e0  20 63 6f 6d 6d 69 74 74  65 64 20 74 68 69 73 20  | committed this |
000006f0  66 69 6c 65 20 74 6f 20  70 61 70 65 72 20 69 74  |file to paper it|
00000700  20 69 73 20 70 6f 73 73  69 62 6c 65 20 74 68 61  | is possible tha|
00000710  74 0d 79 6f 75 72 20 70  72 69 6e 74 65 72 20 68  |t.your printer h|
00000720  61 73 20 70 72 69 6e 74  65 64 20 61 20 70 6f 75  |as printed a pou|
00000730  6e 64 20 73 69 67 6e 20  69 6e 73 74 65 61 64 20  |nd sign instead |
00000740  6f 66 20 61 20 68 61 73  68 2c 0d 74 68 69 73 20  |of a hash,.this |
00000750  69 73 20 61 20 63 6f 6d  6d 6f 6e 20 70 72 6f 62  |is a common prob|
00000760  6c 65 6d 20 69 6e 20 74  68 65 20 55 4b 2e 20 20  |lem in the UK.  |
00000770  59 6f 75 20 73 68 6f 75  6c 64 20 74 72 79 20 74  |You should try t|
00000780  6f 20 6d 61 6b 65 0d 73  75 72 65 20 74 68 61 74  |o make.sure that|
00000790  20 69 6e 20 61 6e 73 77  65 72 20 74 6f 20 41 53  | in answer to AS|
000007a0  43 49 49 20 63 6f 64 65  20 33 35 20 79 6f 75 20  |CII code 35 you |
000007b0  67 65 74 20 61 20 68 61  73 68 2c 20 69 74 0d 6c  |get a hash, it.l|
000007c0  6f 6f 6b 73 20 6c 69 6b  65 20 61 20 73 68 61 72  |ooks like a shar|
000007d0  70 20 73 69 67 6e 20 69  6e 20 6d 75 73 69 63 2c  |p sign in music,|
000007e0  20 61 73 20 70 72 69 6e  74 65 64 20 6f 6e 20 74  | as printed on t|
000007f0  68 65 20 6e 75 6d 62 65  72 20 33 0d 6b 65 79 20  |he number 3.key |
00000800  6f 6e 20 79 6f 75 72 20  6d 69 63 72 6f 20 6b 65  |on your micro ke|
00000810  79 62 6f 61 72 64 2e 20  20 54 68 69 73 20 77 69  |yboard.  This wi|
00000820  6c 6c 20 73 61 76 65 20  79 6f 75 20 6d 75 63 68  |ll save you much|
00000830  20 62 6f 74 68 65 72 0d  69 6e 20 64 65 61 6c 69  | bother.in deali|
00000840  6e 67 20 77 69 74 68 20  61 73 73 65 6d 62 6c 79  |ng with assembly|
00000850  20 6c 69 73 74 69 6e 67  73 2e 0d 0d 54 6f 20 73  | listings...To s|
00000860  74 6f 72 65 20 74 68 65  20 63 6f 6e 74 65 6e 74  |tore the content|
00000870  73 20 6f 66 20 74 68 65  20 61 63 63 75 6d 75 6c  |s of the accumul|
00000880  61 74 6f 72 20 69 6e 20  61 6e 20 61 64 64 72 65  |ator in an addre|
00000890  73 73 20 79 6f 75 0d 75  73 65 20 53 54 41 2e 20  |ss you.use STA. |
000008a0  20 53 54 41 20 26 31 32  33 20 77 69 6c 6c 20 73  | STA &123 will s|
000008b0  74 6f 72 65 20 74 68 65  20 61 63 63 75 6d 75 6c  |tore the accumul|
000008c0  61 74 6f 72 20 63 6f 6e  74 65 6e 74 73 20 69 6e  |ator contents in|
000008d0  0d 61 64 64 72 65 73 73  20 26 31 32 33 2e 20 20  |.address &123.  |
000008e0  46 6f 72 20 62 6f 74 68  20 6c 6f 61 64 69 6e 67  |For both loading|
000008f0  20 61 6e 64 20 73 74 6f  72 69 6e 67 20 79 6f 75  | and storing you|
00000900  20 63 61 6e 2c 20 61 6e  64 0d 6d 6f 73 74 20 6f  | can, and.most o|
00000910  66 74 65 6e 20 77 69 6c  6c 2c 20 75 73 65 20 6c  |ften will, use l|
00000920  61 62 65 6c 73 2e 20 20  48 65 72 65 20 61 72 65  |abels.  Here are|
00000930  20 73 6f 6d 65 20 65 78  61 6d 70 6c 65 73 3a 0d  | some examples:.|
00000940  0d 4c 44 41 20 23 73 70  61 63 65 20 20 20 20 20  |.LDA #space     |
00000950  20 20 20 20 4c 6f 61 64  20 76 61 72 69 61 62 6c  |    Load variabl|
00000960  65 20 27 73 70 61 63 65  27 0d 4c 44 41 20 70 69  |e 'space'.LDA pi|
00000970  67 65 6f 6e 5f 68 6f 6c  65 20 20 20 20 4c 6f 61  |geon_hole    Loa|
00000980  64 20 63 6f 6e 74 65 6e  74 73 20 6f 66 20 61 64  |d contents of ad|
00000990  64 72 65 73 73 20 27 70  69 67 65 6f 6e 5f 68 6f  |dress 'pigeon_ho|
000009a0  6c 65 27 0d 53 54 41 20  68 69 64 65 61 77 61 79  |le'.STA hideaway|
000009b0  20 20 20 20 20 20 20 53  74 6f 72 65 20 69 6e 20  |       Store in |
000009c0  61 64 64 72 65 73 73 20  27 68 69 64 65 61 77 61  |address 'hideawa|
000009d0  79 27 0d 0d 54 68 65 20  58 20 61 6e 64 20 59 20  |y'..The X and Y |
000009e0  72 65 67 69 73 74 65 72  73 20 6f 70 65 72 61 74  |registers operat|
000009f0  65 20 6c 69 6b 65 20 74  68 65 20 61 63 63 75 6d  |e like the accum|
00000a00  75 6c 61 74 6f 72 20 75  73 69 6e 67 20 74 68 65  |ulator using the|
00000a10  0d 6d 6e 65 6d 6f 6e 69  63 73 20 4c 44 58 20 53  |.mnemonics LDX S|
00000a20  54 58 20 4c 44 59 20 53  54 59 2e 0d 0d 59 6f 75  |TX LDY STY...You|
00000a30  20 63 61 6e 20 75 73 65  20 74 68 65 20 58 20 61  | can use the X a|
00000a40  6e 64 20 59 20 72 65 67  69 73 74 65 72 73 20 74  |nd Y registers t|
00000a50  6f 20 6f 66 66 73 65 74  20 79 6f 75 72 20 6c 6f  |o offset your lo|
00000a60  61 64 69 6e 67 20 61 6e  64 0d 73 61 76 69 6e 67  |ading and.saving|
00000a70  20 65 69 74 68 65 72 20  64 69 72 65 63 74 6c 79  | either directly|
00000a80  20 6f 72 20 69 6e 64 69  72 65 63 74 6c 79 2e 20  | or indirectly. |
00000a90  20 46 6f 72 20 74 68 65  20 74 69 6d 65 20 62 65  | For the time be|
00000aa0  69 6e 67 0d 6c 65 74 27  73 20 6a 75 73 74 20 64  |ing.let's just d|
00000ab0  65 61 6c 20 77 69 74 68  20 64 69 72 65 63 74 20  |eal with direct |
00000ac0  69 6e 64 65 78 69 6e 67  2c 20 61 73 20 69 74 20  |indexing, as it |
00000ad0  69 73 20 63 61 6c 6c 65  64 2e 0d 0d 4c 44 41 20  |is called...LDA |
00000ae0  70 69 67 65 6f 6e 5f 68  6f 6c 65 2c 20 58 20 20  |pigeon_hole, X  |
00000af0  20 20 4c 6f 61 64 20 63  6f 6e 74 65 6e 74 73 20  |  Load contents |
00000b00  6f 66 20 27 70 69 67 65  6f 6e 5f 68 6f 6c 65 27  |of 'pigeon_hole'|
00000b10  20 2b 20 58 0d 0d 53 54  41 20 70 69 67 65 6f 6e  | + X..STA pigeon|
00000b20  5f 68 6f 6c 65 2c 20 59  20 20 20 20 53 61 76 65  |_hole, Y    Save|
00000b30  20 63 6f 6e 74 65 6e 74  73 20 69 6e 20 27 70 69  | contents in 'pi|
00000b40  67 65 6f 6e 5f 68 6f 6c  65 27 20 2b 20 59 0d 0d  |geon_hole' + Y..|
00000b50  49 6e 20 74 68 65 20 66  69 72 73 74 20 65 78 61  |In the first exa|
00000b60  6d 70 6c 65 20 77 6f 72  6b 20 6f 75 74 20 28 27  |mple work out ('|
00000b70  70 69 67 65 6f 6e 5f 68  6f 6c 65 27 20 2b 20 58  |pigeon_hole' + X|
00000b80  29 20 66 69 72 73 74 2c  0d 74 68 69 73 20 70 72  |) first,.this pr|
00000b90  6f 64 75 63 65 73 20 61  20 6e 65 77 20 61 64 64  |oduces a new add|
00000ba0  72 65 73 73 20 58 20 61  77 61 79 20 66 72 6f 6d  |ress X away from|
00000bb0  20 27 70 69 67 65 6f 6e  5f 68 6f 6c 65 27 2c 20  | 'pigeon_hole', |
00000bc0  61 6e 64 0d 74 68 65 6e  20 6c 6f 61 64 20 66 72  |and.then load fr|
00000bd0  6f 6d 20 74 68 65 72 65  2e 20 20 53 69 6d 69 6c  |om there.  Simil|
00000be0  61 72 6c 79 20 77 69 74  68 20 74 68 65 20 73 65  |arly with the se|
00000bf0  63 6f 6e 64 20 65 78 61  6d 70 6c 65 2e 0d 0d 42  |cond example...B|
00000c00  6f 74 68 20 74 68 65 20  58 20 61 6e 64 20 59 20  |oth the X and Y |
00000c10  72 65 67 69 73 74 65 72  73 20 63 61 6e 20 62 65  |registers can be|
00000c20  20 75 73 65 64 20 61 73  20 69 6e 64 69 63 65 73  | used as indices|
00000c30  20 77 69 74 68 20 62 6f  74 68 0d 4c 44 41 20 61  | with both.LDA a|
00000c40  6e 64 20 53 54 41 2e 20  20 54 68 69 73 20 67 69  |nd STA.  This gi|
00000c50  76 65 73 20 79 6f 75 20  61 20 77 61 79 20 6f 66  |ves you a way of|
00000c60  20 77 6f 72 6b 69 6e 67  20 74 68 72 6f 75 67 68  | working through|
00000c70  20 61 20 6c 69 73 74 0d  69 6e 20 6d 65 6d 6f 72  | a list.in memor|
00000c80  79 2c 20 6c 69 6b 65 20  61 20 73 74 72 69 6e 67  |y, like a string|
00000c90  20 74 6f 20 62 65 20 70  72 69 6e 74 65 64 20 6f  | to be printed o|
00000ca0  75 74 2c 20 6f 72 20 74  6f 20 6d 6f 76 65 20 61  |ut, or to move a|
00000cb0  0d 62 6c 6f 63 6b 20 6f  66 20 6d 65 6d 6f 72 79  |.block of memory|
00000cc0  20 66 72 6f 6d 20 6f 6e  65 20 70 6c 61 63 65 20  | from one place |
00000cd0  74 6f 20 61 6e 6f 74 68  65 72 20 69 66 20 74 68  |to another if th|
00000ce0  65 20 62 6c 6f 63 6b 20  6f 72 0d 74 68 65 20 6c  |e block or.the l|
00000cf0  69 73 74 20 61 72 65 20  6e 6f 20 6c 61 72 67 65  |ist are no large|
00000d00  72 20 74 68 61 6e 20 32  35 36 20 62 79 74 65 73  |r than 256 bytes|
00000d10  2e 0d 0d 53 69 6d 69 6c  61 72 6c 79 20 74 6f 20  |...Similarly to |
00000d20  74 68 65 20 61 63 63 75  6d 75 6c 61 74 6f 72 20  |the accumulator |
00000d30  58 20 63 61 6e 20 62 65  20 75 73 65 64 20 61 73  |X can be used as|
00000d40  20 61 6e 20 69 6e 64 65  78 20 74 6f 0d 4c 44 59  | an index to.LDY|
00000d50  20 61 6e 64 20 53 54 59  20 61 6e 64 20 59 20 61  | and STY and Y a|
00000d60  73 20 61 6e 20 69 6e 64  65 78 20 74 6f 20 4c 44  |s an index to LD|
00000d70  58 20 61 6e 64 20 53 54  58 2e 0d 0d 59 6f 75 20  |X and STX...You |
00000d80  63 61 6e 20 69 6e 63 72  65 61 73 65 20 6f 72 20  |can increase or |
00000d90  64 65 63 72 65 61 73 65  20 74 68 65 20 58 20 61  |decrease the X a|
00000da0  6e 64 20 59 20 72 65 67  69 73 74 65 72 73 20 62  |nd Y registers b|
00000db0  79 20 6f 6e 65 2c 0d 66  6f 72 20 63 6f 75 6e 74  |y one,.for count|
00000dc0  69 6e 67 2c 20 62 79 20  75 73 69 6e 67 20 49 4e  |ing, by using IN|
00000dd0  58 20 61 6e 64 20 49 4e  59 20 74 6f 20 69 6e 63  |X and INY to inc|
00000de0  72 65 61 73 65 20 61 6e  64 20 44 45 58 20 61 6e  |rease and DEX an|
00000df0  64 20 44 45 59 0d 74 6f  20 64 65 63 72 65 61 73  |d DEY.to decreas|
00000e00  65 2e 20 20 54 68 65 72  65 20 69 73 20 6e 6f 20  |e.  There is no |
00000e10  65 71 75 69 76 61 6c 65  6e 74 20 66 6f 72 20 74  |equivalent for t|
00000e20  68 65 20 61 63 63 75 6d  75 6c 61 74 6f 72 20 69  |he accumulator i|
00000e30  6e 0d 62 61 73 69 63 20  36 35 30 32 20 61 73 73  |n.basic 6502 ass|
00000e40  65 6d 62 6c 65 72 20 61  6c 74 68 6f 75 67 68 20  |embler although |
00000e50  49 4e 43 20 61 6e 64 20  44 45 43 20 77 69 6c 6c  |INC and DEC will|
00000e60  20 77 6f 72 6b 20 6f 6e  20 74 68 65 0d 63 6f 6e  | work on the.con|
00000e70  74 65 6e 74 73 20 6f 66  20 6d 65 6d 6f 72 79 20  |tents of memory |
00000e80  6c 6f 63 61 74 69 6f 6e  73 2e 0d 0d 54 68 65 20  |locations...The |
00000e90  61 63 63 75 6d 75 6c 61  74 6f 72 20 61 6e 64 20  |accumulator and |
00000ea0  74 68 65 20 58 20 61 6e  64 20 59 20 72 65 67 69  |the X and Y regi|
00000eb0  73 74 65 72 73 20 63 61  6e 20 62 65 20 61 66 66  |sters can be aff|
00000ec0  65 63 74 65 64 0d 64 69  72 65 63 74 6c 79 20 62  |ected.directly b|
00000ed0  79 20 74 68 65 20 70 72  6f 67 72 61 6d 6d 65 72  |y the programmer|
00000ee0  2e 20 20 49 6e 64 69 72  65 63 74 6c 79 20 79 6f  |.  Indirectly yo|
00000ef0  75 20 63 61 6e 20 61 66  66 65 63 74 20 74 68 65  |u can affect the|
00000f00  0d 70 72 6f 67 72 61 6d  20 63 6f 75 6e 74 65 72  |.program counter|
00000f10  2c 20 77 68 69 63 68 20  68 6f 6c 64 73 20 74 68  |, which holds th|
00000f20  65 20 61 64 64 72 65 73  73 20 6f 66 20 74 68 65  |e address of the|
00000f30  20 6e 65 78 74 0d 69 6e  73 74 72 75 63 74 69 6f  | next.instructio|
00000f40  6e 2c 20 61 6e 64 20 74  68 65 20 73 74 61 74 75  |n, and the statu|
00000f50  73 20 72 65 67 69 73 74  65 72 2e 0d 0d 54 68 65  |s register...The|
00000f60  20 70 72 6f 67 72 61 6d  20 63 6f 75 6e 74 65 72  | program counter|
00000f70  20 69 73 20 61 66 66 65  63 74 65 64 20 62 79 20  | is affected by |
00000f80  61 6e 79 20 69 6e 73 74  72 75 63 74 69 6f 6e 20  |any instruction |
00000f90  74 68 61 74 20 63 61 6e  0d 6d 6f 76 65 20 65 78  |that can.move ex|
00000fa0  65 63 75 74 69 6f 6e 20  74 6f 20 61 20 64 69 66  |ecution to a dif|
00000fb0  66 65 72 65 6e 74 20 70  61 72 74 20 6f 66 20 74  |ferent part of t|
00000fc0  68 65 20 70 72 6f 67 72  61 6d 2e 20 20 54 68 65  |he program.  The|
00000fd0  72 65 0d 61 72 65 20 62  72 61 6e 63 68 65 73 20  |re.are branches |
00000fe0  61 6e 64 20 6a 75 6d 70  73 20 74 68 61 74 20 64  |and jumps that d|
00000ff0  6f 20 74 68 69 73 2e 20  20 41 20 62 72 61 6e 63  |o this.  A branc|
00001000  68 20 63 61 6e 20 67 6f  20 62 61 63 6b 0d 6f 72  |h can go back.or|
00001010  20 66 6f 72 77 61 72 64  73 20 62 79 20 31 32 37  | forwards by 127|
00001020  20 61 6e 64 20 61 20 6a  75 6d 70 20 63 61 6e 20  | and a jump can |
00001030  62 65 20 74 6f 20 61 6e  79 77 68 65 72 65 20 69  |be to anywhere i|
00001040  6e 20 74 68 65 0d 61 64  64 72 65 73 73 20 73 70  |n the.address sp|
00001050  61 63 65 2e 20 20 52 61  74 68 65 72 20 74 68 61  |ace.  Rather tha|
00001060  6e 20 74 68 69 6e 6b 20  6f 66 20 74 68 65 73 65  |n think of these|
00001070  20 69 6e 73 74 72 75 63  74 69 6f 6e 73 20 61 73  | instructions as|
00001080  0d 63 68 61 6e 67 69 6e  67 20 74 68 65 20 70 72  |.changing the pr|
00001090  6f 67 72 61 6d 20 63 6f  75 6e 74 65 72 20 77 65  |ogram counter we|
000010a0  20 73 68 6f 75 6c 64 20  63 6f 6e 63 65 6e 74 72  | should concentr|
000010b0  61 74 65 20 6f 6e 20 77  68 61 74 0d 74 68 65 79  |ate on what.they|
000010c0  20 6d 65 61 6e 20 69 6e  20 74 65 72 6d 73 20 6f  | mean in terms o|
000010d0  66 20 70 72 6f 67 72 61  6d 6d 69 6e 67 2e 0d 0d  |f programming...|
000010e0  54 68 65 20 73 74 61 74  75 73 20 72 65 67 69 73  |The status regis|
000010f0  74 65 72 20 68 61 73 20  73 65 76 65 6e 20 66 6c  |ter has seven fl|
00001100  61 67 73 2e 20 20 45 61  63 68 20 66 6c 61 67 20  |ags.  Each flag |
00001110  69 73 20 61 20 62 69 74  20 6f 66 0d 74 68 65 20  |is a bit of.the |
00001120  62 79 74 65 20 68 65 6c  64 20 69 6e 20 74 68 65  |byte held in the|
00001130  20 72 65 67 69 73 74 65  72 2e 20 20 54 68 69 73  | register.  This|
00001140  20 69 73 20 77 68 65 72  65 20 64 65 63 69 73 69  | is where decisi|
00001150  6f 6e 73 20 63 61 6e 0d  62 65 20 6d 61 64 65 20  |ons can.be made |
00001160  73 69 6e 63 65 20 74 68  65 20 6d 69 63 72 6f 70  |since the microp|
00001170  72 6f 63 65 73 73 6f 72  20 63 61 6e 20 62 65 20  |rocessor can be |
00001180  69 6e 73 74 72 75 63 74  65 64 20 74 6f 20 62 72  |instructed to br|
00001190  61 6e 63 68 0d 74 6f 20  61 20 64 69 66 66 65 72  |anch.to a differ|
000011a0  65 6e 74 20 70 61 72 74  20 6f 66 20 74 68 65 20  |ent part of the |
000011b0  70 72 6f 67 72 61 6d 20  64 65 70 65 6e 64 69 6e  |program dependin|
000011c0  67 20 6f 6e 20 74 68 65  20 73 74 61 74 75 73 0d  |g on the status.|
000011d0  6f 66 20 73 6f 6d 65 20  6f 66 20 74 68 65 20 66  |of some of the f|
000011e0  6c 61 67 73 2e 0d 0d 0d  42 69 74 20 30 20 69 73  |lags....Bit 0 is|
000011f0  20 74 68 65 20 63 61 72  72 79 20 66 6c 61 67 20  | the carry flag |
00001200  77 68 69 63 68 20 69 73  20 73 65 74 20 6f 6e 20  |which is set on |
00001210  61 20 63 61 72 72 79 20  64 75 72 69 6e 67 0d 61  |a carry during.a|
00001220  64 64 69 74 69 6f 6e 20  61 6e 64 20 63 6c 65 61  |ddition and clea|
00001230  72 65 64 20 62 79 20 61  20 62 6f 72 72 6f 77 20  |red by a borrow |
00001240  6f 6e 20 73 75 62 74 72  61 63 74 69 6f 6e 2e 20  |on subtraction. |
00001250  20 49 6e 20 73 6f 6d 65  0d 77 61 79 73 20 79 6f  | In some.ways yo|
00001260  75 20 63 61 6e 20 74 68  69 6e 6b 20 6f 66 20 69  |u can think of i|
00001270  74 20 61 73 20 61 20 6e  69 6e 74 68 20 62 69 74  |t as a ninth bit|
00001280  20 6f 66 20 74 68 65 20  62 79 74 65 20 79 6f 75  | of the byte you|
00001290  20 61 72 65 0d 77 6f 72  6b 69 6e 67 20 6f 6e 2e  | are.working on.|
000012a0  0d 0d 42 43 53 20 6d 65  61 6e 73 20 42 72 61 6e  |..BCS means Bran|
000012b0  63 68 20 69 66 20 74 68  65 20 43 61 72 72 79 20  |ch if the Carry |
000012c0  66 6c 61 67 20 69 73 20  53 65 74 2c 20 42 43 43  |flag is Set, BCC|
000012d0  20 6d 65 61 6e 73 20 42  72 61 6e 63 68 0d 69 66  | means Branch.if|
000012e0  20 74 68 65 20 43 61 72  72 79 20 66 6c 61 67 20  | the Carry flag |
000012f0  69 73 20 43 6c 65 61 72  2e 0d 0d 0d 42 69 74 20  |is Clear....Bit |
00001300  31 20 69 73 20 74 68 65  20 7a 65 72 6f 20 66 6c  |1 is the zero fl|
00001310  61 67 20 77 68 69 63 68  20 69 73 20 73 65 74 20  |ag which is set |
00001320  69 66 20 74 68 65 20 72  65 73 75 6c 74 20 6f 66  |if the result of|
00001330  20 73 6f 6d 65 0d 6f 70  65 72 61 74 69 6f 6e 20  | some.operation |
00001340  69 73 20 7a 65 72 6f 2c  20 6f 74 68 65 72 77 69  |is zero, otherwi|
00001350  73 65 20 69 74 20 69 73  20 63 6c 65 61 72 65 64  |se it is cleared|
00001360  2e 0d 0d 42 45 51 20 6d  65 61 6e 73 20 42 72 61  |...BEQ means Bra|
00001370  6e 63 68 20 69 66 20 45  51 75 61 6c 20 74 6f 20  |nch if EQual to |
00001380  7a 65 72 6f 2c 20 69 2e  65 2e 20 69 66 20 74 68  |zero, i.e. if th|
00001390  65 20 7a 65 72 6f 20 66  6c 61 67 20 69 73 0d 73  |e zero flag is.s|
000013a0  65 74 2c 20 42 4e 45 20  6d 65 61 6e 73 20 42 72  |et, BNE means Br|
000013b0  61 6e 63 68 20 69 66 20  4e 6f 74 20 45 71 75 61  |anch if Not Equa|
000013c0  6c 20 74 6f 20 7a 65 72  6f 2c 20 69 2e 65 2e 20  |l to zero, i.e. |
000013d0  69 66 20 74 68 65 20 7a  65 72 6f 0d 66 6c 61 67  |if the zero.flag|
000013e0  20 69 73 20 63 6c 65 61  72 2e 0d 0d 0d 54 68 65  | is clear....The|
000013f0  20 6e 65 78 74 20 66 6f  75 72 20 62 69 74 73 20  | next four bits |
00001400  64 6f 20 6e 6f 74 20 65  6e 74 65 72 20 69 6e 74  |do not enter int|
00001410  6f 20 6f 75 72 20 62 72  61 6e 63 68 69 6e 67 20  |o our branching |
00001420  61 6e 64 20 77 65 27 6c  6c 0d 63 6f 6d 65 20 62  |and we'll.come b|
00001430  61 63 6b 20 74 6f 20 74  68 65 6d 20 61 74 20 61  |ack to them at a|
00001440  20 6c 61 74 65 72 20 73  74 61 67 65 2e 0d 0d 42  | later stage...B|
00001450  69 74 20 32 20 69 73 20  74 68 65 20 69 6e 74 65  |it 2 is the inte|
00001460  72 72 75 70 74 20 66 6c  61 67 2c 20 73 65 74 20  |rrupt flag, set |
00001470  77 68 65 6e 20 69 6e 74  65 72 72 75 70 74 73 20  |when interrupts |
00001480  61 72 65 0d 64 69 73 61  62 6c 65 64 2e 0d 0d 42  |are.disabled...B|
00001490  69 74 20 33 20 69 73 20  74 68 65 20 64 65 63 69  |it 3 is the deci|
000014a0  6d 61 6c 20 66 6c 61 67  2e 20 20 57 68 65 6e 20  |mal flag.  When |
000014b0  73 65 74 20 74 68 65 20  70 72 6f 63 65 73 73 6f  |set the processo|
000014c0  72 0d 63 61 6c 63 75 6c  61 74 65 73 20 69 6e 20  |r.calculates in |
000014d0  42 69 6e 61 72 79 20 43  6f 64 65 64 20 44 65 63  |Binary Coded Dec|
000014e0  69 6d 61 6c 2e 0d 0d 42  69 74 20 34 20 69 73 20  |imal...Bit 4 is |
000014f0  74 68 65 20 62 72 65 61  6b 20 66 6c 61 67 20 61  |the break flag a|
00001500  6e 64 20 69 73 20 73 65  74 20 64 75 72 69 6e 67  |nd is set during|
00001510  20 61 20 42 52 4b 20 69  6e 74 65 72 72 75 70 74  | a BRK interrupt|
00001520  2e 0d 0d 42 69 74 20 35  20 69 73 20 6e 6f 74 20  |...Bit 5 is not |
00001530  75 73 65 64 2e 0d 0d 0d  42 69 74 20 36 20 69 73  |used....Bit 6 is|
00001540  20 74 68 65 20 6f 76 65  72 66 6c 6f 77 20 66 6c  | the overflow fl|
00001550  61 67 20 77 68 69 63 68  20 69 73 20 73 65 74 20  |ag which is set |
00001560  69 66 20 74 68 65 72 65  20 69 73 20 61 0d 64 69  |if there is a.di|
00001570  73 63 72 65 70 61 6e 63  79 20 62 65 74 77 65 65  |screpancy betwee|
00001580  6e 20 74 68 65 20 63 61  72 72 79 20 62 65 74 77  |n the carry betw|
00001590  65 65 6e 20 62 69 74 73  20 36 20 61 6e 64 20 37  |een bits 6 and 7|
000015a0  20 61 6e 64 20 6f 75 74  0d 6f 66 20 62 69 74 20  | and out.of bit |
000015b0  37 20 64 75 72 69 6e 67  20 61 64 64 69 74 69 6f  |7 during additio|
000015c0  6e 20 61 6e 64 20 73 75  62 74 72 61 63 74 69 6f  |n and subtractio|
000015d0  6e 2e 0d 0d 42 56 53 20  6d 65 61 6e 73 20 42 72  |n...BVS means Br|
000015e0  61 6e 63 68 20 69 66 20  6f 56 65 72 66 6c 6f 77  |anch if oVerflow|
000015f0  20 73 65 74 20 61 6e 64  20 42 56 43 20 6d 65 61  | set and BVC mea|
00001600  6e 73 20 42 72 61 6e 63  68 20 69 66 0d 6f 56 65  |ns Branch if.oVe|
00001610  72 66 6c 6f 77 20 63 6c  65 61 72 2e 0d 0d 0d 42  |rflow clear....B|
00001620  69 74 20 37 20 69 73 20  74 68 65 20 6e 65 67 61  |it 7 is the nega|
00001630  74 69 76 65 20 66 6c 61  67 2c 20 73 65 74 20 69  |tive flag, set i|
00001640  66 20 74 68 65 20 74 6f  70 20 62 69 74 20 6f 66  |f the top bit of|
00001650  20 74 68 65 20 6c 61 73  74 0d 6f 70 65 72 61 74  | the last.operat|
00001660  69 6f 6e 20 69 73 20 73  65 74 2c 20 6f 74 68 65  |ion is set, othe|
00001670  72 77 69 73 65 20 63 6c  65 61 72 2e 0d 0d 42 4d  |rwise clear...BM|
00001680  49 20 6d 65 61 6e 73 20  42 72 61 6e 63 68 20 6f  |I means Branch o|
00001690  6e 20 4d 49 6e 75 73 2c  20 69 2e 65 2e 20 74 68  |n MInus, i.e. th|
000016a0  65 20 6e 65 67 61 74 69  76 65 20 66 6c 61 67 20  |e negative flag |
000016b0  69 73 20 73 65 74 2c 0d  61 6e 64 20 42 50 4c 20  |is set,.and BPL |
000016c0  6d 65 61 6e 73 20 42 72  61 6e 63 68 20 6f 6e 20  |means Branch on |
000016d0  50 4c 75 73 2c 20 69 2e  65 2e 20 74 68 65 20 6e  |PLus, i.e. the n|
000016e0  65 67 61 74 69 76 65 20  66 6c 61 67 20 69 73 0d  |egative flag is.|
000016f0  63 6c 65 61 72 2e 0d 0d  0d 46 69 6e 61 6c 6c 79  |clear....Finally|
00001700  20 74 68 65 72 65 20 69  73 20 74 68 65 20 73 74  | there is the st|
00001710  61 63 6b 20 70 6f 69 6e  74 65 72 2e 20 20 54 68  |ack pointer.  Th|
00001720  65 20 73 74 61 63 6b 20  69 73 20 61 20 73 70 65  |e stack is a spe|
00001730  63 69 61 6c 0d 73 65 63  74 69 6f 6e 20 6f 66 20  |cial.section of |
00001740  6d 65 6d 6f 72 79 20 75  73 65 64 20 62 79 20 74  |memory used by t|
00001750  68 65 20 36 35 30 32 20  61 6e 64 20 74 68 69 73  |he 6502 and this|
00001760  20 72 65 67 69 73 74 65  72 20 68 6f 6c 64 73 0d  | register holds.|
00001770  74 68 65 20 6c 6f 77 65  73 74 20 73 69 67 6e 69  |the lowest signi|
00001780  66 69 63 61 6e 74 20 62  79 74 65 20 28 4c 53 42  |ficant byte (LSB|
00001790  29 20 6f 66 20 74 68 65  20 6e 65 78 74 20 66 72  |) of the next fr|
000017a0  65 65 20 73 74 61 63 6b  0d 6d 65 6d 6f 72 79 20  |ee stack.memory |
000017b0  6c 6f 63 61 74 69 6f 6e  2e 20 20 54 68 65 20 36  |location.  The 6|
000017c0  35 30 32 20 61 6c 77 61  79 73 20 6b 65 65 70 73  |502 always keeps|
000017d0  20 69 74 73 20 73 74 61  63 6b 20 69 6e 20 6d 65  | its stack in me|
000017e0  6d 6f 72 79 0d 62 65 74  77 65 65 6e 20 26 31 30  |mory.between &10|
000017f0  30 20 61 6e 64 20 26 31  46 46 2c 20 63 61 6c 6c  |0 and &1FF, call|
00001800  65 64 20 50 61 67 65 20  31 2e 20 20 59 6f 75 20  |ed Page 1.  You |
00001810  63 61 6e 20 72 65 61 64  20 61 6e 64 0d 77 72 69  |can read and.wri|
00001820  74 65 20 74 6f 20 74 68  65 20 73 74 61 63 6b 20  |te to the stack |
00001830  70 6f 69 6e 74 65 72 20  61 6e 64 20 74 68 65 20  |pointer and the |
00001840  73 74 61 63 6b 20 62 75  74 20 77 65 27 6c 6c 20  |stack but we'll |
00001850  6c 65 61 76 65 0d 74 68  69 73 20 74 6f 20 6c 61  |leave.this to la|
00001860  74 65 72 2e 0d 0d 57 65  20 73 68 61 6c 6c 20 75  |ter...We shall u|
00001870  73 65 20 62 72 61 6e 63  68 69 6e 67 20 69 6e 73  |se branching ins|
00001880  74 72 75 63 74 69 6f 6e  73 20 74 6f 20 63 61 72  |tructions to car|
00001890  72 79 20 6f 75 74 20 74  68 65 0d 65 71 75 69 76  |ry out the.equiv|
000018a0  61 6c 65 6e 74 20 6f 66  20 49 46 20 54 48 45 4e  |alent of IF THEN|
000018b0  20 45 4c 53 45 20 69 6e  73 74 72 75 63 74 69 6f  | ELSE instructio|
000018c0  6e 73 2e 20 20 42 75 74  20 77 65 20 61 6c 73 6f  |ns.  But we also|
000018d0  20 6e 65 65 64 0d 74 6f  20 68 61 76 65 20 74 68  | need.to have th|
000018e0  65 20 65 71 75 69 76 61  6c 65 6e 74 20 6f 66 20  |e equivalent of |
000018f0  47 4f 54 4f 20 61 6e 64  20 47 4f 53 55 42 20 61  |GOTO and GOSUB a|
00001900  6e 64 20 74 68 65 73 65  20 61 72 65 20 4a 4d 50  |nd these are JMP|
00001910  0d 61 6e 64 20 4a 53 52  2e 0d 0d 4a 4d 50 20 65  |.and JSR...JMP e|
00001920  6c 73 65 77 68 65 72 65  20 2d 20 73 69 6d 70 6c  |lsewhere - simpl|
00001930  79 20 6a 75 6d 70 73 20  74 6f 20 74 68 65 20 69  |y jumps to the i|
00001940  6e 73 74 72 75 63 74 69  6f 6e 20 73 74 6f 72 65  |nstruction store|
00001950  64 20 61 74 0d 27 65 6c  73 65 77 68 65 72 65 27  |d at.'elsewhere'|
00001960  2e 20 20 49 6e 20 61 64  64 69 74 69 6f 6e 20 79  |.  In addition y|
00001970  6f 75 20 63 61 6e 20 4a  4d 50 20 28 65 6c 73 65  |ou can JMP (else|
00001980  77 68 65 72 65 29 20 77  68 69 63 68 0d 6a 75 6d  |where) which.jum|
00001990  70 73 20 74 6f 20 74 68  65 20 69 6e 73 74 72 75  |ps to the instru|
000019a0  63 74 69 6f 6e 20 73 74  6f 72 65 64 20 61 74 20  |ction stored at |
000019b0  74 68 65 20 61 64 64 72  65 73 73 20 73 74 6f 72  |the address stor|
000019c0  65 64 20 61 74 0d 27 65  6c 73 65 77 68 65 72 65  |ed at.'elsewhere|
000019d0  27 20 61 6e 64 20 27 65  6c 73 65 77 68 65 72 65  |' and 'elsewhere|
000019e0  27 2b 31 2e 20 20 54 68  69 73 20 69 73 20 61 6e  |'+1.  This is an|
000019f0  20 69 6e 64 69 72 65 63  74 20 6a 75 6d 70 20 6f  | indirect jump o|
00001a00  66 0d 77 68 69 63 68 20  6d 6f 72 65 20 61 6e 6f  |f.which more ano|
00001a10  74 68 65 72 20 74 69 6d  65 2e 0d 0d 4a 53 52 20  |ther time...JSR |
00001a20  65 6c 73 65 77 68 65 72  65 20 2d 20 6a 75 6d 70  |elsewhere - jump|
00001a30  73 20 74 6f 20 74 68 65  20 69 6e 73 74 72 75 63  |s to the instruc|
00001a40  74 69 6f 6e 20 73 74 6f  72 65 64 20 61 74 0d 27  |tion stored at.'|
00001a50  65 6c 73 65 77 68 65 72  65 27 20 62 75 74 20 74  |elsewhere' but t|
00001a60  68 65 20 61 64 64 72 65  73 73 20 6f 66 20 74 68  |he address of th|
00001a70  65 20 69 6e 73 74 72 75  63 74 69 6f 6e 20 61 66  |e instruction af|
00001a80  74 65 72 20 74 68 65 20  4a 53 52 0d 69 73 20 73  |ter the JSR.is s|
00001a90  74 6f 72 65 64 20 6f 6e  20 74 68 65 20 73 74 61  |tored on the sta|
00001aa0  63 6b 20 61 6e 64 20 77  68 65 6e 20 74 68 65 20  |ck and when the |
00001ab0  70 72 6f 67 72 61 6d 20  72 65 61 63 68 65 73 20  |program reaches |
00001ac0  74 68 65 20 6e 65 78 74  0d 52 54 53 20 69 6e 73  |the next.RTS ins|
00001ad0  74 72 75 63 74 69 6f 6e  20 69 74 20 72 65 74 75  |truction it retu|
00001ae0  72 6e 73 20 74 6f 20 74  68 61 74 20 61 64 64 72  |rns to that addr|
00001af0  65 73 73 2e 20 20 54 68  65 20 70 69 65 63 65 20  |ess.  The piece |
00001b00  6f 66 0d 70 72 6f 67 72  61 6d 20 62 65 74 77 65  |of.program betwe|
00001b10  65 6e 20 27 65 6c 73 65  77 68 65 72 65 27 20 61  |en 'elsewhere' a|
00001b20  6e 64 20 74 68 65 20 52  54 53 20 69 73 20 61 20  |nd the RTS is a |
00001b30  73 75 62 72 6f 75 74 69  6e 65 2e 0d 0d 4f 6e 65  |subroutine...One|
00001b40  20 69 6d 70 6f 72 74 61  6e 74 20 74 68 69 6e 67  | important thing|
00001b50  20 74 6f 20 72 65 6d 65  6d 62 65 72 20 61 62 6f  | to remember abo|
00001b60  75 74 20 73 75 62 72 6f  75 74 69 6e 65 73 20 69  |ut subroutines i|
00001b70  73 20 74 68 61 74 0d 74  68 65 79 20 63 61 6e 20  |s that.they can |
00001b80  63 68 61 6e 67 65 20 74  68 65 20 76 61 6c 75 65  |change the value|
00001b90  73 20 68 65 6c 64 20 69  6e 20 79 6f 75 72 20 72  |s held in your r|
00001ba0  65 67 69 73 74 65 72 73  20 61 6e 64 20 74 68 65  |egisters and the|
00001bb0  0d 73 65 74 74 69 6e 67  73 20 6f 66 20 79 6f 75  |.settings of you|
00001bc0  72 20 66 6c 61 67 73 2e  20 20 49 74 27 73 20 77  |r flags.  It's w|
00001bd0  6f 72 74 68 20 6e 6f 74  69 6e 67 20 77 68 61 74  |orth noting what|
00001be0  20 63 68 61 6e 67 65 73  2c 20 69 66 0d 61 6e 79  | changes, if.any|
00001bf0  2c 20 74 68 65 20 73 75  62 72 6f 75 74 69 6e 65  |, the subroutine|
00001c00  20 6d 61 6b 65 73 20 62  65 66 6f 72 65 20 69 74  | makes before it|
00001c10  20 72 65 74 75 72 6e 73  2e 20 20 49 6e 20 61 20  | returns.  In a |
00001c20  6c 61 74 65 72 0d 6d 6f  64 75 6c 65 20 49 20 77  |later.module I w|
00001c30  69 6c 6c 20 74 65 6c 6c  20 79 6f 75 20 68 6f 77  |ill tell you how|
00001c40  20 74 6f 20 70 72 65 73  65 72 76 65 20 79 6f 75  | to preserve you|
00001c50  72 20 72 65 67 69 73 74  65 72 73 20 61 6e 64 0d  |r registers and.|
00001c60  66 6c 61 67 73 2e 0d 0d  41 20 66 69 6e 61 6c 20  |flags...A final |
00001c70  73 65 74 20 6f 66 20 69  6e 73 74 72 75 63 74 69  |set of instructi|
00001c80  6f 6e 73 20 74 68 61 74  20 77 69 6c 6c 20 62 65  |ons that will be|
00001c90  20 6e 65 65 64 65 64 20  66 6f 72 0d 62 72 61 6e  | needed for.bran|
00001ca0  63 68 69 6e 67 20 61 72  65 20 43 4d 50 2c 20 43  |ching are CMP, C|
00001cb0  50 58 20 61 6e 64 20 43  50 59 2e 20 20 54 68 65  |PX and CPY.  The|
00001cc0  20 73 74 61 74 75 73 20  72 65 67 69 73 74 65 72  | status register|
00001cd0  20 66 6c 61 67 73 0d 61  72 65 20 73 65 74 20 61  | flags.are set a|
00001ce0  75 74 6f 6d 61 74 69 63  61 6c 6c 79 20 75 6e 64  |utomatically und|
00001cf0  65 72 20 73 6f 6d 65 20  63 69 72 63 75 6d 73 74  |er some circumst|
00001d00  61 6e 63 65 73 2e 20 20  46 6f 72 20 65 78 61 6d  |ances.  For exam|
00001d10  70 6c 65 0d 74 68 65 20  7a 65 72 6f 2c 20 6e 65  |ple.the zero, ne|
00001d20  67 61 74 69 76 65 2c 20  6f 76 65 72 66 6c 6f 77  |gative, overflow|
00001d30  20 61 6e 64 20 63 61 72  72 79 20 66 6c 61 67 73  | and carry flags|
00001d40  20 63 61 6e 20 61 6c 6c  20 62 65 0d 61 66 66 65  | can all be.affe|
00001d50  63 74 65 64 20 61 66 74  65 72 20 61 6e 20 41 44  |cted after an AD|
00001d60  43 2e 20 20 41 6e 6f 74  68 65 72 20 77 61 79 20  |C.  Another way |
00001d70  6f 66 20 73 65 74 74 69  6e 67 20 74 68 65 73 65  |of setting these|
00001d80  20 66 6c 61 67 73 0d 69  73 20 62 79 20 75 73 69  | flags.is by usi|
00001d90  6e 67 20 43 4d 50 20 74  6f 20 63 6f 6d 70 61 72  |ng CMP to compar|
00001da0  65 20 74 68 65 20 61 63  63 75 6d 75 6c 61 74 6f  |e the accumulato|
00001db0  72 20 77 69 74 68 20 65  69 74 68 65 72 20 61 0d  |r with either a.|
00001dc0  76 61 6c 75 65 20 69 6e  20 6d 65 6d 6f 72 79 20  |value in memory |
00001dd0  6f 72 20 64 69 72 65 63  74 6c 79 20 77 69 74 68  |or directly with|
00001de0  20 61 20 6e 75 6d 62 65  72 2e 0d 0d 65 2e 67 2e  | a number...e.g.|
00001df0  20 20 20 20 20 20 20 43  4d 50 20 73 6f 6d 65 77  |       CMP somew|
00001e00  68 65 72 65 20 20 20 20  20 20 20 6f 72 20 20 20  |here       or   |
00001e10  20 20 20 20 20 43 4d 50  20 23 31 33 0d 0d 49 6e  |     CMP #13..In|
00001e20  20 62 6f 74 68 20 63 61  73 65 73 20 74 68 65 20  | both cases the |
00001e30  76 61 6c 75 65 20 69 6e  20 74 68 65 20 61 63 63  |value in the acc|
00001e40  75 6d 75 6c 61 74 6f 72  20 69 73 20 6e 6f 74 20  |umulator is not |
00001e50  63 68 61 6e 67 65 64 0d  62 75 74 20 74 68 65 20  |changed.but the |
00001e60  66 6c 61 67 73 20 61 72  65 20 73 65 74 20 61 6e  |flags are set an|
00001e70  64 20 73 6f 20 62 72 61  6e 63 68 69 6e 67 20 69  |d so branching i|
00001e80  6e 73 74 72 75 63 74 69  6f 6e 73 20 73 75 63 68  |nstructions such|
00001e90  20 61 73 0d 42 45 51 20  6f 72 20 42 4d 49 20 63  | as.BEQ or BMI c|
00001ea0  61 6e 20 62 65 20 75 73  65 64 2e 20 20 4f 6e 65  |an be used.  One|
00001eb0  20 70 61 72 74 69 63 75  6c 61 72 20 62 72 61 6e  | particular bran|
00001ec0  63 68 20 74 6f 20 72 65  6d 65 6d 62 65 72 0d 61  |ch to remember.a|
00001ed0  66 74 65 72 20 61 20 43  4d 50 20 69 73 20 74 68  |fter a CMP is th|
00001ee0  61 74 20 74 68 65 20 63  61 72 72 79 20 66 6c 61  |at the carry fla|
00001ef0  67 20 69 73 20 73 65 74  20 69 66 20 74 68 65 20  |g is set if the |
00001f00  76 61 6c 75 65 20 69 6e  20 41 0d 69 73 20 67 72  |value in A.is gr|
00001f10  65 61 74 65 72 20 74 68  61 6e 20 6f 72 20 65 71  |eater than or eq|
00001f20  75 61 6c 20 74 6f 20 74  68 65 20 76 61 6c 75 65  |ual to the value|
00001f30  20 69 6e 20 27 73 6f 6d  65 77 68 65 72 65 27 20  | in 'somewhere' |
00001f40  28 6f 72 20 31 33 29 0d  69 6e 20 74 68 65 20 65  |(or 13).in the e|
00001f50  78 61 6d 70 6c 65 20 61  62 6f 76 65 2e 20 20 54  |xample above.  T|
00001f60  68 69 73 20 6d 61 6b 65  73 20 42 43 53 20 65 71  |his makes BCS eq|
00001f70  75 69 76 61 6c 65 6e 74  20 74 6f 20 61 20 62 72  |uivalent to a br|
00001f80  61 6e 63 68 0d 69 66 20  67 72 65 61 74 65 72 20  |anch.if greater |
00001f90  74 68 61 6e 20 6f 72 20  65 71 75 61 6c 2e 20 20  |than or equal.  |
00001fa0  28 44 6f 20 6e 6f 74 20  75 73 65 20 42 4d 49 20  |(Do not use BMI |
00001fb0  6f 72 20 42 50 4c 20 66  6f 72 20 74 68 69 73 2e  |or BPL for this.|
00001fc0  29 0d 0d 49 6e 20 74 68  65 20 70 72 6f 67 72 61  |)..In the progra|
00001fd0  6d 20 42 2f 6f 73 62 30  33 20 69 6e 20 74 68 69  |m B/osb03 in thi|
00001fe0  73 20 74 65 6c 65 73 6f  66 74 77 61 72 65 20 74  |s telesoftware t|
00001ff0  72 61 6e 73 6d 69 73 73  69 6f 6e 20 69 73 0d 61  |ransmission is.a|
00002000  20 72 6f 75 74 69 6e 65  20 74 68 61 74 20 64 65  | routine that de|
00002010  74 65 63 74 73 20 77 68  65 74 68 65 72 20 61 20  |tects whether a |
00002020  6b 65 79 20 70 72 65 73  73 65 64 20 69 73 20 75  |key pressed is u|
00002030  70 70 65 72 20 6f 72 0d  6c 6f 77 65 72 20 63 61  |pper or.lower ca|
00002040  73 65 2c 20 61 20 6e 75  6d 62 65 72 2c 20 70 75  |se, a number, pu|
00002050  6e 63 74 75 61 74 69 6f  6e 20 6f 72 20 61 20 63  |nctuation or a c|
00002060  6f 6e 74 72 6f 6c 20 63  6f 64 65 20 61 6e 64 0d  |ontrol code and.|
00002070  70 72 69 6e 74 73 20 6f  75 74 20 61 20 6d 65 73  |prints out a mes|
00002080  73 61 67 65 20 61 63 63  6f 72 64 69 6e 67 6c 79  |sage accordingly|
00002090  2e 20 20 49 74 20 75 73  65 73 20 61 6e 20 6f 70  |.  It uses an op|
000020a0  65 72 61 74 69 6e 67 0d  73 79 73 74 65 6d 20 72  |erating.system r|
000020b0  6f 75 74 69 6e 65 20 74  6f 20 72 65 61 64 20 69  |outine to read i|
000020c0  6e 20 74 68 65 20 6b 65  79 20 70 72 65 73 73 2c  |n the key press,|
000020d0  20 74 68 69 73 20 69 73  20 4f 53 52 44 43 48 0d  | this is OSRDCH.|
000020e0  77 68 69 63 68 20 69 73  20 74 68 65 20 65 71 75  |which is the equ|
000020f0  69 76 61 6c 65 6e 74 20  6f 66 20 42 41 53 49 43  |ivalent of BASIC|
00002100  27 73 20 47 45 54 20 63  6f 6d 6d 61 6e 64 2e 20  |'s GET command. |
00002110  20 54 68 65 0d 62 72 61  6e 63 68 69 6e 67 20 69  | The.branching i|
00002120  73 20 64 6f 6e 65 20 6d  61 69 6e 6c 79 20 75 73  |s done mainly us|
00002130  69 6e 67 20 74 68 65 20  63 61 72 72 79 20 66 6c  |ing the carry fl|
00002140  61 67 20 61 6e 64 20 74  68 65 0d 6d 65 73 73 61  |ag and the.messa|
00002150  67 65 73 20 61 72 65 20  6f 75 74 70 75 74 20 75  |ges are output u|
00002160  73 69 6e 67 20 69 6e 64  65 78 65 64 20 61 64 64  |sing indexed add|
00002170  72 65 73 73 69 6e 67 20  61 6e 64 20 74 68 65 20  |ressing and the |
00002180  4f 53 41 53 43 49 0d 72  6f 75 74 69 6e 65 20 66  |OSASCI.routine f|
00002190  6f 72 20 70 72 69 6e 74  69 6e 67 20 74 6f 20 74  |or printing to t|
000021a0  68 65 20 73 63 72 65 65  6e 2e 0d 0d 54 68 69 6e  |he screen...Thin|
000021b0  67 73 20 74 6f 20 6e 6f  74 65 3a 0d 0d 42 43 53  |gs to note:..BCS|
000021c0  20 67 69 76 65 73 20 61  20 62 72 61 6e 63 68 20  | gives a branch |
000021d0  6f 6e 20 67 72 65 61 74  65 72 20 74 68 61 6e 20  |on greater than |
000021e0  6f 72 20 65 71 75 61 6c  20 74 6f 2c 20 6e 6f 74  |or equal to, not|
000021f0  20 6a 75 73 74 20 6f 6e  0d 67 72 65 61 74 65 72  | just on.greater|
00002200  20 74 68 61 6e 2e 0d 0d  54 68 69 73 20 70 72 6f  | than...This pro|
00002210  67 72 61 6d 20 6f 70 65  72 61 74 65 73 20 6c 69  |gram operates li|
00002220  6b 65 20 61 20 73 65 72  69 65 73 20 6f 66 20 73  |ke a series of s|
00002230  69 65 76 65 73 2c 20 65  61 63 68 20 73 74 61 67  |ieves, each stag|
00002240  65 0d 6c 65 74 73 20 74  68 72 6f 75 67 68 20 66  |e.lets through f|
00002250  65 77 65 72 20 61 6e 64  20 66 65 77 65 72 20 76  |ewer and fewer v|
00002260  61 6c 75 65 73 20 69 6e  20 41 20 75 6e 74 69 6c  |alues in A until|
00002270  20 74 68 6f 73 65 20 6c  65 66 74 0d 63 61 6e 20  | those left.can |
00002280  6f 6e 6c 79 20 62 65 20  70 75 6e 63 74 75 61 74  |only be punctuat|
00002290  69 6f 6e 2e 20 20 49 6e  20 74 68 69 73 20 63 61  |ion.  In this ca|
000022a0  73 65 20 77 65 20 73 74  61 72 74 20 73 69 65 76  |se we start siev|
000022b0  69 6e 67 20 66 72 6f 6d  0d 74 68 65 20 62 6f 74  |ing from.the bot|
000022c0  74 6f 6d 2c 20 77 69 74  68 20 63 6f 6e 74 72 6f  |tom, with contro|
000022d0  6c 20 63 6f 64 65 73 2e  0d 0d 4e 6f 74 65 20 74  |l codes...Note t|
000022e0  68 65 20 64 6f 75 62 6c  65 20 6c 61 62 65 6c 6c  |he double labell|
000022f0  69 6e 67 20 6f 66 20 27  74 65 78 74 27 20 61 6e  |ing of 'text' an|
00002300  64 20 27 63 6f 6e 74 72  6f 6c 27 2e 20 20 49 74  |d 'control'.  It|
00002310  20 74 61 6b 65 73 0d 75  70 20 6e 6f 20 72 6f 6f  | takes.up no roo|
00002320  6d 20 69 6e 20 74 68 65  20 61 73 73 65 6d 62 6c  |m in the assembl|
00002330  65 64 20 63 6f 64 65 20  6f 66 20 63 6f 75 72 73  |ed code of cours|
00002340  65 20 62 75 74 20 49 20  68 6f 70 65 20 69 74 0d  |e but I hope it.|
00002350  6d 61 6b 65 73 20 74 68  65 20 73 6f 75 72 63 65  |makes the source|
00002360  20 63 6f 64 65 20 61 20  6c 69 74 74 6c 65 20 63  | code a little c|
00002370  6c 65 61 72 65 72 2e 0d  0d 54 68 65 20 76 65 72  |learer...The ver|
00002380  79 20 63 6f 6e 76 6f 6c  75 74 65 64 20 77 61 79  |y convoluted way|
00002390  20 6f 66 20 70 75 74 74  69 6e 67 20 74 68 65 20  | of putting the |
000023a0  73 74 72 69 6e 67 73 20  69 6e 74 6f 20 6d 65 6d  |strings into mem|
000023b0  6f 72 79 0d 69 73 20 6e  6f 74 20 6e 65 63 65 73  |ory.is not neces|
000023c0  73 61 72 79 2c 20 49 20  77 69 6c 6c 20 73 68 6f  |sary, I will sho|
000023d0  77 20 79 6f 75 20 61 20  6d 6f 72 65 20 65 6c 65  |w you a more ele|
000023e0  67 61 6e 74 20 77 61 79  20 69 6e 20 74 68 65 0d  |gant way in the.|
000023f0  6e 65 78 74 20 66 69 6c  65 2e 0d 0d 49 6e 20 74  |next file...In t|
00002400  68 69 73 20 70 61 72 74  69 63 75 6c 61 72 20 70  |his particular p|
00002410  69 65 63 65 20 6f 66 20  63 6f 64 65 20 79 6f 75  |iece of code you|
00002420  20 63 61 6e 20 72 65 70  6c 61 63 65 20 65 76 65  | can replace eve|
00002430  72 79 0d 6f 63 63 75 72  72 65 6e 63 65 20 6f 66  |ry.occurrence of|
00002440  20 4a 53 52 20 2a 2a 2a  2a 20 66 6f 6c 6c 6f 77  | JSR **** follow|
00002450  65 64 20 62 79 20 52 54  53 20 77 69 74 68 20 6a  |ed by RTS with j|
00002460  75 73 74 20 61 20 4a 4d  50 20 2a 2a 2a 2a 2e 20  |ust a JMP ****. |
00002470  0d 43 61 6e 20 79 6f 75  20 73 65 65 20 77 68 79  |.Can you see why|
00002480  20 74 68 69 73 20 77 6f  72 6b 73 3f 20 20 4d 6f  | this works?  Mo|
00002490  64 69 66 79 20 74 68 65  20 73 6f 75 72 63 65 20  |dify the source |
000024a0  63 6f 64 65 20 74 6f 20  64 6f 0d 74 68 69 73 20  |code to do.this |
000024b0  61 6e 64 20 79 6f 75 20  77 69 6c 6c 20 66 69 6e  |and you will fin|
000024c0  64 20 69 74 20 61 20 6c  69 74 74 6c 65 20 73 68  |d it a little sh|
000024d0  6f 72 74 65 72 2e 20 20  49 74 20 77 69 6c 6c 20  |orter.  It will |
000024e0  61 6c 73 6f 20 62 65 0d  61 20 6c 69 74 74 6c 65  |also be.a little|
000024f0  20 66 61 73 74 65 72 20  62 75 74 20 49 20 64 6f  | faster but I do|
00002500  75 62 74 20 69 66 20 79  6f 75 20 77 69 6c 6c 20  |ubt if you will |
00002510  6e 6f 74 69 63 65 20 74  68 61 74 2e 20 4e 6f 74  |notice that. Not|
00002520  69 63 65 0d 77 68 61 74  20 69 74 20 6c 65 61 64  |ice.what it lead|
00002530  73 20 79 6f 75 20 74 6f  20 64 6f 20 62 65 74 77  |s you to do betw|
00002540  65 65 6e 20 6c 69 6e 65  73 20 37 34 30 20 61 6e  |een lines 740 an|
00002550  64 20 38 37 30 20 77 68  65 72 65 20 79 6f 75 0d  |d 870 where you.|
00002560  68 61 76 65 20 4a 4d 50  73 20 74 6f 20 74 68 65  |have JMPs to the|
00002570  20 6e 65 78 74 20 6c 69  6e 65 2c 20 77 68 69 63  | next line, whic|
00002580  68 20 63 61 6e 20 74 68  65 6e 20 62 65 20 72 65  |h can then be re|
00002590  6d 6f 76 65 64 0d 63 6f  6d 70 6c 65 74 65 6c 79  |moved.completely|
000025a0  2e 0d 0d 41 6c 6c 20 69  6e 20 61 6c 6c 20 74 68  |...All in all th|
000025b0  69 73 20 63 6f 64 65 20  69 73 20 77 72 69 74 74  |is code is writt|
000025c0  65 6e 20 74 6f 20 62 65  20 72 65 61 64 61 62 6c  |en to be readabl|
000025d0  65 20 61 73 20 73 65 63  74 69 6f 6e 73 0d 62 75  |e as sections.bu|
000025e0  74 20 63 61 6e 20 62 65  20 73 68 6f 72 74 65 6e  |t can be shorten|
000025f0  65 64 20 74 6f 20 62 65  20 6d 6f 72 65 20 65 66  |ed to be more ef|
00002600  66 69 63 69 65 6e 74 2e  20 20 49 74 20 69 73 20  |ficient.  It is |
00002610  77 6f 72 74 68 0d 67 6f  69 6e 67 20 74 68 72 6f  |worth.going thro|
00002620  75 67 68 20 74 68 65 20  52 54 53 73 20 74 6f 20  |ugh the RTSs to |
00002630  73 65 65 20 6a 75 73 74  20 77 68 65 72 65 20 74  |see just where t|
00002640  68 65 79 20 72 65 74 75  72 6e 20 74 6f 2e 0d 0d  |hey return to...|
00002650  57 68 65 6e 20 74 68 65  20 63 6f 64 65 20 69 73  |When the code is|
00002660  20 72 75 6e 6e 69 6e 67  20 79 6f 75 20 63 61 6e  | running you can|
00002670  20 62 72 65 61 6b 20 6f  75 74 20 6f 66 20 69 74  | break out of it|
00002680  20 77 69 74 68 0d 45 53  43 41 50 45 2c 20 77 68  | with.ESCAPE, wh|
00002690  69 63 68 20 61 6c 73 6f  20 69 73 20 61 20 63 6f  |ich also is a co|
000026a0  6e 74 72 6f 6c 20 63 6f  64 65 2e 20 20 45 76 65  |ntrol code.  Eve|
000026b0  72 79 20 63 68 61 72 61  63 74 65 72 0d 70 72 65  |ry character.pre|
000026c0  73 73 65 64 20 6f 6e 20  74 68 65 20 62 6c 61 63  |ssed on the blac|
000026d0  6b 20 6b 65 79 73 20 77  69 6c 6c 20 6c 65 61 64  |k keys will lead|
000026e0  20 74 6f 20 61 20 70 72  69 6e 74 65 64 20 64 65  | to a printed de|
000026f0  73 63 72 69 70 74 69 76  65 0d 6c 69 6e 65 2e 0d  |scriptive.line..|
00002700  0d 49 20 68 6f 70 65 20  79 6f 75 20 6e 6f 77 20  |.I hope you now |
00002710  68 61 76 65 20 73 6f 6d  65 20 69 64 65 61 20 6f  |have some idea o|
00002720  66 20 68 6f 77 20 74 6f  20 75 73 65 20 74 68 65  |f how to use the|
00002730  20 61 73 73 65 6d 62 6c  65 72 0d 66 6f 72 20 61  | assembler.for a|
00002740  64 64 69 74 69 6f 6e 20  61 6e 64 20 73 75 62 74  |ddition and subt|
00002750  72 61 63 74 69 6f 6e 20  28 66 72 6f 6d 20 6c 61  |raction (from la|
00002760  73 74 20 77 65 65 6b 29  20 61 6e 64 20 66 6f 72  |st week) and for|
00002770  0d 62 72 61 6e 63 68 69  6e 67 20 61 6e 64 20 6a  |.branching and j|
00002780  75 6d 70 69 6e 67 2e 20  20 49 6e 20 74 68 65 20  |umping.  In the |
00002790  6e 65 78 74 20 6d 6f 64  75 6c 65 20 77 65 20 77  |next module we w|
000027a0  69 6c 6c 20 64 69 73 63  75 73 73 0d 62 65 74 74  |ill discuss.bett|
000027b0  65 72 20 77 61 79 73 20  6f 66 20 72 65 73 65 72  |er ways of reser|
000027c0  76 69 6e 67 20 6d 65 6d  6f 72 79 20 66 6f 72 20  |ving memory for |
000027d0  76 61 72 69 61 62 6c 65  73 20 28 69 6e 20 42 41  |variables (in BA|
000027e0  53 49 43 20 31 20 61 73  0d 77 65 6c 6c 20 61 73  |SIC 1 as.well as|
000027f0  20 69 6e 20 6c 61 74 65  72 20 42 41 53 49 43 73  | in later BASICs|
00002800  29 20 61 6e 64 20 77 68  65 72 65 20 74 6f 20 70  |) and where to p|
00002810  75 74 20 6d 61 63 68 69  6e 65 20 63 6f 64 65 0d  |ut machine code.|
00002820  70 72 6f 67 72 61 6d 73  2e 20 20 54 68 65 20 66  |programs.  The f|
00002830  69 72 73 74 20 74 68 69  6e 67 20 74 6f 20 6c 6f  |irst thing to lo|
00002840  6f 6b 20 61 74 20 6e 65  78 74 20 77 65 65 6b 20  |ok at next week |
00002850  77 69 6c 6c 20 62 65 20  74 68 65 0d 77 61 79 20  |will be the.way |
00002860  74 68 65 20 42 42 43 20  4d 69 63 72 6f 27 73 20  |the BBC Micro's |
00002870  6d 65 6d 6f 72 79 20 69  73 20 6f 72 67 61 6e 69  |memory is organi|
00002880  73 65 64 2e 0d                                    |sed..|
00002885
06_11_87/T\OSB03.m0
06_11_87/T\OSB03.m1
06_11_87/T\OSB03.m2
06_11_87/T\OSB03.m4
06_11_87/T\OSB03.m5