Home » CEEFAX disks » telesoftware3.adl » 27_11_87/T\OSB06

27_11_87/T\OSB06

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

By Programmer

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


Part 6: Rotating and Shifting


Continuing along the machine code trail this week I'll do
two things.  Firstly some more byte manipulation with bits
being rotated and shifted about, and second some thoughts on
where to keep numbers temporarily during your programs.

Right then, let's have some bit manipulation.  This is
something you can't do in BASIC although it is needed for
multiplication and division in machine code.

To start with here is a byte (the dots represent the ends of
the byte):

            .  b7 b6 b5 b4 b3 b2 b1 b0  .

each bit being the number b0 to b7, representing 2^n and
enabling us to make numbers up to 255 out of the byte.

There are four rotating/shifting operations we can carry out
on this byte.  First of all we can shift it left one place.
We now have the following result:

            b7 . b6 b5 b4 b3 b2 b1 b0 0  .

A new byte holding the old bits b6 down to b0 and with a
zero added in at the end.  The value of b7 has now set or
cleared the Carry flag.  This operation is called an
Arithmetic Shift Left and the mnemonic for it is ASL.  You
will probably also have seen that this operation also
effectively multiplies the number held in the byte by 2.

The equivalent operation but going right is a Logical Shift
Right with mnemonic LSR.  This time the value of bit 0 is
put in the carry flag and bit 7 replaced by a zero whilst
all the bits are shifted down one.  This effectively halves
the number in the byte.

OK so you may now be wondering in which two other directions
can we shift things.  Well obviously we only have left and
right but the other two operations rotate the carry flag
into the byte instead of shifting in a zero.

So we have ROL and ROR for a rotation left or right
respectively.  With ROL  bits 0 to 6 are moved up one, the
carry flag is put into bit 0 and the original bit 7 is put
in the carry flag.  With ROR bits 7 to 1 are moved down one,
the Carry flag is put into bit 7, and the original bit 0 is
put in the carry flag.

Obviously it is important that the state of the carry flag
is known before you ROL or ROR.

These four operations can be carried out on memory, e.g.

                   ROR temp
                   ASL &70

or on the Accumulator e.g.

                   LSR A

Besides having a place in multiplication and division these
operations enable you to examine a byte bit by bit.  If you
rotate a byte in the accumulator or in a memory location bit
by bit you can then test the Carry flag to see what each bit
is.  The program with this week's module, B/osb06, includes
a section that examines a byte in this way and prints out
its value in binary.

Most of the operations we have discussed so far, and
similarly for the others we will come to, can operate on
memory locations as well as the accumulator.  Now I have
said already that you use a label to indicate a memory
location and that such a label behaves as a BASIC variable
name.  Remember though that the variable holds the location
not what is in it.

Let's think about holding variables for a moment.  In
assembly language programming, as with many computer
languages (but not BBC BASIC ) you have to allocate a slot
for your variables before you actually store something.  I
use the term variable a little loosely to also include
constants that occupy a memory location throughout the whole
program.

We've already come across this allocation of space and have
used EQU or FNEQU methods for allocating it as the program
is assembled.  It's worth noting that you can use a slightly
dirty but nonetheless legal alternative like this:

                 .variable BRK

which sets the byte at address 'variable' to zero (the
mnemonic BRK assembles to zero).  As the actual value you
want to store there changes you just overwrite the byte at
'variable'.

As with other methods of allocating space this must not lie
in the path of your program, or the bytes stored will be
interpreted as instructions with unpredictable results.

If you want your code to run at any memory location
(relocatable code, something I'll discuss in detail in a
later module) you cannot put your variables within the
program space so you could deliberately put them at fixed
locations elsewhere in memory, such as within the zero page
space allocated for the user between &70 and &8F.  In this
case the sensible thing to do is define BASIC variables at
the start of your program, outside the assembly bit, just as
I've done with OS routines.

When you put variables into memory you can read the location
as many times as you like and the byte stored will remain
the same.  I often use a memory location I call 'accustore'
to store the byte currently being processed.  In this way,
no matter what I use the accumulator for I can retrieve the
main value from this location as many times as I like.  This
method is used in B/osb06 to hold a byte you type in with
one key stroke while the program prints it to the screen in
binary, hexadecimal and then decimal form.

There is a third and more specialised storage method.  This
uses the processor stack.  Now the 6502 reserves for itself
a page of memory, from &100 to &1FF, which it uses as a
last-in first-out store.  It is rather like a stack of
plates, hence its name.  The stack has an important function
in that it automatically holds the return address while
software is executing a subroutine.  In fact the RTS command
takes the top two memory locations off the stack and puts
them in the program counter.  I mention all this as a
warning that the storage trick I am about to divulge must
never be used where a subroutine call or return might
interfere.  Again you would get those notorious
unpredictable results.

Say you had just entered a subroutine and knew that the
routine was going to mess up the values of the accumulator
and X and Y registers.  Now you could save them to memory if
you wished and in many instances that would gain you a
little speed, but a neat thing to do is to use the stack. 
You would simply push the relevant register values onto the
stack while you did your computation in the subroutine and
then pull (or pop) them back again afterwards.  It is
important to make sure you do it the right way round.  This
means pulling back off the stack in the reverse order to the
way you pushed onto it, like this:

On the way in -       PHA
                      TXA
                      PHA
                      TYA
                      PHA

On the way back -     PLA
                      TAY
                      PLA
                      TAX
                      PLA

PHA means PusH A onto the stack and PLA means PulL A from
the stack.  Once you have pulled a value from the stack it
is effectively gone and the next pull will produce a
different value, unlike normal memory storage.  The
instructions TAX and TAY transfer A to X and Y while TXA and
TYA transfer X and Y to A.  There are also instructions to
push and pull the processor flags on and off the stack (PHP
and PLP) which are important if you are concerned about a
subroutine affecting the flags.

Those pushes and pulls must always balance out otherwise
your program will have, you guessed, unpredictable results. 
You could end up with your registers mixed up or with some
funny numbers getting into the program counter.

If you ever have subroutines that are recursive (call
themselves) then you have to use the stack for storage since
using a fixed location will be disastrous with each call
writing in a new value before the next outermost call can
reuse the value it put in there in the first place.  There
will also be times when you can not get at memory easily, if
you have written a sideways ROM for instance, and in these
cases the stack will be very useful.  However it is only 256
bytes long and too much use will make it overflow which will
almost certainly crash the machine.

In the case of both stack and memory storage if you want to
store anything larger than a byte you have to do so a byte
at a time.  In memory your label would represent the lowest
byte in memory which, in 6502 convention, stores the lowest
significant byte.  On the stack you can do as you wish,
providing it balances.

In B/osb06 there are a couple of places where I have used
the stack for brief storage, lines 550 + 610 and 1070 +
1190.  In the first instance I should really just have used
'accustore' since this is what it is for.  The latter though
is a reasonable instance of stack use as a temporary storage
for an interim result while the code checks for zeros.

Let's look at B/osb06 in more detail.  What it does is take
a byte that you type in by pressing a key and print its
value out in three ways.  Binary, hexadecimal and decimal.

The JSR osrdch at line 190 reads your keypress and puts it
in the accumulator.  (I'll be dealing with some more OS
routines next week).  It is then put into the 'accustore'
for the duration of the routine.

Now since I wanted this code to be self-contained and not
return to BASIC after each key press I had to put in some
way of exiting.  Any key value would do but ESCAPE seemed
most appropriate, although you have to carry out an escape
in an orderly manner.  So at line 220 the code checks for an
escape and if it detects one, by A being set to 27, OSBYTE
126 is called which carries out housekeeping to acknowledge
an ESCAPE after which we return to BASIC.  Because the
ESCAPE has been acknowledged you return to BASIC without an
error condition and so there is no printing of ESCAPE.  You
could try missing out the trap for 27, or omit the
acknowledgement and compare the results.

[It is possible to trigger an ESCAPE from another ASCII code
than 27, although 27 is the standard.  OSBYTE 220 will do
this.  You might do this to enable a device to generate
ESCAPE's down the RS423.]

If the key pressed is not ESCAPE then the three sections of
the program are executed.  Notice that three locations for
variables have been set at lines 290-310 using the BRK short
cut I mentioned earlier.

The first section prints out binary and it does this by
rotating the byte eight times, each time looking at the
carry flag and printing a 1 or 0 accordingly.  The loop that
does the work is between 400 and 460 and uses the X register
as a counter.  Since it is the Carry flag that is being used
we can make use of the ADC instruction to add, with carry, 0
to the ASCII value of 0.

Hexadecimal printing is more difficult.  First we separate
the top nybble of the byte (the top 4 bits) by shifting the
byte right four times.  This nybble must then hold a value
between 0 and 15, or 0 and F in hex.  A little trick with
binary coded decimal is of help here.

In binary coded decimal the four bits of a nybble can only
ever hold between 0 and 9, the other numbers just don't
exist and if you add 1 to 9 you get 10 and not A as you
would normally.  To tell the processor you are working in
BCD you set the decimal flag with an SED (line 710).

If the accumulator contains your nybble then adding 90 to it
in BCD mode gives you a number in the range 90 to 99 (Carry
clear) if you had 0 to 9 in there and 0 to 5 (Carry set) if
you had 10 to 15 in there. If we then add 40 with carry we
will get 30 to 39 or 41 to 46 (because of the Carry). 
Returning to normal binary (with CLD) these become &33 to
&39 or &41 to &46 which gives us the ASCII values of 0-9 or
A-F.  Thus you print the nybble value.

Regrabbing the original byte we then look at the lower
nybble by ANDing with &F which (more details in a week or
so) wipes the top four bits.  The nybble printing routine is
then repeated.

Decimal printing is more difficult still, and I don't know a
short-cut.  One extra complication I have introduced is that
in this case we don't print leading zeros, except for the
final figure.  In this case I have a subroutine called
'digit' which takes the value in the accumulator and prints
out the number of times the number in the Y register will go
into it.  This is found out by repeated subtraction.

In all cases here we are dealing only with byte sized
numbers.  In fact the first two routines will adapt easily
to any size of number but that is not so true of the decimal
one.

Next week some more OS calls and I'll show you how to use a
look-up table and indexed addressing to provide proportional
spacing.
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 0d 0d 0d  50 61 72 74 20 36 3a 20  |........Part 6: |
00000090  52 6f 74 61 74 69 6e 67  20 61 6e 64 20 53 68 69  |Rotating and Shi|
000000a0  66 74 69 6e 67 0d 0d 0d  43 6f 6e 74 69 6e 75 69  |fting...Continui|
000000b0  6e 67 20 61 6c 6f 6e 67  20 74 68 65 20 6d 61 63  |ng along the mac|
000000c0  68 69 6e 65 20 63 6f 64  65 20 74 72 61 69 6c 20  |hine code trail |
000000d0  74 68 69 73 20 77 65 65  6b 20 49 27 6c 6c 20 64  |this week I'll d|
000000e0  6f 0d 74 77 6f 20 74 68  69 6e 67 73 2e 20 20 46  |o.two things.  F|
000000f0  69 72 73 74 6c 79 20 73  6f 6d 65 20 6d 6f 72 65  |irstly some more|
00000100  20 62 79 74 65 20 6d 61  6e 69 70 75 6c 61 74 69  | byte manipulati|
00000110  6f 6e 20 77 69 74 68 20  62 69 74 73 0d 62 65 69  |on with bits.bei|
00000120  6e 67 20 72 6f 74 61 74  65 64 20 61 6e 64 20 73  |ng rotated and s|
00000130  68 69 66 74 65 64 20 61  62 6f 75 74 2c 20 61 6e  |hifted about, an|
00000140  64 20 73 65 63 6f 6e 64  20 73 6f 6d 65 20 74 68  |d second some th|
00000150  6f 75 67 68 74 73 20 6f  6e 0d 77 68 65 72 65 20  |oughts on.where |
00000160  74 6f 20 6b 65 65 70 20  6e 75 6d 62 65 72 73 20  |to keep numbers |
00000170  74 65 6d 70 6f 72 61 72  69 6c 79 20 64 75 72 69  |temporarily duri|
00000180  6e 67 20 79 6f 75 72 20  70 72 6f 67 72 61 6d 73  |ng your programs|
00000190  2e 0d 0d 52 69 67 68 74  20 74 68 65 6e 2c 20 6c  |...Right then, l|
000001a0  65 74 27 73 20 68 61 76  65 20 73 6f 6d 65 20 62  |et's have some b|
000001b0  69 74 20 6d 61 6e 69 70  75 6c 61 74 69 6f 6e 2e  |it manipulation.|
000001c0  20 20 54 68 69 73 20 69  73 0d 73 6f 6d 65 74 68  |  This is.someth|
000001d0  69 6e 67 20 79 6f 75 20  63 61 6e 27 74 20 64 6f  |ing you can't do|
000001e0  20 69 6e 20 42 41 53 49  43 20 61 6c 74 68 6f 75  | in BASIC althou|
000001f0  67 68 20 69 74 20 69 73  20 6e 65 65 64 65 64 20  |gh it is needed |
00000200  66 6f 72 0d 6d 75 6c 74  69 70 6c 69 63 61 74 69  |for.multiplicati|
00000210  6f 6e 20 61 6e 64 20 64  69 76 69 73 69 6f 6e 20  |on and division |
00000220  69 6e 20 6d 61 63 68 69  6e 65 20 63 6f 64 65 2e  |in machine code.|
00000230  0d 0d 54 6f 20 73 74 61  72 74 20 77 69 74 68 20  |..To start with |
00000240  68 65 72 65 20 69 73 20  61 20 62 79 74 65 20 28  |here is a byte (|
00000250  74 68 65 20 64 6f 74 73  20 72 65 70 72 65 73 65  |the dots represe|
00000260  6e 74 20 74 68 65 20 65  6e 64 73 20 6f 66 0d 74  |nt the ends of.t|
00000270  68 65 20 62 79 74 65 29  3a 0d 0d 20 20 20 20 20  |he byte):..     |
00000280  20 20 20 20 20 20 20 2e  20 20 62 37 20 62 36 20  |       .  b7 b6 |
00000290  62 35 20 62 34 20 62 33  20 62 32 20 62 31 20 62  |b5 b4 b3 b2 b1 b|
000002a0  30 20 20 2e 0d 0d 65 61  63 68 20 62 69 74 20 62  |0  ...each bit b|
000002b0  65 69 6e 67 20 74 68 65  20 6e 75 6d 62 65 72 20  |eing the number |
000002c0  62 30 20 74 6f 20 62 37  2c 20 72 65 70 72 65 73  |b0 to b7, repres|
000002d0  65 6e 74 69 6e 67 20 32  5e 6e 20 61 6e 64 0d 65  |enting 2^n and.e|
000002e0  6e 61 62 6c 69 6e 67 20  75 73 20 74 6f 20 6d 61  |nabling us to ma|
000002f0  6b 65 20 6e 75 6d 62 65  72 73 20 75 70 20 74 6f  |ke numbers up to|
00000300  20 32 35 35 20 6f 75 74  20 6f 66 20 74 68 65 20  | 255 out of the |
00000310  62 79 74 65 2e 0d 0d 54  68 65 72 65 20 61 72 65  |byte...There are|
00000320  20 66 6f 75 72 20 72 6f  74 61 74 69 6e 67 2f 73  | four rotating/s|
00000330  68 69 66 74 69 6e 67 20  6f 70 65 72 61 74 69 6f  |hifting operatio|
00000340  6e 73 20 77 65 20 63 61  6e 20 63 61 72 72 79 20  |ns we can carry |
00000350  6f 75 74 0d 6f 6e 20 74  68 69 73 20 62 79 74 65  |out.on this byte|
00000360  2e 20 20 46 69 72 73 74  20 6f 66 20 61 6c 6c 20  |.  First of all |
00000370  77 65 20 63 61 6e 20 73  68 69 66 74 20 69 74 20  |we can shift it |
00000380  6c 65 66 74 20 6f 6e 65  20 70 6c 61 63 65 2e 0d  |left one place..|
00000390  57 65 20 6e 6f 77 20 68  61 76 65 20 74 68 65 20  |We now have the |
000003a0  66 6f 6c 6c 6f 77 69 6e  67 20 72 65 73 75 6c 74  |following result|
000003b0  3a 0d 0d 20 20 20 20 20  20 20 20 20 20 20 20 62  |:..            b|
000003c0  37 20 2e 20 62 36 20 62  35 20 62 34 20 62 33 20  |7 . b6 b5 b4 b3 |
000003d0  62 32 20 62 31 20 62 30  20 30 20 20 2e 0d 0d 41  |b2 b1 b0 0  ...A|
000003e0  20 6e 65 77 20 62 79 74  65 20 68 6f 6c 64 69 6e  | new byte holdin|
000003f0  67 20 74 68 65 20 6f 6c  64 20 62 69 74 73 20 62  |g the old bits b|
00000400  36 20 64 6f 77 6e 20 74  6f 20 62 30 20 61 6e 64  |6 down to b0 and|
00000410  20 77 69 74 68 20 61 0d  7a 65 72 6f 20 61 64 64  | with a.zero add|
00000420  65 64 20 69 6e 20 61 74  20 74 68 65 20 65 6e 64  |ed in at the end|
00000430  2e 20 20 54 68 65 20 76  61 6c 75 65 20 6f 66 20  |.  The value of |
00000440  62 37 20 68 61 73 20 6e  6f 77 20 73 65 74 20 6f  |b7 has now set o|
00000450  72 0d 63 6c 65 61 72 65  64 20 74 68 65 20 43 61  |r.cleared the Ca|
00000460  72 72 79 20 66 6c 61 67  2e 20 20 54 68 69 73 20  |rry flag.  This |
00000470  6f 70 65 72 61 74 69 6f  6e 20 69 73 20 63 61 6c  |operation is cal|
00000480  6c 65 64 20 61 6e 0d 41  72 69 74 68 6d 65 74 69  |led an.Arithmeti|
00000490  63 20 53 68 69 66 74 20  4c 65 66 74 20 61 6e 64  |c Shift Left and|
000004a0  20 74 68 65 20 6d 6e 65  6d 6f 6e 69 63 20 66 6f  | the mnemonic fo|
000004b0  72 20 69 74 20 69 73 20  41 53 4c 2e 20 20 59 6f  |r it is ASL.  Yo|
000004c0  75 0d 77 69 6c 6c 20 70  72 6f 62 61 62 6c 79 20  |u.will probably |
000004d0  61 6c 73 6f 20 68 61 76  65 20 73 65 65 6e 20 74  |also have seen t|
000004e0  68 61 74 20 74 68 69 73  20 6f 70 65 72 61 74 69  |hat this operati|
000004f0  6f 6e 20 61 6c 73 6f 0d  65 66 66 65 63 74 69 76  |on also.effectiv|
00000500  65 6c 79 20 6d 75 6c 74  69 70 6c 69 65 73 20 74  |ely multiplies t|
00000510  68 65 20 6e 75 6d 62 65  72 20 68 65 6c 64 20 69  |he number held i|
00000520  6e 20 74 68 65 20 62 79  74 65 20 62 79 20 32 2e  |n the byte by 2.|
00000530  0d 0d 54 68 65 20 65 71  75 69 76 61 6c 65 6e 74  |..The equivalent|
00000540  20 6f 70 65 72 61 74 69  6f 6e 20 62 75 74 20 67  | operation but g|
00000550  6f 69 6e 67 20 72 69 67  68 74 20 69 73 20 61 20  |oing right is a |
00000560  4c 6f 67 69 63 61 6c 20  53 68 69 66 74 0d 52 69  |Logical Shift.Ri|
00000570  67 68 74 20 77 69 74 68  20 6d 6e 65 6d 6f 6e 69  |ght with mnemoni|
00000580  63 20 4c 53 52 2e 20 20  54 68 69 73 20 74 69 6d  |c LSR.  This tim|
00000590  65 20 74 68 65 20 76 61  6c 75 65 20 6f 66 20 62  |e the value of b|
000005a0  69 74 20 30 20 69 73 0d  70 75 74 20 69 6e 20 74  |it 0 is.put in t|
000005b0  68 65 20 63 61 72 72 79  20 66 6c 61 67 20 61 6e  |he carry flag an|
000005c0  64 20 62 69 74 20 37 20  72 65 70 6c 61 63 65 64  |d bit 7 replaced|
000005d0  20 62 79 20 61 20 7a 65  72 6f 20 77 68 69 6c 73  | by a zero whils|
000005e0  74 0d 61 6c 6c 20 74 68  65 20 62 69 74 73 20 61  |t.all the bits a|
000005f0  72 65 20 73 68 69 66 74  65 64 20 64 6f 77 6e 20  |re shifted down |
00000600  6f 6e 65 2e 20 20 54 68  69 73 20 65 66 66 65 63  |one.  This effec|
00000610  74 69 76 65 6c 79 20 68  61 6c 76 65 73 0d 74 68  |tively halves.th|
00000620  65 20 6e 75 6d 62 65 72  20 69 6e 20 74 68 65 20  |e number in the |
00000630  62 79 74 65 2e 0d 0d 4f  4b 20 73 6f 20 79 6f 75  |byte...OK so you|
00000640  20 6d 61 79 20 6e 6f 77  20 62 65 20 77 6f 6e 64  | may now be wond|
00000650  65 72 69 6e 67 20 69 6e  20 77 68 69 63 68 20 74  |ering in which t|
00000660  77 6f 20 6f 74 68 65 72  20 64 69 72 65 63 74 69  |wo other directi|
00000670  6f 6e 73 0d 63 61 6e 20  77 65 20 73 68 69 66 74  |ons.can we shift|
00000680  20 74 68 69 6e 67 73 2e  20 20 57 65 6c 6c 20 6f  | things.  Well o|
00000690  62 76 69 6f 75 73 6c 79  20 77 65 20 6f 6e 6c 79  |bviously we only|
000006a0  20 68 61 76 65 20 6c 65  66 74 20 61 6e 64 0d 72  | have left and.r|
000006b0  69 67 68 74 20 62 75 74  20 74 68 65 20 6f 74 68  |ight but the oth|
000006c0  65 72 20 74 77 6f 20 6f  70 65 72 61 74 69 6f 6e  |er two operation|
000006d0  73 20 72 6f 74 61 74 65  20 74 68 65 20 63 61 72  |s rotate the car|
000006e0  72 79 20 66 6c 61 67 0d  69 6e 74 6f 20 74 68 65  |ry flag.into the|
000006f0  20 62 79 74 65 20 69 6e  73 74 65 61 64 20 6f 66  | byte instead of|
00000700  20 73 68 69 66 74 69 6e  67 20 69 6e 20 61 20 7a  | shifting in a z|
00000710  65 72 6f 2e 0d 0d 53 6f  20 77 65 20 68 61 76 65  |ero...So we have|
00000720  20 52 4f 4c 20 61 6e 64  20 52 4f 52 20 66 6f 72  | ROL and ROR for|
00000730  20 61 20 72 6f 74 61 74  69 6f 6e 20 6c 65 66 74  | a rotation left|
00000740  20 6f 72 20 72 69 67 68  74 0d 72 65 73 70 65 63  | or right.respec|
00000750  74 69 76 65 6c 79 2e 20  20 57 69 74 68 20 52 4f  |tively.  With RO|
00000760  4c 20 20 62 69 74 73 20  30 20 74 6f 20 36 20 61  |L  bits 0 to 6 a|
00000770  72 65 20 6d 6f 76 65 64  20 75 70 20 6f 6e 65 2c  |re moved up one,|
00000780  20 74 68 65 0d 63 61 72  72 79 20 66 6c 61 67 20  | the.carry flag |
00000790  69 73 20 70 75 74 20 69  6e 74 6f 20 62 69 74 20  |is put into bit |
000007a0  30 20 61 6e 64 20 74 68  65 20 6f 72 69 67 69 6e  |0 and the origin|
000007b0  61 6c 20 62 69 74 20 37  20 69 73 20 70 75 74 0d  |al bit 7 is put.|
000007c0  69 6e 20 74 68 65 20 63  61 72 72 79 20 66 6c 61  |in the carry fla|
000007d0  67 2e 20 20 57 69 74 68  20 52 4f 52 20 62 69 74  |g.  With ROR bit|
000007e0  73 20 37 20 74 6f 20 31  20 61 72 65 20 6d 6f 76  |s 7 to 1 are mov|
000007f0  65 64 20 64 6f 77 6e 20  6f 6e 65 2c 0d 74 68 65  |ed down one,.the|
00000800  20 43 61 72 72 79 20 66  6c 61 67 20 69 73 20 70  | Carry flag is p|
00000810  75 74 20 69 6e 74 6f 20  62 69 74 20 37 2c 20 61  |ut into bit 7, a|
00000820  6e 64 20 74 68 65 20 6f  72 69 67 69 6e 61 6c 20  |nd the original |
00000830  62 69 74 20 30 20 69 73  0d 70 75 74 20 69 6e 20  |bit 0 is.put in |
00000840  74 68 65 20 63 61 72 72  79 20 66 6c 61 67 2e 0d  |the carry flag..|
00000850  0d 4f 62 76 69 6f 75 73  6c 79 20 69 74 20 69 73  |.Obviously it is|
00000860  20 69 6d 70 6f 72 74 61  6e 74 20 74 68 61 74 20  | important that |
00000870  74 68 65 20 73 74 61 74  65 20 6f 66 20 74 68 65  |the state of the|
00000880  20 63 61 72 72 79 20 66  6c 61 67 0d 69 73 20 6b  | carry flag.is k|
00000890  6e 6f 77 6e 20 62 65 66  6f 72 65 20 79 6f 75 20  |nown before you |
000008a0  52 4f 4c 20 6f 72 20 52  4f 52 2e 0d 0d 54 68 65  |ROL or ROR...The|
000008b0  73 65 20 66 6f 75 72 20  6f 70 65 72 61 74 69 6f  |se four operatio|
000008c0  6e 73 20 63 61 6e 20 62  65 20 63 61 72 72 69 65  |ns can be carrie|
000008d0  64 20 6f 75 74 20 6f 6e  20 6d 65 6d 6f 72 79 2c  |d out on memory,|
000008e0  20 65 2e 67 2e 0d 0d 20  20 20 20 20 20 20 20 20  | e.g...         |
000008f0  20 20 20 20 20 20 20 20  20 20 52 4f 52 20 74 65  |          ROR te|
00000900  6d 70 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |mp.             |
00000910  20 20 20 20 20 20 41 53  4c 20 26 37 30 0d 0d 6f  |      ASL &70..o|
00000920  72 20 6f 6e 20 74 68 65  20 41 63 63 75 6d 75 6c  |r on the Accumul|
00000930  61 74 6f 72 20 65 2e 67  2e 0d 0d 20 20 20 20 20  |ator e.g...     |
00000940  20 20 20 20 20 20 20 20  20 20 20 20 20 20 4c 53  |              LS|
00000950  52 20 41 0d 0d 42 65 73  69 64 65 73 20 68 61 76  |R A..Besides hav|
00000960  69 6e 67 20 61 20 70 6c  61 63 65 20 69 6e 20 6d  |ing a place in m|
00000970  75 6c 74 69 70 6c 69 63  61 74 69 6f 6e 20 61 6e  |ultiplication an|
00000980  64 20 64 69 76 69 73 69  6f 6e 20 74 68 65 73 65  |d division these|
00000990  0d 6f 70 65 72 61 74 69  6f 6e 73 20 65 6e 61 62  |.operations enab|
000009a0  6c 65 20 79 6f 75 20 74  6f 20 65 78 61 6d 69 6e  |le you to examin|
000009b0  65 20 61 20 62 79 74 65  20 62 69 74 20 62 79 20  |e a byte bit by |
000009c0  62 69 74 2e 20 20 49 66  20 79 6f 75 0d 72 6f 74  |bit.  If you.rot|
000009d0  61 74 65 20 61 20 62 79  74 65 20 69 6e 20 74 68  |ate a byte in th|
000009e0  65 20 61 63 63 75 6d 75  6c 61 74 6f 72 20 6f 72  |e accumulator or|
000009f0  20 69 6e 20 61 20 6d 65  6d 6f 72 79 20 6c 6f 63  | in a memory loc|
00000a00  61 74 69 6f 6e 20 62 69  74 0d 62 79 20 62 69 74  |ation bit.by bit|
00000a10  20 79 6f 75 20 63 61 6e  20 74 68 65 6e 20 74 65  | you can then te|
00000a20  73 74 20 74 68 65 20 43  61 72 72 79 20 66 6c 61  |st the Carry fla|
00000a30  67 20 74 6f 20 73 65 65  20 77 68 61 74 20 65 61  |g to see what ea|
00000a40  63 68 20 62 69 74 0d 69  73 2e 20 20 54 68 65 20  |ch bit.is.  The |
00000a50  70 72 6f 67 72 61 6d 20  77 69 74 68 20 74 68 69  |program with thi|
00000a60  73 20 77 65 65 6b 27 73  20 6d 6f 64 75 6c 65 2c  |s week's module,|
00000a70  20 42 2f 6f 73 62 30 36  2c 20 69 6e 63 6c 75 64  | B/osb06, includ|
00000a80  65 73 0d 61 20 73 65 63  74 69 6f 6e 20 74 68 61  |es.a section tha|
00000a90  74 20 65 78 61 6d 69 6e  65 73 20 61 20 62 79 74  |t examines a byt|
00000aa0  65 20 69 6e 20 74 68 69  73 20 77 61 79 20 61 6e  |e in this way an|
00000ab0  64 20 70 72 69 6e 74 73  20 6f 75 74 0d 69 74 73  |d prints out.its|
00000ac0  20 76 61 6c 75 65 20 69  6e 20 62 69 6e 61 72 79  | value in binary|
00000ad0  2e 0d 0d 4d 6f 73 74 20  6f 66 20 74 68 65 20 6f  |...Most of the o|
00000ae0  70 65 72 61 74 69 6f 6e  73 20 77 65 20 68 61 76  |perations we hav|
00000af0  65 20 64 69 73 63 75 73  73 65 64 20 73 6f 20 66  |e discussed so f|
00000b00  61 72 2c 20 61 6e 64 0d  73 69 6d 69 6c 61 72 6c  |ar, and.similarl|
00000b10  79 20 66 6f 72 20 74 68  65 20 6f 74 68 65 72 73  |y for the others|
00000b20  20 77 65 20 77 69 6c 6c  20 63 6f 6d 65 20 74 6f  | we will come to|
00000b30  2c 20 63 61 6e 20 6f 70  65 72 61 74 65 20 6f 6e  |, can operate on|
00000b40  0d 6d 65 6d 6f 72 79 20  6c 6f 63 61 74 69 6f 6e  |.memory location|
00000b50  73 20 61 73 20 77 65 6c  6c 20 61 73 20 74 68 65  |s as well as the|
00000b60  20 61 63 63 75 6d 75 6c  61 74 6f 72 2e 20 20 4e  | accumulator.  N|
00000b70  6f 77 20 49 20 68 61 76  65 0d 73 61 69 64 20 61  |ow I have.said a|
00000b80  6c 72 65 61 64 79 20 74  68 61 74 20 79 6f 75 20  |lready that you |
00000b90  75 73 65 20 61 20 6c 61  62 65 6c 20 74 6f 20 69  |use a label to i|
00000ba0  6e 64 69 63 61 74 65 20  61 20 6d 65 6d 6f 72 79  |ndicate a memory|
00000bb0  0d 6c 6f 63 61 74 69 6f  6e 20 61 6e 64 20 74 68  |.location and th|
00000bc0  61 74 20 73 75 63 68 20  61 20 6c 61 62 65 6c 20  |at such a label |
00000bd0  62 65 68 61 76 65 73 20  61 73 20 61 20 42 41 53  |behaves as a BAS|
00000be0  49 43 20 76 61 72 69 61  62 6c 65 0d 6e 61 6d 65  |IC variable.name|
00000bf0  2e 20 20 52 65 6d 65 6d  62 65 72 20 74 68 6f 75  |.  Remember thou|
00000c00  67 68 20 74 68 61 74 20  74 68 65 20 76 61 72 69  |gh that the vari|
00000c10  61 62 6c 65 20 68 6f 6c  64 73 20 74 68 65 20 6c  |able holds the l|
00000c20  6f 63 61 74 69 6f 6e 0d  6e 6f 74 20 77 68 61 74  |ocation.not what|
00000c30  20 69 73 20 69 6e 20 69  74 2e 0d 0d 4c 65 74 27  | is in it...Let'|
00000c40  73 20 74 68 69 6e 6b 20  61 62 6f 75 74 20 68 6f  |s think about ho|
00000c50  6c 64 69 6e 67 20 76 61  72 69 61 62 6c 65 73 20  |lding variables |
00000c60  66 6f 72 20 61 20 6d 6f  6d 65 6e 74 2e 20 20 49  |for a moment.  I|
00000c70  6e 0d 61 73 73 65 6d 62  6c 79 20 6c 61 6e 67 75  |n.assembly langu|
00000c80  61 67 65 20 70 72 6f 67  72 61 6d 6d 69 6e 67 2c  |age programming,|
00000c90  20 61 73 20 77 69 74 68  20 6d 61 6e 79 20 63 6f  | as with many co|
00000ca0  6d 70 75 74 65 72 0d 6c  61 6e 67 75 61 67 65 73  |mputer.languages|
00000cb0  20 28 62 75 74 20 6e 6f  74 20 42 42 43 20 42 41  | (but not BBC BA|
00000cc0  53 49 43 20 29 20 79 6f  75 20 68 61 76 65 20 74  |SIC ) you have t|
00000cd0  6f 20 61 6c 6c 6f 63 61  74 65 20 61 20 73 6c 6f  |o allocate a slo|
00000ce0  74 0d 66 6f 72 20 79 6f  75 72 20 76 61 72 69 61  |t.for your varia|
00000cf0  62 6c 65 73 20 62 65 66  6f 72 65 20 79 6f 75 20  |bles before you |
00000d00  61 63 74 75 61 6c 6c 79  20 73 74 6f 72 65 20 73  |actually store s|
00000d10  6f 6d 65 74 68 69 6e 67  2e 20 20 49 0d 75 73 65  |omething.  I.use|
00000d20  20 74 68 65 20 74 65 72  6d 20 76 61 72 69 61 62  | the term variab|
00000d30  6c 65 20 61 20 6c 69 74  74 6c 65 20 6c 6f 6f 73  |le a little loos|
00000d40  65 6c 79 20 74 6f 20 61  6c 73 6f 20 69 6e 63 6c  |ely to also incl|
00000d50  75 64 65 0d 63 6f 6e 73  74 61 6e 74 73 20 74 68  |ude.constants th|
00000d60  61 74 20 6f 63 63 75 70  79 20 61 20 6d 65 6d 6f  |at occupy a memo|
00000d70  72 79 20 6c 6f 63 61 74  69 6f 6e 20 74 68 72 6f  |ry location thro|
00000d80  75 67 68 6f 75 74 20 74  68 65 20 77 68 6f 6c 65  |ughout the whole|
00000d90  0d 70 72 6f 67 72 61 6d  2e 0d 0d 57 65 27 76 65  |.program...We've|
00000da0  20 61 6c 72 65 61 64 79  20 63 6f 6d 65 20 61 63  | already come ac|
00000db0  72 6f 73 73 20 74 68 69  73 20 61 6c 6c 6f 63 61  |ross this alloca|
00000dc0  74 69 6f 6e 20 6f 66 20  73 70 61 63 65 20 61 6e  |tion of space an|
00000dd0  64 20 68 61 76 65 0d 75  73 65 64 20 45 51 55 20  |d have.used EQU |
00000de0  6f 72 20 46 4e 45 51 55  20 6d 65 74 68 6f 64 73  |or FNEQU methods|
00000df0  20 66 6f 72 20 61 6c 6c  6f 63 61 74 69 6e 67 20  | for allocating |
00000e00  69 74 20 61 73 20 74 68  65 20 70 72 6f 67 72 61  |it as the progra|
00000e10  6d 0d 69 73 20 61 73 73  65 6d 62 6c 65 64 2e 20  |m.is assembled. |
00000e20  20 49 74 27 73 20 77 6f  72 74 68 20 6e 6f 74 69  | It's worth noti|
00000e30  6e 67 20 74 68 61 74 20  79 6f 75 20 63 61 6e 20  |ng that you can |
00000e40  75 73 65 20 61 20 73 6c  69 67 68 74 6c 79 0d 64  |use a slightly.d|
00000e50  69 72 74 79 20 62 75 74  20 6e 6f 6e 65 74 68 65  |irty but nonethe|
00000e60  6c 65 73 73 20 6c 65 67  61 6c 20 61 6c 74 65 72  |less legal alter|
00000e70  6e 61 74 69 76 65 20 6c  69 6b 65 20 74 68 69 73  |native like this|
00000e80  3a 0d 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |:..             |
00000e90  20 20 20 20 2e 76 61 72  69 61 62 6c 65 20 42 52  |    .variable BR|
00000ea0  4b 0d 0d 77 68 69 63 68  20 73 65 74 73 20 74 68  |K..which sets th|
00000eb0  65 20 62 79 74 65 20 61  74 20 61 64 64 72 65 73  |e byte at addres|
00000ec0  73 20 27 76 61 72 69 61  62 6c 65 27 20 74 6f 20  |s 'variable' to |
00000ed0  7a 65 72 6f 20 28 74 68  65 0d 6d 6e 65 6d 6f 6e  |zero (the.mnemon|
00000ee0  69 63 20 42 52 4b 20 61  73 73 65 6d 62 6c 65 73  |ic BRK assembles|
00000ef0  20 74 6f 20 7a 65 72 6f  29 2e 20 20 41 73 20 74  | to zero).  As t|
00000f00  68 65 20 61 63 74 75 61  6c 20 76 61 6c 75 65 20  |he actual value |
00000f10  79 6f 75 0d 77 61 6e 74  20 74 6f 20 73 74 6f 72  |you.want to stor|
00000f20  65 20 74 68 65 72 65 20  63 68 61 6e 67 65 73 20  |e there changes |
00000f30  79 6f 75 20 6a 75 73 74  20 6f 76 65 72 77 72 69  |you just overwri|
00000f40  74 65 20 74 68 65 20 62  79 74 65 20 61 74 0d 27  |te the byte at.'|
00000f50  76 61 72 69 61 62 6c 65  27 2e 0d 0d 41 73 20 77  |variable'...As w|
00000f60  69 74 68 20 6f 74 68 65  72 20 6d 65 74 68 6f 64  |ith other method|
00000f70  73 20 6f 66 20 61 6c 6c  6f 63 61 74 69 6e 67 20  |s of allocating |
00000f80  73 70 61 63 65 20 74 68  69 73 20 6d 75 73 74 20  |space this must |
00000f90  6e 6f 74 20 6c 69 65 0d  69 6e 20 74 68 65 20 70  |not lie.in the p|
00000fa0  61 74 68 20 6f 66 20 79  6f 75 72 20 70 72 6f 67  |ath of your prog|
00000fb0  72 61 6d 2c 20 6f 72 20  74 68 65 20 62 79 74 65  |ram, or the byte|
00000fc0  73 20 73 74 6f 72 65 64  20 77 69 6c 6c 20 62 65  |s stored will be|
00000fd0  0d 69 6e 74 65 72 70 72  65 74 65 64 20 61 73 20  |.interpreted as |
00000fe0  69 6e 73 74 72 75 63 74  69 6f 6e 73 20 77 69 74  |instructions wit|
00000ff0  68 20 75 6e 70 72 65 64  69 63 74 61 62 6c 65 20  |h unpredictable |
00001000  72 65 73 75 6c 74 73 2e  0d 0d 49 66 20 79 6f 75  |results...If you|
00001010  20 77 61 6e 74 20 79 6f  75 72 20 63 6f 64 65 20  | want your code |
00001020  74 6f 20 72 75 6e 20 61  74 20 61 6e 79 20 6d 65  |to run at any me|
00001030  6d 6f 72 79 20 6c 6f 63  61 74 69 6f 6e 0d 28 72  |mory location.(r|
00001040  65 6c 6f 63 61 74 61 62  6c 65 20 63 6f 64 65 2c  |elocatable code,|
00001050  20 73 6f 6d 65 74 68 69  6e 67 20 49 27 6c 6c 20  | something I'll |
00001060  64 69 73 63 75 73 73 20  69 6e 20 64 65 74 61 69  |discuss in detai|
00001070  6c 20 69 6e 20 61 0d 6c  61 74 65 72 20 6d 6f 64  |l in a.later mod|
00001080  75 6c 65 29 20 79 6f 75  20 63 61 6e 6e 6f 74 20  |ule) you cannot |
00001090  70 75 74 20 79 6f 75 72  20 76 61 72 69 61 62 6c  |put your variabl|
000010a0  65 73 20 77 69 74 68 69  6e 20 74 68 65 0d 70 72  |es within the.pr|
000010b0  6f 67 72 61 6d 20 73 70  61 63 65 20 73 6f 20 79  |ogram space so y|
000010c0  6f 75 20 63 6f 75 6c 64  20 64 65 6c 69 62 65 72  |ou could deliber|
000010d0  61 74 65 6c 79 20 70 75  74 20 74 68 65 6d 20 61  |ately put them a|
000010e0  74 20 66 69 78 65 64 0d  6c 6f 63 61 74 69 6f 6e  |t fixed.location|
000010f0  73 20 65 6c 73 65 77 68  65 72 65 20 69 6e 20 6d  |s elsewhere in m|
00001100  65 6d 6f 72 79 2c 20 73  75 63 68 20 61 73 20 77  |emory, such as w|
00001110  69 74 68 69 6e 20 74 68  65 20 7a 65 72 6f 20 70  |ithin the zero p|
00001120  61 67 65 0d 73 70 61 63  65 20 61 6c 6c 6f 63 61  |age.space alloca|
00001130  74 65 64 20 66 6f 72 20  74 68 65 20 75 73 65 72  |ted for the user|
00001140  20 62 65 74 77 65 65 6e  20 26 37 30 20 61 6e 64  | between &70 and|
00001150  20 26 38 46 2e 20 20 49  6e 20 74 68 69 73 0d 63  | &8F.  In this.c|
00001160  61 73 65 20 74 68 65 20  73 65 6e 73 69 62 6c 65  |ase the sensible|
00001170  20 74 68 69 6e 67 20 74  6f 20 64 6f 20 69 73 20  | thing to do is |
00001180  64 65 66 69 6e 65 20 42  41 53 49 43 20 76 61 72  |define BASIC var|
00001190  69 61 62 6c 65 73 20 61  74 0d 74 68 65 20 73 74  |iables at.the st|
000011a0  61 72 74 20 6f 66 20 79  6f 75 72 20 70 72 6f 67  |art of your prog|
000011b0  72 61 6d 2c 20 6f 75 74  73 69 64 65 20 74 68 65  |ram, outside the|
000011c0  20 61 73 73 65 6d 62 6c  79 20 62 69 74 2c 20 6a  | assembly bit, j|
000011d0  75 73 74 20 61 73 0d 49  27 76 65 20 64 6f 6e 65  |ust as.I've done|
000011e0  20 77 69 74 68 20 4f 53  20 72 6f 75 74 69 6e 65  | with OS routine|
000011f0  73 2e 0d 0d 57 68 65 6e  20 79 6f 75 20 70 75 74  |s...When you put|
00001200  20 76 61 72 69 61 62 6c  65 73 20 69 6e 74 6f 20  | variables into |
00001210  6d 65 6d 6f 72 79 20 79  6f 75 20 63 61 6e 20 72  |memory you can r|
00001220  65 61 64 20 74 68 65 20  6c 6f 63 61 74 69 6f 6e  |ead the location|
00001230  0d 61 73 20 6d 61 6e 79  20 74 69 6d 65 73 20 61  |.as many times a|
00001240  73 20 79 6f 75 20 6c 69  6b 65 20 61 6e 64 20 74  |s you like and t|
00001250  68 65 20 62 79 74 65 20  73 74 6f 72 65 64 20 77  |he byte stored w|
00001260  69 6c 6c 20 72 65 6d 61  69 6e 0d 74 68 65 20 73  |ill remain.the s|
00001270  61 6d 65 2e 20 20 49 20  6f 66 74 65 6e 20 75 73  |ame.  I often us|
00001280  65 20 61 20 6d 65 6d 6f  72 79 20 6c 6f 63 61 74  |e a memory locat|
00001290  69 6f 6e 20 49 20 63 61  6c 6c 20 27 61 63 63 75  |ion I call 'accu|
000012a0  73 74 6f 72 65 27 0d 74  6f 20 73 74 6f 72 65 20  |store'.to store |
000012b0  74 68 65 20 62 79 74 65  20 63 75 72 72 65 6e 74  |the byte current|
000012c0  6c 79 20 62 65 69 6e 67  20 70 72 6f 63 65 73 73  |ly being process|
000012d0  65 64 2e 20 20 49 6e 20  74 68 69 73 20 77 61 79  |ed.  In this way|
000012e0  2c 0d 6e 6f 20 6d 61 74  74 65 72 20 77 68 61 74  |,.no matter what|
000012f0  20 49 20 75 73 65 20 74  68 65 20 61 63 63 75 6d  | I use the accum|
00001300  75 6c 61 74 6f 72 20 66  6f 72 20 49 20 63 61 6e  |ulator for I can|
00001310  20 72 65 74 72 69 65 76  65 20 74 68 65 0d 6d 61  | retrieve the.ma|
00001320  69 6e 20 76 61 6c 75 65  20 66 72 6f 6d 20 74 68  |in value from th|
00001330  69 73 20 6c 6f 63 61 74  69 6f 6e 20 61 73 20 6d  |is location as m|
00001340  61 6e 79 20 74 69 6d 65  73 20 61 73 20 49 20 6c  |any times as I l|
00001350  69 6b 65 2e 20 20 54 68  69 73 0d 6d 65 74 68 6f  |ike.  This.metho|
00001360  64 20 69 73 20 75 73 65  64 20 69 6e 20 42 2f 6f  |d is used in B/o|
00001370  73 62 30 36 20 74 6f 20  68 6f 6c 64 20 61 20 62  |sb06 to hold a b|
00001380  79 74 65 20 79 6f 75 20  74 79 70 65 20 69 6e 20  |yte you type in |
00001390  77 69 74 68 0d 6f 6e 65  20 6b 65 79 20 73 74 72  |with.one key str|
000013a0  6f 6b 65 20 77 68 69 6c  65 20 74 68 65 20 70 72  |oke while the pr|
000013b0  6f 67 72 61 6d 20 70 72  69 6e 74 73 20 69 74 20  |ogram prints it |
000013c0  74 6f 20 74 68 65 20 73  63 72 65 65 6e 20 69 6e  |to the screen in|
000013d0  0d 62 69 6e 61 72 79 2c  20 68 65 78 61 64 65 63  |.binary, hexadec|
000013e0  69 6d 61 6c 20 61 6e 64  20 74 68 65 6e 20 64 65  |imal and then de|
000013f0  63 69 6d 61 6c 20 66 6f  72 6d 2e 0d 0d 54 68 65  |cimal form...The|
00001400  72 65 20 69 73 20 61 20  74 68 69 72 64 20 61 6e  |re is a third an|
00001410  64 20 6d 6f 72 65 20 73  70 65 63 69 61 6c 69 73  |d more specialis|
00001420  65 64 20 73 74 6f 72 61  67 65 20 6d 65 74 68 6f  |ed storage metho|
00001430  64 2e 20 20 54 68 69 73  0d 75 73 65 73 20 74 68  |d.  This.uses th|
00001440  65 20 70 72 6f 63 65 73  73 6f 72 20 73 74 61 63  |e processor stac|
00001450  6b 2e 20 20 4e 6f 77 20  74 68 65 20 36 35 30 32  |k.  Now the 6502|
00001460  20 72 65 73 65 72 76 65  73 20 66 6f 72 20 69 74  | reserves for it|
00001470  73 65 6c 66 0d 61 20 70  61 67 65 20 6f 66 20 6d  |self.a page of m|
00001480  65 6d 6f 72 79 2c 20 66  72 6f 6d 20 26 31 30 30  |emory, from &100|
00001490  20 74 6f 20 26 31 46 46  2c 20 77 68 69 63 68 20  | to &1FF, which |
000014a0  69 74 20 75 73 65 73 20  61 73 20 61 0d 6c 61 73  |it uses as a.las|
000014b0  74 2d 69 6e 20 66 69 72  73 74 2d 6f 75 74 20 73  |t-in first-out s|
000014c0  74 6f 72 65 2e 20 20 49  74 20 69 73 20 72 61 74  |tore.  It is rat|
000014d0  68 65 72 20 6c 69 6b 65  20 61 20 73 74 61 63 6b  |her like a stack|
000014e0  20 6f 66 0d 70 6c 61 74  65 73 2c 20 68 65 6e 63  | of.plates, henc|
000014f0  65 20 69 74 73 20 6e 61  6d 65 2e 20 20 54 68 65  |e its name.  The|
00001500  20 73 74 61 63 6b 20 68  61 73 20 61 6e 20 69 6d  | stack has an im|
00001510  70 6f 72 74 61 6e 74 20  66 75 6e 63 74 69 6f 6e  |portant function|
00001520  0d 69 6e 20 74 68 61 74  20 69 74 20 61 75 74 6f  |.in that it auto|
00001530  6d 61 74 69 63 61 6c 6c  79 20 68 6f 6c 64 73 20  |matically holds |
00001540  74 68 65 20 72 65 74 75  72 6e 20 61 64 64 72 65  |the return addre|
00001550  73 73 20 77 68 69 6c 65  0d 73 6f 66 74 77 61 72  |ss while.softwar|
00001560  65 20 69 73 20 65 78 65  63 75 74 69 6e 67 20 61  |e is executing a|
00001570  20 73 75 62 72 6f 75 74  69 6e 65 2e 20 20 49 6e  | subroutine.  In|
00001580  20 66 61 63 74 20 74 68  65 20 52 54 53 20 63 6f  | fact the RTS co|
00001590  6d 6d 61 6e 64 0d 74 61  6b 65 73 20 74 68 65 20  |mmand.takes the |
000015a0  74 6f 70 20 74 77 6f 20  6d 65 6d 6f 72 79 20 6c  |top two memory l|
000015b0  6f 63 61 74 69 6f 6e 73  20 6f 66 66 20 74 68 65  |ocations off the|
000015c0  20 73 74 61 63 6b 20 61  6e 64 20 70 75 74 73 0d  | stack and puts.|
000015d0  74 68 65 6d 20 69 6e 20  74 68 65 20 70 72 6f 67  |them in the prog|
000015e0  72 61 6d 20 63 6f 75 6e  74 65 72 2e 20 20 49 20  |ram counter.  I |
000015f0  6d 65 6e 74 69 6f 6e 20  61 6c 6c 20 74 68 69 73  |mention all this|
00001600  20 61 73 20 61 0d 77 61  72 6e 69 6e 67 20 74 68  | as a.warning th|
00001610  61 74 20 74 68 65 20 73  74 6f 72 61 67 65 20 74  |at the storage t|
00001620  72 69 63 6b 20 49 20 61  6d 20 61 62 6f 75 74 20  |rick I am about |
00001630  74 6f 20 64 69 76 75 6c  67 65 20 6d 75 73 74 0d  |to divulge must.|
00001640  6e 65 76 65 72 20 62 65  20 75 73 65 64 20 77 68  |never be used wh|
00001650  65 72 65 20 61 20 73 75  62 72 6f 75 74 69 6e 65  |ere a subroutine|
00001660  20 63 61 6c 6c 20 6f 72  20 72 65 74 75 72 6e 20  | call or return |
00001670  6d 69 67 68 74 0d 69 6e  74 65 72 66 65 72 65 2e  |might.interfere.|
00001680  20 20 41 67 61 69 6e 20  79 6f 75 20 77 6f 75 6c  |  Again you woul|
00001690  64 20 67 65 74 20 74 68  6f 73 65 20 6e 6f 74 6f  |d get those noto|
000016a0  72 69 6f 75 73 0d 75 6e  70 72 65 64 69 63 74 61  |rious.unpredicta|
000016b0  62 6c 65 20 72 65 73 75  6c 74 73 2e 0d 0d 53 61  |ble results...Sa|
000016c0  79 20 79 6f 75 20 68 61  64 20 6a 75 73 74 20 65  |y you had just e|
000016d0  6e 74 65 72 65 64 20 61  20 73 75 62 72 6f 75 74  |ntered a subrout|
000016e0  69 6e 65 20 61 6e 64 20  6b 6e 65 77 20 74 68 61  |ine and knew tha|
000016f0  74 20 74 68 65 0d 72 6f  75 74 69 6e 65 20 77 61  |t the.routine wa|
00001700  73 20 67 6f 69 6e 67 20  74 6f 20 6d 65 73 73 20  |s going to mess |
00001710  75 70 20 74 68 65 20 76  61 6c 75 65 73 20 6f 66  |up the values of|
00001720  20 74 68 65 20 61 63 63  75 6d 75 6c 61 74 6f 72  | the accumulator|
00001730  0d 61 6e 64 20 58 20 61  6e 64 20 59 20 72 65 67  |.and X and Y reg|
00001740  69 73 74 65 72 73 2e 20  20 4e 6f 77 20 79 6f 75  |isters.  Now you|
00001750  20 63 6f 75 6c 64 20 73  61 76 65 20 74 68 65 6d  | could save them|
00001760  20 74 6f 20 6d 65 6d 6f  72 79 20 69 66 0d 79 6f  | to memory if.yo|
00001770  75 20 77 69 73 68 65 64  20 61 6e 64 20 69 6e 20  |u wished and in |
00001780  6d 61 6e 79 20 69 6e 73  74 61 6e 63 65 73 20 74  |many instances t|
00001790  68 61 74 20 77 6f 75 6c  64 20 67 61 69 6e 20 79  |hat would gain y|
000017a0  6f 75 20 61 0d 6c 69 74  74 6c 65 20 73 70 65 65  |ou a.little spee|
000017b0  64 2c 20 62 75 74 20 61  20 6e 65 61 74 20 74 68  |d, but a neat th|
000017c0  69 6e 67 20 74 6f 20 64  6f 20 69 73 20 74 6f 20  |ing to do is to |
000017d0  75 73 65 20 74 68 65 20  73 74 61 63 6b 2e 20 0d  |use the stack. .|
000017e0  59 6f 75 20 77 6f 75 6c  64 20 73 69 6d 70 6c 79  |You would simply|
000017f0  20 70 75 73 68 20 74 68  65 20 72 65 6c 65 76 61  | push the releva|
00001800  6e 74 20 72 65 67 69 73  74 65 72 20 76 61 6c 75  |nt register valu|
00001810  65 73 20 6f 6e 74 6f 20  74 68 65 0d 73 74 61 63  |es onto the.stac|
00001820  6b 20 77 68 69 6c 65 20  79 6f 75 20 64 69 64 20  |k while you did |
00001830  79 6f 75 72 20 63 6f 6d  70 75 74 61 74 69 6f 6e  |your computation|
00001840  20 69 6e 20 74 68 65 20  73 75 62 72 6f 75 74 69  | in the subrouti|
00001850  6e 65 20 61 6e 64 0d 74  68 65 6e 20 70 75 6c 6c  |ne and.then pull|
00001860  20 28 6f 72 20 70 6f 70  29 20 74 68 65 6d 20 62  | (or pop) them b|
00001870  61 63 6b 20 61 67 61 69  6e 20 61 66 74 65 72 77  |ack again afterw|
00001880  61 72 64 73 2e 20 20 49  74 20 69 73 0d 69 6d 70  |ards.  It is.imp|
00001890  6f 72 74 61 6e 74 20 74  6f 20 6d 61 6b 65 20 73  |ortant to make s|
000018a0  75 72 65 20 79 6f 75 20  64 6f 20 69 74 20 74 68  |ure you do it th|
000018b0  65 20 72 69 67 68 74 20  77 61 79 20 72 6f 75 6e  |e right way roun|
000018c0  64 2e 20 20 54 68 69 73  0d 6d 65 61 6e 73 20 70  |d.  This.means p|
000018d0  75 6c 6c 69 6e 67 20 62  61 63 6b 20 6f 66 66 20  |ulling back off |
000018e0  74 68 65 20 73 74 61 63  6b 20 69 6e 20 74 68 65  |the stack in the|
000018f0  20 72 65 76 65 72 73 65  20 6f 72 64 65 72 20 74  | reverse order t|
00001900  6f 20 74 68 65 0d 77 61  79 20 79 6f 75 20 70 75  |o the.way you pu|
00001910  73 68 65 64 20 6f 6e 74  6f 20 69 74 2c 20 6c 69  |shed onto it, li|
00001920  6b 65 20 74 68 69 73 3a  0d 0d 4f 6e 20 74 68 65  |ke this:..On the|
00001930  20 77 61 79 20 69 6e 20  2d 20 20 20 20 20 20 20  | way in -       |
00001940  50 48 41 0d 20 20 20 20  20 20 20 20 20 20 20 20  |PHA.            |
00001950  20 20 20 20 20 20 20 20  20 20 54 58 41 0d 20 20  |          TXA.  |
00001960  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001970  20 20 20 20 50 48 41 0d  20 20 20 20 20 20 20 20  |    PHA.        |
00001980  20 20 20 20 20 20 20 20  20 20 20 20 20 20 54 59  |              TY|
00001990  41 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |A.              |
000019a0  20 20 20 20 20 20 20 20  50 48 41 0d 0d 4f 6e 20  |        PHA..On |
000019b0  74 68 65 20 77 61 79 20  62 61 63 6b 20 2d 20 20  |the way back -  |
000019c0  20 20 20 50 4c 41 0d 20  20 20 20 20 20 20 20 20  |   PLA.         |
000019d0  20 20 20 20 20 20 20 20  20 20 20 20 20 54 41 59  |             TAY|
000019e0  0d 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
000019f0  20 20 20 20 20 20 20 50  4c 41 0d 20 20 20 20 20  |       PLA.     |
00001a00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001a10  20 54 41 58 0d 20 20 20  20 20 20 20 20 20 20 20  | TAX.           |
00001a20  20 20 20 20 20 20 20 20  20 20 20 50 4c 41 0d 0d  |           PLA..|
00001a30  50 48 41 20 6d 65 61 6e  73 20 50 75 73 48 20 41  |PHA means PusH A|
00001a40  20 6f 6e 74 6f 20 74 68  65 20 73 74 61 63 6b 20  | onto the stack |
00001a50  61 6e 64 20 50 4c 41 20  6d 65 61 6e 73 20 50 75  |and PLA means Pu|
00001a60  6c 4c 20 41 20 66 72 6f  6d 0d 74 68 65 20 73 74  |lL A from.the st|
00001a70  61 63 6b 2e 20 20 4f 6e  63 65 20 79 6f 75 20 68  |ack.  Once you h|
00001a80  61 76 65 20 70 75 6c 6c  65 64 20 61 20 76 61 6c  |ave pulled a val|
00001a90  75 65 20 66 72 6f 6d 20  74 68 65 20 73 74 61 63  |ue from the stac|
00001aa0  6b 20 69 74 0d 69 73 20  65 66 66 65 63 74 69 76  |k it.is effectiv|
00001ab0  65 6c 79 20 67 6f 6e 65  20 61 6e 64 20 74 68 65  |ely gone and the|
00001ac0  20 6e 65 78 74 20 70 75  6c 6c 20 77 69 6c 6c 20  | next pull will |
00001ad0  70 72 6f 64 75 63 65 20  61 0d 64 69 66 66 65 72  |produce a.differ|
00001ae0  65 6e 74 20 76 61 6c 75  65 2c 20 75 6e 6c 69 6b  |ent value, unlik|
00001af0  65 20 6e 6f 72 6d 61 6c  20 6d 65 6d 6f 72 79 20  |e normal memory |
00001b00  73 74 6f 72 61 67 65 2e  20 20 54 68 65 0d 69 6e  |storage.  The.in|
00001b10  73 74 72 75 63 74 69 6f  6e 73 20 54 41 58 20 61  |structions TAX a|
00001b20  6e 64 20 54 41 59 20 74  72 61 6e 73 66 65 72 20  |nd TAY transfer |
00001b30  41 20 74 6f 20 58 20 61  6e 64 20 59 20 77 68 69  |A to X and Y whi|
00001b40  6c 65 20 54 58 41 20 61  6e 64 0d 54 59 41 20 74  |le TXA and.TYA t|
00001b50  72 61 6e 73 66 65 72 20  58 20 61 6e 64 20 59 20  |ransfer X and Y |
00001b60  74 6f 20 41 2e 20 20 54  68 65 72 65 20 61 72 65  |to A.  There are|
00001b70  20 61 6c 73 6f 20 69 6e  73 74 72 75 63 74 69 6f  | also instructio|
00001b80  6e 73 20 74 6f 0d 70 75  73 68 20 61 6e 64 20 70  |ns to.push and p|
00001b90  75 6c 6c 20 74 68 65 20  70 72 6f 63 65 73 73 6f  |ull the processo|
00001ba0  72 20 66 6c 61 67 73 20  6f 6e 20 61 6e 64 20 6f  |r flags on and o|
00001bb0  66 66 20 74 68 65 20 73  74 61 63 6b 20 28 50 48  |ff the stack (PH|
00001bc0  50 0d 61 6e 64 20 50 4c  50 29 20 77 68 69 63 68  |P.and PLP) which|
00001bd0  20 61 72 65 20 69 6d 70  6f 72 74 61 6e 74 20 69  | are important i|
00001be0  66 20 79 6f 75 20 61 72  65 20 63 6f 6e 63 65 72  |f you are concer|
00001bf0  6e 65 64 20 61 62 6f 75  74 20 61 0d 73 75 62 72  |ned about a.subr|
00001c00  6f 75 74 69 6e 65 20 61  66 66 65 63 74 69 6e 67  |outine affecting|
00001c10  20 74 68 65 20 66 6c 61  67 73 2e 0d 0d 54 68 6f  | the flags...Tho|
00001c20  73 65 20 70 75 73 68 65  73 20 61 6e 64 20 70 75  |se pushes and pu|
00001c30  6c 6c 73 20 6d 75 73 74  20 61 6c 77 61 79 73 20  |lls must always |
00001c40  62 61 6c 61 6e 63 65 20  6f 75 74 20 6f 74 68 65  |balance out othe|
00001c50  72 77 69 73 65 0d 79 6f  75 72 20 70 72 6f 67 72  |rwise.your progr|
00001c60  61 6d 20 77 69 6c 6c 20  68 61 76 65 2c 20 79 6f  |am will have, yo|
00001c70  75 20 67 75 65 73 73 65  64 2c 20 75 6e 70 72 65  |u guessed, unpre|
00001c80  64 69 63 74 61 62 6c 65  20 72 65 73 75 6c 74 73  |dictable results|
00001c90  2e 20 0d 59 6f 75 20 63  6f 75 6c 64 20 65 6e 64  |. .You could end|
00001ca0  20 75 70 20 77 69 74 68  20 79 6f 75 72 20 72 65  | up with your re|
00001cb0  67 69 73 74 65 72 73 20  6d 69 78 65 64 20 75 70  |gisters mixed up|
00001cc0  20 6f 72 20 77 69 74 68  20 73 6f 6d 65 0d 66 75  | or with some.fu|
00001cd0  6e 6e 79 20 6e 75 6d 62  65 72 73 20 67 65 74 74  |nny numbers gett|
00001ce0  69 6e 67 20 69 6e 74 6f  20 74 68 65 20 70 72 6f  |ing into the pro|
00001cf0  67 72 61 6d 20 63 6f 75  6e 74 65 72 2e 0d 0d 49  |gram counter...I|
00001d00  66 20 79 6f 75 20 65 76  65 72 20 68 61 76 65 20  |f you ever have |
00001d10  73 75 62 72 6f 75 74 69  6e 65 73 20 74 68 61 74  |subroutines that|
00001d20  20 61 72 65 20 72 65 63  75 72 73 69 76 65 20 28  | are recursive (|
00001d30  63 61 6c 6c 0d 74 68 65  6d 73 65 6c 76 65 73 29  |call.themselves)|
00001d40  20 74 68 65 6e 20 79 6f  75 20 68 61 76 65 20 74  | then you have t|
00001d50  6f 20 75 73 65 20 74 68  65 20 73 74 61 63 6b 20  |o use the stack |
00001d60  66 6f 72 20 73 74 6f 72  61 67 65 20 73 69 6e 63  |for storage sinc|
00001d70  65 0d 75 73 69 6e 67 20  61 20 66 69 78 65 64 20  |e.using a fixed |
00001d80  6c 6f 63 61 74 69 6f 6e  20 77 69 6c 6c 20 62 65  |location will be|
00001d90  20 64 69 73 61 73 74 72  6f 75 73 20 77 69 74 68  | disastrous with|
00001da0  20 65 61 63 68 20 63 61  6c 6c 0d 77 72 69 74 69  | each call.writi|
00001db0  6e 67 20 69 6e 20 61 20  6e 65 77 20 76 61 6c 75  |ng in a new valu|
00001dc0  65 20 62 65 66 6f 72 65  20 74 68 65 20 6e 65 78  |e before the nex|
00001dd0  74 20 6f 75 74 65 72 6d  6f 73 74 20 63 61 6c 6c  |t outermost call|
00001de0  20 63 61 6e 0d 72 65 75  73 65 20 74 68 65 20 76  | can.reuse the v|
00001df0  61 6c 75 65 20 69 74 20  70 75 74 20 69 6e 20 74  |alue it put in t|
00001e00  68 65 72 65 20 69 6e 20  74 68 65 20 66 69 72 73  |here in the firs|
00001e10  74 20 70 6c 61 63 65 2e  20 20 54 68 65 72 65 0d  |t place.  There.|
00001e20  77 69 6c 6c 20 61 6c 73  6f 20 62 65 20 74 69 6d  |will also be tim|
00001e30  65 73 20 77 68 65 6e 20  79 6f 75 20 63 61 6e 20  |es when you can |
00001e40  6e 6f 74 20 67 65 74 20  61 74 20 6d 65 6d 6f 72  |not get at memor|
00001e50  79 20 65 61 73 69 6c 79  2c 20 69 66 0d 79 6f 75  |y easily, if.you|
00001e60  20 68 61 76 65 20 77 72  69 74 74 65 6e 20 61 20  | have written a |
00001e70  73 69 64 65 77 61 79 73  20 52 4f 4d 20 66 6f 72  |sideways ROM for|
00001e80  20 69 6e 73 74 61 6e 63  65 2c 20 61 6e 64 20 69  | instance, and i|
00001e90  6e 20 74 68 65 73 65 0d  63 61 73 65 73 20 74 68  |n these.cases th|
00001ea0  65 20 73 74 61 63 6b 20  77 69 6c 6c 20 62 65 20  |e stack will be |
00001eb0  76 65 72 79 20 75 73 65  66 75 6c 2e 20 20 48 6f  |very useful.  Ho|
00001ec0  77 65 76 65 72 20 69 74  20 69 73 20 6f 6e 6c 79  |wever it is only|
00001ed0  20 32 35 36 0d 62 79 74  65 73 20 6c 6f 6e 67 20  | 256.bytes long |
00001ee0  61 6e 64 20 74 6f 6f 20  6d 75 63 68 20 75 73 65  |and too much use|
00001ef0  20 77 69 6c 6c 20 6d 61  6b 65 20 69 74 20 6f 76  | will make it ov|
00001f00  65 72 66 6c 6f 77 20 77  68 69 63 68 20 77 69 6c  |erflow which wil|
00001f10  6c 0d 61 6c 6d 6f 73 74  20 63 65 72 74 61 69 6e  |l.almost certain|
00001f20  6c 79 20 63 72 61 73 68  20 74 68 65 20 6d 61 63  |ly crash the mac|
00001f30  68 69 6e 65 2e 0d 0d 49  6e 20 74 68 65 20 63 61  |hine...In the ca|
00001f40  73 65 20 6f 66 20 62 6f  74 68 20 73 74 61 63 6b  |se of both stack|
00001f50  20 61 6e 64 20 6d 65 6d  6f 72 79 20 73 74 6f 72  | and memory stor|
00001f60  61 67 65 20 69 66 20 79  6f 75 20 77 61 6e 74 20  |age if you want |
00001f70  74 6f 0d 73 74 6f 72 65  20 61 6e 79 74 68 69 6e  |to.store anythin|
00001f80  67 20 6c 61 72 67 65 72  20 74 68 61 6e 20 61 20  |g larger than a |
00001f90  62 79 74 65 20 79 6f 75  20 68 61 76 65 20 74 6f  |byte you have to|
00001fa0  20 64 6f 20 73 6f 20 61  20 62 79 74 65 0d 61 74  | do so a byte.at|
00001fb0  20 61 20 74 69 6d 65 2e  20 20 49 6e 20 6d 65 6d  | a time.  In mem|
00001fc0  6f 72 79 20 79 6f 75 72  20 6c 61 62 65 6c 20 77  |ory your label w|
00001fd0  6f 75 6c 64 20 72 65 70  72 65 73 65 6e 74 20 74  |ould represent t|
00001fe0  68 65 20 6c 6f 77 65 73  74 0d 62 79 74 65 20 69  |he lowest.byte i|
00001ff0  6e 20 6d 65 6d 6f 72 79  20 77 68 69 63 68 2c 20  |n memory which, |
00002000  69 6e 20 36 35 30 32 20  63 6f 6e 76 65 6e 74 69  |in 6502 conventi|
00002010  6f 6e 2c 20 73 74 6f 72  65 73 20 74 68 65 20 6c  |on, stores the l|
00002020  6f 77 65 73 74 0d 73 69  67 6e 69 66 69 63 61 6e  |owest.significan|
00002030  74 20 62 79 74 65 2e 20  20 4f 6e 20 74 68 65 20  |t byte.  On the |
00002040  73 74 61 63 6b 20 79 6f  75 20 63 61 6e 20 64 6f  |stack you can do|
00002050  20 61 73 20 79 6f 75 20  77 69 73 68 2c 0d 70 72  | as you wish,.pr|
00002060  6f 76 69 64 69 6e 67 20  69 74 20 62 61 6c 61 6e  |oviding it balan|
00002070  63 65 73 2e 0d 0d 49 6e  20 42 2f 6f 73 62 30 36  |ces...In B/osb06|
00002080  20 74 68 65 72 65 20 61  72 65 20 61 20 63 6f 75  | there are a cou|
00002090  70 6c 65 20 6f 66 20 70  6c 61 63 65 73 20 77 68  |ple of places wh|
000020a0  65 72 65 20 49 20 68 61  76 65 20 75 73 65 64 0d  |ere I have used.|
000020b0  74 68 65 20 73 74 61 63  6b 20 66 6f 72 20 62 72  |the stack for br|
000020c0  69 65 66 20 73 74 6f 72  61 67 65 2c 20 6c 69 6e  |ief storage, lin|
000020d0  65 73 20 35 35 30 20 2b  20 36 31 30 20 61 6e 64  |es 550 + 610 and|
000020e0  20 31 30 37 30 20 2b 0d  31 31 39 30 2e 20 20 49  | 1070 +.1190.  I|
000020f0  6e 20 74 68 65 20 66 69  72 73 74 20 69 6e 73 74  |n the first inst|
00002100  61 6e 63 65 20 49 20 73  68 6f 75 6c 64 20 72 65  |ance I should re|
00002110  61 6c 6c 79 20 6a 75 73  74 20 68 61 76 65 20 75  |ally just have u|
00002120  73 65 64 0d 27 61 63 63  75 73 74 6f 72 65 27 20  |sed.'accustore' |
00002130  73 69 6e 63 65 20 74 68  69 73 20 69 73 20 77 68  |since this is wh|
00002140  61 74 20 69 74 20 69 73  20 66 6f 72 2e 20 20 54  |at it is for.  T|
00002150  68 65 20 6c 61 74 74 65  72 20 74 68 6f 75 67 68  |he latter though|
00002160  0d 69 73 20 61 20 72 65  61 73 6f 6e 61 62 6c 65  |.is a reasonable|
00002170  20 69 6e 73 74 61 6e 63  65 20 6f 66 20 73 74 61  | instance of sta|
00002180  63 6b 20 75 73 65 20 61  73 20 61 20 74 65 6d 70  |ck use as a temp|
00002190  6f 72 61 72 79 20 73 74  6f 72 61 67 65 0d 66 6f  |orary storage.fo|
000021a0  72 20 61 6e 20 69 6e 74  65 72 69 6d 20 72 65 73  |r an interim res|
000021b0  75 6c 74 20 77 68 69 6c  65 20 74 68 65 20 63 6f  |ult while the co|
000021c0  64 65 20 63 68 65 63 6b  73 20 66 6f 72 20 7a 65  |de checks for ze|
000021d0  72 6f 73 2e 0d 0d 4c 65  74 27 73 20 6c 6f 6f 6b  |ros...Let's look|
000021e0  20 61 74 20 42 2f 6f 73  62 30 36 20 69 6e 20 6d  | at B/osb06 in m|
000021f0  6f 72 65 20 64 65 74 61  69 6c 2e 20 20 57 68 61  |ore detail.  Wha|
00002200  74 20 69 74 20 64 6f 65  73 20 69 73 20 74 61 6b  |t it does is tak|
00002210  65 0d 61 20 62 79 74 65  20 74 68 61 74 20 79 6f  |e.a byte that yo|
00002220  75 20 74 79 70 65 20 69  6e 20 62 79 20 70 72 65  |u type in by pre|
00002230  73 73 69 6e 67 20 61 20  6b 65 79 20 61 6e 64 20  |ssing a key and |
00002240  70 72 69 6e 74 20 69 74  73 0d 76 61 6c 75 65 20  |print its.value |
00002250  6f 75 74 20 69 6e 20 74  68 72 65 65 20 77 61 79  |out in three way|
00002260  73 2e 20 20 42 69 6e 61  72 79 2c 20 68 65 78 61  |s.  Binary, hexa|
00002270  64 65 63 69 6d 61 6c 20  61 6e 64 20 64 65 63 69  |decimal and deci|
00002280  6d 61 6c 2e 0d 0d 54 68  65 20 4a 53 52 20 6f 73  |mal...The JSR os|
00002290  72 64 63 68 20 61 74 20  6c 69 6e 65 20 31 39 30  |rdch at line 190|
000022a0  20 72 65 61 64 73 20 79  6f 75 72 20 6b 65 79 70  | reads your keyp|
000022b0  72 65 73 73 20 61 6e 64  20 70 75 74 73 20 69 74  |ress and puts it|
000022c0  0d 69 6e 20 74 68 65 20  61 63 63 75 6d 75 6c 61  |.in the accumula|
000022d0  74 6f 72 2e 20 20 28 49  27 6c 6c 20 62 65 20 64  |tor.  (I'll be d|
000022e0  65 61 6c 69 6e 67 20 77  69 74 68 20 73 6f 6d 65  |ealing with some|
000022f0  20 6d 6f 72 65 20 4f 53  0d 72 6f 75 74 69 6e 65  | more OS.routine|
00002300  73 20 6e 65 78 74 20 77  65 65 6b 29 2e 20 20 49  |s next week).  I|
00002310  74 20 69 73 20 74 68 65  6e 20 70 75 74 20 69 6e  |t is then put in|
00002320  74 6f 20 74 68 65 20 27  61 63 63 75 73 74 6f 72  |to the 'accustor|
00002330  65 27 0d 66 6f 72 20 74  68 65 20 64 75 72 61 74  |e'.for the durat|
00002340  69 6f 6e 20 6f 66 20 74  68 65 20 72 6f 75 74 69  |ion of the routi|
00002350  6e 65 2e 0d 0d 4e 6f 77  20 73 69 6e 63 65 20 49  |ne...Now since I|
00002360  20 77 61 6e 74 65 64 20  74 68 69 73 20 63 6f 64  | wanted this cod|
00002370  65 20 74 6f 20 62 65 20  73 65 6c 66 2d 63 6f 6e  |e to be self-con|
00002380  74 61 69 6e 65 64 20 61  6e 64 20 6e 6f 74 0d 72  |tained and not.r|
00002390  65 74 75 72 6e 20 74 6f  20 42 41 53 49 43 20 61  |eturn to BASIC a|
000023a0  66 74 65 72 20 65 61 63  68 20 6b 65 79 20 70 72  |fter each key pr|
000023b0  65 73 73 20 49 20 68 61  64 20 74 6f 20 70 75 74  |ess I had to put|
000023c0  20 69 6e 20 73 6f 6d 65  0d 77 61 79 20 6f 66 20  | in some.way of |
000023d0  65 78 69 74 69 6e 67 2e  20 20 41 6e 79 20 6b 65  |exiting.  Any ke|
000023e0  79 20 76 61 6c 75 65 20  77 6f 75 6c 64 20 64 6f  |y value would do|
000023f0  20 62 75 74 20 45 53 43  41 50 45 20 73 65 65 6d  | but ESCAPE seem|
00002400  65 64 0d 6d 6f 73 74 20  61 70 70 72 6f 70 72 69  |ed.most appropri|
00002410  61 74 65 2c 20 61 6c 74  68 6f 75 67 68 20 79 6f  |ate, although yo|
00002420  75 20 68 61 76 65 20 74  6f 20 63 61 72 72 79 20  |u have to carry |
00002430  6f 75 74 20 61 6e 20 65  73 63 61 70 65 0d 69 6e  |out an escape.in|
00002440  20 61 6e 20 6f 72 64 65  72 6c 79 20 6d 61 6e 6e  | an orderly mann|
00002450  65 72 2e 20 20 53 6f 20  61 74 20 6c 69 6e 65 20  |er.  So at line |
00002460  32 32 30 20 74 68 65 20  63 6f 64 65 20 63 68 65  |220 the code che|
00002470  63 6b 73 20 66 6f 72 20  61 6e 0d 65 73 63 61 70  |cks for an.escap|
00002480  65 20 61 6e 64 20 69 66  20 69 74 20 64 65 74 65  |e and if it dete|
00002490  63 74 73 20 6f 6e 65 2c  20 62 79 20 41 20 62 65  |cts one, by A be|
000024a0  69 6e 67 20 73 65 74 20  74 6f 20 32 37 2c 20 4f  |ing set to 27, O|
000024b0  53 42 59 54 45 0d 31 32  36 20 69 73 20 63 61 6c  |SBYTE.126 is cal|
000024c0  6c 65 64 20 77 68 69 63  68 20 63 61 72 72 69 65  |led which carrie|
000024d0  73 20 6f 75 74 20 68 6f  75 73 65 6b 65 65 70 69  |s out housekeepi|
000024e0  6e 67 20 74 6f 20 61 63  6b 6e 6f 77 6c 65 64 67  |ng to acknowledg|
000024f0  65 0d 61 6e 20 45 53 43  41 50 45 20 61 66 74 65  |e.an ESCAPE afte|
00002500  72 20 77 68 69 63 68 20  77 65 20 72 65 74 75 72  |r which we retur|
00002510  6e 20 74 6f 20 42 41 53  49 43 2e 20 20 42 65 63  |n to BASIC.  Bec|
00002520  61 75 73 65 20 74 68 65  0d 45 53 43 41 50 45 20  |ause the.ESCAPE |
00002530  68 61 73 20 62 65 65 6e  20 61 63 6b 6e 6f 77 6c  |has been acknowl|
00002540  65 64 67 65 64 20 79 6f  75 20 72 65 74 75 72 6e  |edged you return|
00002550  20 74 6f 20 42 41 53 49  43 20 77 69 74 68 6f 75  | to BASIC withou|
00002560  74 20 61 6e 0d 65 72 72  6f 72 20 63 6f 6e 64 69  |t an.error condi|
00002570  74 69 6f 6e 20 61 6e 64  20 73 6f 20 74 68 65 72  |tion and so ther|
00002580  65 20 69 73 20 6e 6f 20  70 72 69 6e 74 69 6e 67  |e is no printing|
00002590  20 6f 66 20 45 53 43 41  50 45 2e 20 20 59 6f 75  | of ESCAPE.  You|
000025a0  0d 63 6f 75 6c 64 20 74  72 79 20 6d 69 73 73 69  |.could try missi|
000025b0  6e 67 20 6f 75 74 20 74  68 65 20 74 72 61 70 20  |ng out the trap |
000025c0  66 6f 72 20 32 37 2c 20  6f 72 20 6f 6d 69 74 20  |for 27, or omit |
000025d0  74 68 65 0d 61 63 6b 6e  6f 77 6c 65 64 67 65 6d  |the.acknowledgem|
000025e0  65 6e 74 20 61 6e 64 20  63 6f 6d 70 61 72 65 20  |ent and compare |
000025f0  74 68 65 20 72 65 73 75  6c 74 73 2e 0d 0d 5b 49  |the results...[I|
00002600  74 20 69 73 20 70 6f 73  73 69 62 6c 65 20 74 6f  |t is possible to|
00002610  20 74 72 69 67 67 65 72  20 61 6e 20 45 53 43 41  | trigger an ESCA|
00002620  50 45 20 66 72 6f 6d 20  61 6e 6f 74 68 65 72 20  |PE from another |
00002630  41 53 43 49 49 20 63 6f  64 65 0d 74 68 61 6e 20  |ASCII code.than |
00002640  32 37 2c 20 61 6c 74 68  6f 75 67 68 20 32 37 20  |27, although 27 |
00002650  69 73 20 74 68 65 20 73  74 61 6e 64 61 72 64 2e  |is the standard.|
00002660  20 20 4f 53 42 59 54 45  20 32 32 30 20 77 69 6c  |  OSBYTE 220 wil|
00002670  6c 20 64 6f 0d 74 68 69  73 2e 20 20 59 6f 75 20  |l do.this.  You |
00002680  6d 69 67 68 74 20 64 6f  20 74 68 69 73 20 74 6f  |might do this to|
00002690  20 65 6e 61 62 6c 65 20  61 20 64 65 76 69 63 65  | enable a device|
000026a0  20 74 6f 20 67 65 6e 65  72 61 74 65 0d 45 53 43  | to generate.ESC|
000026b0  41 50 45 27 73 20 64 6f  77 6e 20 74 68 65 20 52  |APE's down the R|
000026c0  53 34 32 33 2e 5d 0d 0d  49 66 20 74 68 65 20 6b  |S423.]..If the k|
000026d0  65 79 20 70 72 65 73 73  65 64 20 69 73 20 6e 6f  |ey pressed is no|
000026e0  74 20 45 53 43 41 50 45  20 74 68 65 6e 20 74 68  |t ESCAPE then th|
000026f0  65 20 74 68 72 65 65 20  73 65 63 74 69 6f 6e 73  |e three sections|
00002700  20 6f 66 0d 74 68 65 20  70 72 6f 67 72 61 6d 20  | of.the program |
00002710  61 72 65 20 65 78 65 63  75 74 65 64 2e 20 20 4e  |are executed.  N|
00002720  6f 74 69 63 65 20 74 68  61 74 20 74 68 72 65 65  |otice that three|
00002730  20 6c 6f 63 61 74 69 6f  6e 73 20 66 6f 72 0d 76  | locations for.v|
00002740  61 72 69 61 62 6c 65 73  20 68 61 76 65 20 62 65  |ariables have be|
00002750  65 6e 20 73 65 74 20 61  74 20 6c 69 6e 65 73 20  |en set at lines |
00002760  32 39 30 2d 33 31 30 20  75 73 69 6e 67 20 74 68  |290-310 using th|
00002770  65 20 42 52 4b 20 73 68  6f 72 74 0d 63 75 74 20  |e BRK short.cut |
00002780  49 20 6d 65 6e 74 69 6f  6e 65 64 20 65 61 72 6c  |I mentioned earl|
00002790  69 65 72 2e 0d 0d 54 68  65 20 66 69 72 73 74 20  |ier...The first |
000027a0  73 65 63 74 69 6f 6e 20  70 72 69 6e 74 73 20 6f  |section prints o|
000027b0  75 74 20 62 69 6e 61 72  79 20 61 6e 64 20 69 74  |ut binary and it|
000027c0  20 64 6f 65 73 20 74 68  69 73 20 62 79 0d 72 6f  | does this by.ro|
000027d0  74 61 74 69 6e 67 20 74  68 65 20 62 79 74 65 20  |tating the byte |
000027e0  65 69 67 68 74 20 74 69  6d 65 73 2c 20 65 61 63  |eight times, eac|
000027f0  68 20 74 69 6d 65 20 6c  6f 6f 6b 69 6e 67 20 61  |h time looking a|
00002800  74 20 74 68 65 0d 63 61  72 72 79 20 66 6c 61 67  |t the.carry flag|
00002810  20 61 6e 64 20 70 72 69  6e 74 69 6e 67 20 61 20  | and printing a |
00002820  31 20 6f 72 20 30 20 61  63 63 6f 72 64 69 6e 67  |1 or 0 according|
00002830  6c 79 2e 20 20 54 68 65  20 6c 6f 6f 70 20 74 68  |ly.  The loop th|
00002840  61 74 0d 64 6f 65 73 20  74 68 65 20 77 6f 72 6b  |at.does the work|
00002850  20 69 73 20 62 65 74 77  65 65 6e 20 34 30 30 20  | is between 400 |
00002860  61 6e 64 20 34 36 30 20  61 6e 64 20 75 73 65 73  |and 460 and uses|
00002870  20 74 68 65 20 58 20 72  65 67 69 73 74 65 72 0d  | the X register.|
00002880  61 73 20 61 20 63 6f 75  6e 74 65 72 2e 20 20 53  |as a counter.  S|
00002890  69 6e 63 65 20 69 74 20  69 73 20 74 68 65 20 43  |ince it is the C|
000028a0  61 72 72 79 20 66 6c 61  67 20 74 68 61 74 20 69  |arry flag that i|
000028b0  73 20 62 65 69 6e 67 20  75 73 65 64 0d 77 65 20  |s being used.we |
000028c0  63 61 6e 20 6d 61 6b 65  20 75 73 65 20 6f 66 20  |can make use of |
000028d0  74 68 65 20 41 44 43 20  69 6e 73 74 72 75 63 74  |the ADC instruct|
000028e0  69 6f 6e 20 74 6f 20 61  64 64 2c 20 77 69 74 68  |ion to add, with|
000028f0  20 63 61 72 72 79 2c 20  30 0d 74 6f 20 74 68 65  | carry, 0.to the|
00002900  20 41 53 43 49 49 20 76  61 6c 75 65 20 6f 66 20  | ASCII value of |
00002910  30 2e 0d 0d 48 65 78 61  64 65 63 69 6d 61 6c 20  |0...Hexadecimal |
00002920  70 72 69 6e 74 69 6e 67  20 69 73 20 6d 6f 72 65  |printing is more|
00002930  20 64 69 66 66 69 63 75  6c 74 2e 20 20 46 69 72  | difficult.  Fir|
00002940  73 74 20 77 65 20 73 65  70 61 72 61 74 65 0d 74  |st we separate.t|
00002950  68 65 20 74 6f 70 20 6e  79 62 62 6c 65 20 6f 66  |he top nybble of|
00002960  20 74 68 65 20 62 79 74  65 20 28 74 68 65 20 74  | the byte (the t|
00002970  6f 70 20 34 20 62 69 74  73 29 20 62 79 20 73 68  |op 4 bits) by sh|
00002980  69 66 74 69 6e 67 20 74  68 65 0d 62 79 74 65 20  |ifting the.byte |
00002990  72 69 67 68 74 20 66 6f  75 72 20 74 69 6d 65 73  |right four times|
000029a0  2e 20 20 54 68 69 73 20  6e 79 62 62 6c 65 20 6d  |.  This nybble m|
000029b0  75 73 74 20 74 68 65 6e  20 68 6f 6c 64 20 61 20  |ust then hold a |
000029c0  76 61 6c 75 65 0d 62 65  74 77 65 65 6e 20 30 20  |value.between 0 |
000029d0  61 6e 64 20 31 35 2c 20  6f 72 20 30 20 61 6e 64  |and 15, or 0 and|
000029e0  20 46 20 69 6e 20 68 65  78 2e 20 20 41 20 6c 69  | F in hex.  A li|
000029f0  74 74 6c 65 20 74 72 69  63 6b 20 77 69 74 68 0d  |ttle trick with.|
00002a00  62 69 6e 61 72 79 20 63  6f 64 65 64 20 64 65 63  |binary coded dec|
00002a10  69 6d 61 6c 20 69 73 20  6f 66 20 68 65 6c 70 20  |imal is of help |
00002a20  68 65 72 65 2e 0d 0d 49  6e 20 62 69 6e 61 72 79  |here...In binary|
00002a30  20 63 6f 64 65 64 20 64  65 63 69 6d 61 6c 20 74  | coded decimal t|
00002a40  68 65 20 66 6f 75 72 20  62 69 74 73 20 6f 66 20  |he four bits of |
00002a50  61 20 6e 79 62 62 6c 65  20 63 61 6e 20 6f 6e 6c  |a nybble can onl|
00002a60  79 0d 65 76 65 72 20 68  6f 6c 64 20 62 65 74 77  |y.ever hold betw|
00002a70  65 65 6e 20 30 20 61 6e  64 20 39 2c 20 74 68 65  |een 0 and 9, the|
00002a80  20 6f 74 68 65 72 20 6e  75 6d 62 65 72 73 20 6a  | other numbers j|
00002a90  75 73 74 20 64 6f 6e 27  74 0d 65 78 69 73 74 20  |ust don't.exist |
00002aa0  61 6e 64 20 69 66 20 79  6f 75 20 61 64 64 20 31  |and if you add 1|
00002ab0  20 74 6f 20 39 20 79 6f  75 20 67 65 74 20 31 30  | to 9 you get 10|
00002ac0  20 61 6e 64 20 6e 6f 74  20 41 20 61 73 20 79 6f  | and not A as yo|
00002ad0  75 0d 77 6f 75 6c 64 20  6e 6f 72 6d 61 6c 6c 79  |u.would normally|
00002ae0  2e 20 20 54 6f 20 74 65  6c 6c 20 74 68 65 20 70  |.  To tell the p|
00002af0  72 6f 63 65 73 73 6f 72  20 79 6f 75 20 61 72 65  |rocessor you are|
00002b00  20 77 6f 72 6b 69 6e 67  20 69 6e 0d 42 43 44 20  | working in.BCD |
00002b10  79 6f 75 20 73 65 74 20  74 68 65 20 64 65 63 69  |you set the deci|
00002b20  6d 61 6c 20 66 6c 61 67  20 77 69 74 68 20 61 6e  |mal flag with an|
00002b30  20 53 45 44 20 28 6c 69  6e 65 20 37 31 30 29 2e  | SED (line 710).|
00002b40  0d 0d 49 66 20 74 68 65  20 61 63 63 75 6d 75 6c  |..If the accumul|
00002b50  61 74 6f 72 20 63 6f 6e  74 61 69 6e 73 20 79 6f  |ator contains yo|
00002b60  75 72 20 6e 79 62 62 6c  65 20 74 68 65 6e 20 61  |ur nybble then a|
00002b70  64 64 69 6e 67 20 39 30  20 74 6f 20 69 74 0d 69  |dding 90 to it.i|
00002b80  6e 20 42 43 44 20 6d 6f  64 65 20 67 69 76 65 73  |n BCD mode gives|
00002b90  20 79 6f 75 20 61 20 6e  75 6d 62 65 72 20 69 6e  | you a number in|
00002ba0  20 74 68 65 20 72 61 6e  67 65 20 39 30 20 74 6f  | the range 90 to|
00002bb0  20 39 39 20 28 43 61 72  72 79 0d 63 6c 65 61 72  | 99 (Carry.clear|
00002bc0  29 20 69 66 20 79 6f 75  20 68 61 64 20 30 20 74  |) if you had 0 t|
00002bd0  6f 20 39 20 69 6e 20 74  68 65 72 65 20 61 6e 64  |o 9 in there and|
00002be0  20 30 20 74 6f 20 35 20  28 43 61 72 72 79 20 73  | 0 to 5 (Carry s|
00002bf0  65 74 29 20 69 66 0d 79  6f 75 20 68 61 64 20 31  |et) if.you had 1|
00002c00  30 20 74 6f 20 31 35 20  69 6e 20 74 68 65 72 65  |0 to 15 in there|
00002c10  2e 20 49 66 20 77 65 20  74 68 65 6e 20 61 64 64  |. If we then add|
00002c20  20 34 30 20 77 69 74 68  20 63 61 72 72 79 20 77  | 40 with carry w|
00002c30  65 0d 77 69 6c 6c 20 67  65 74 20 33 30 20 74 6f  |e.will get 30 to|
00002c40  20 33 39 20 6f 72 20 34  31 20 74 6f 20 34 36 20  | 39 or 41 to 46 |
00002c50  28 62 65 63 61 75 73 65  20 6f 66 20 74 68 65 20  |(because of the |
00002c60  43 61 72 72 79 29 2e 20  0d 52 65 74 75 72 6e 69  |Carry). .Returni|
00002c70  6e 67 20 74 6f 20 6e 6f  72 6d 61 6c 20 62 69 6e  |ng to normal bin|
00002c80  61 72 79 20 28 77 69 74  68 20 43 4c 44 29 20 74  |ary (with CLD) t|
00002c90  68 65 73 65 20 62 65 63  6f 6d 65 20 26 33 33 20  |hese become &33 |
00002ca0  74 6f 0d 26 33 39 20 6f  72 20 26 34 31 20 74 6f  |to.&39 or &41 to|
00002cb0  20 26 34 36 20 77 68 69  63 68 20 67 69 76 65 73  | &46 which gives|
00002cc0  20 75 73 20 74 68 65 20  41 53 43 49 49 20 76 61  | us the ASCII va|
00002cd0  6c 75 65 73 20 6f 66 20  30 2d 39 20 6f 72 0d 41  |lues of 0-9 or.A|
00002ce0  2d 46 2e 20 20 54 68 75  73 20 79 6f 75 20 70 72  |-F.  Thus you pr|
00002cf0  69 6e 74 20 74 68 65 20  6e 79 62 62 6c 65 20 76  |int the nybble v|
00002d00  61 6c 75 65 2e 0d 0d 52  65 67 72 61 62 62 69 6e  |alue...Regrabbin|
00002d10  67 20 74 68 65 20 6f 72  69 67 69 6e 61 6c 20 62  |g the original b|
00002d20  79 74 65 20 77 65 20 74  68 65 6e 20 6c 6f 6f 6b  |yte we then look|
00002d30  20 61 74 20 74 68 65 20  6c 6f 77 65 72 0d 6e 79  | at the lower.ny|
00002d40  62 62 6c 65 20 62 79 20  41 4e 44 69 6e 67 20 77  |bble by ANDing w|
00002d50  69 74 68 20 26 46 20 77  68 69 63 68 20 28 6d 6f  |ith &F which (mo|
00002d60  72 65 20 64 65 74 61 69  6c 73 20 69 6e 20 61 20  |re details in a |
00002d70  77 65 65 6b 20 6f 72 0d  73 6f 29 20 77 69 70 65  |week or.so) wipe|
00002d80  73 20 74 68 65 20 74 6f  70 20 66 6f 75 72 20 62  |s the top four b|
00002d90  69 74 73 2e 20 20 54 68  65 20 6e 79 62 62 6c 65  |its.  The nybble|
00002da0  20 70 72 69 6e 74 69 6e  67 20 72 6f 75 74 69 6e  | printing routin|
00002db0  65 20 69 73 0d 74 68 65  6e 20 72 65 70 65 61 74  |e is.then repeat|
00002dc0  65 64 2e 0d 0d 44 65 63  69 6d 61 6c 20 70 72 69  |ed...Decimal pri|
00002dd0  6e 74 69 6e 67 20 69 73  20 6d 6f 72 65 20 64 69  |nting is more di|
00002de0  66 66 69 63 75 6c 74 20  73 74 69 6c 6c 2c 20 61  |fficult still, a|
00002df0  6e 64 20 49 20 64 6f 6e  27 74 20 6b 6e 6f 77 20  |nd I don't know |
00002e00  61 0d 73 68 6f 72 74 2d  63 75 74 2e 20 20 4f 6e  |a.short-cut.  On|
00002e10  65 20 65 78 74 72 61 20  63 6f 6d 70 6c 69 63 61  |e extra complica|
00002e20  74 69 6f 6e 20 49 20 68  61 76 65 20 69 6e 74 72  |tion I have intr|
00002e30  6f 64 75 63 65 64 20 69  73 20 74 68 61 74 0d 69  |oduced is that.i|
00002e40  6e 20 74 68 69 73 20 63  61 73 65 20 77 65 20 64  |n this case we d|
00002e50  6f 6e 27 74 20 70 72 69  6e 74 20 6c 65 61 64 69  |on't print leadi|
00002e60  6e 67 20 7a 65 72 6f 73  2c 20 65 78 63 65 70 74  |ng zeros, except|
00002e70  20 66 6f 72 20 74 68 65  0d 66 69 6e 61 6c 20 66  | for the.final f|
00002e80  69 67 75 72 65 2e 20 20  49 6e 20 74 68 69 73 20  |igure.  In this |
00002e90  63 61 73 65 20 49 20 68  61 76 65 20 61 20 73 75  |case I have a su|
00002ea0  62 72 6f 75 74 69 6e 65  20 63 61 6c 6c 65 64 0d  |broutine called.|
00002eb0  27 64 69 67 69 74 27 20  77 68 69 63 68 20 74 61  |'digit' which ta|
00002ec0  6b 65 73 20 74 68 65 20  76 61 6c 75 65 20 69 6e  |kes the value in|
00002ed0  20 74 68 65 20 61 63 63  75 6d 75 6c 61 74 6f 72  | the accumulator|
00002ee0  20 61 6e 64 20 70 72 69  6e 74 73 0d 6f 75 74 20  | and prints.out |
00002ef0  74 68 65 20 6e 75 6d 62  65 72 20 6f 66 20 74 69  |the number of ti|
00002f00  6d 65 73 20 74 68 65 20  6e 75 6d 62 65 72 20 69  |mes the number i|
00002f10  6e 20 74 68 65 20 59 20  72 65 67 69 73 74 65 72  |n the Y register|
00002f20  20 77 69 6c 6c 20 67 6f  0d 69 6e 74 6f 20 69 74  | will go.into it|
00002f30  2e 20 20 54 68 69 73 20  69 73 20 66 6f 75 6e 64  |.  This is found|
00002f40  20 6f 75 74 20 62 79 20  72 65 70 65 61 74 65 64  | out by repeated|
00002f50  20 73 75 62 74 72 61 63  74 69 6f 6e 2e 0d 0d 49  | subtraction...I|
00002f60  6e 20 61 6c 6c 20 63 61  73 65 73 20 68 65 72 65  |n all cases here|
00002f70  20 77 65 20 61 72 65 20  64 65 61 6c 69 6e 67 20  | we are dealing |
00002f80  6f 6e 6c 79 20 77 69 74  68 20 62 79 74 65 20 73  |only with byte s|
00002f90  69 7a 65 64 0d 6e 75 6d  62 65 72 73 2e 20 20 49  |ized.numbers.  I|
00002fa0  6e 20 66 61 63 74 20 74  68 65 20 66 69 72 73 74  |n fact the first|
00002fb0  20 74 77 6f 20 72 6f 75  74 69 6e 65 73 20 77 69  | two routines wi|
00002fc0  6c 6c 20 61 64 61 70 74  20 65 61 73 69 6c 79 0d  |ll adapt easily.|
00002fd0  74 6f 20 61 6e 79 20 73  69 7a 65 20 6f 66 20 6e  |to any size of n|
00002fe0  75 6d 62 65 72 20 62 75  74 20 74 68 61 74 20 69  |umber but that i|
00002ff0  73 20 6e 6f 74 20 73 6f  20 74 72 75 65 20 6f 66  |s not so true of|
00003000  20 74 68 65 20 64 65 63  69 6d 61 6c 0d 6f 6e 65  | the decimal.one|
00003010  2e 0d 0d 4e 65 78 74 20  77 65 65 6b 20 73 6f 6d  |...Next week som|
00003020  65 20 6d 6f 72 65 20 4f  53 20 63 61 6c 6c 73 20  |e more OS calls |
00003030  61 6e 64 20 49 27 6c 6c  20 73 68 6f 77 20 79 6f  |and I'll show yo|
00003040  75 20 68 6f 77 20 74 6f  20 75 73 65 20 61 0d 6c  |u how to use a.l|
00003050  6f 6f 6b 2d 75 70 20 74  61 62 6c 65 20 61 6e 64  |ook-up table and|
00003060  20 69 6e 64 65 78 65 64  20 61 64 64 72 65 73 73  | indexed address|
00003070  69 6e 67 20 74 6f 20 70  72 6f 76 69 64 65 20 70  |ing to provide p|
00003080  72 6f 70 6f 72 74 69 6f  6e 61 6c 0d 73 70 61 63  |roportional.spac|
00003090  69 6e 67 2e 0d                                    |ing..|
00003095
27_11_87/T\OSB06.m0
27_11_87/T\OSB06.m1
27_11_87/T\OSB06.m2
27_11_87/T\OSB06.m4
27_11_87/T\OSB06.m5