Turning on the RUN switch starts the clock and puts a high
of
events
that
sequence
cau"ses a TPA
responds by performing a
state code
not
normally occur at this time) and
case,
the
high, the cycle immediately
signal
line (SCI) indicates
DMA
cycle does nothing more than take COSMAC
initiates program execution when the RUN switch
each
machine cycle. The
DMA
cycle (S2), which
that
COSMAC
causes
following
the
DMA
22M
20PF
-=
_____ ~ ________
low
on the
is
described in the section on
is
executing the
the
flip-flop
cycle
will
------1
COS
MAC
I
1
I
I
1
CLOCK
P
120
F
on
the
CLEAR
DMA-OUT
DMA
holding the
out
of
be
a normal instruction fetch operation (SO).
line
cycle (or
DMA-OUT
the
IDLE
1
---1
92CM-26473
line. Fig.
is
is
detected
I/O
interrupt
line
state. Since the
44
turned on. The clock
by
interface. A
cycle, which
low
to
be
COSMAC_
~In
shows the
low
on the
would
LOAD
line
It
this
is
OFF
RUN SWITCH
CLEAR
(LOWI
_____
CLOCK
TPA
DMA-OUT
w..
---'
I----IDLE
ON
L..J
I
,I
I
CYCLE
(SII----1.~I
Fig.
44
-
START
..
o__-
timing.
DMA-OUT
CYCLE
L
~
(S21--1
92CM-26471
COSMAC Microprocessor
The
previous low
be
incremented
that
program
program
eliminated
tact
manual switches.
The
above
switches
execution
by
on
by 1.
The
execution
continues
example
having a
could
be used. Program
Other
represents
the
CLEAR
first
instruction
normally
until an IDLE
program
oscillators
line has
will,
begins
at
one
method
permanently
execution
could
be used
set
P=O
and
therefore,
M(0001)
instruction
of
initiating
stored
could
for
clock
R(O)=OOOO.
be
with
occurs
in
ROM.
also
generation.
fetched
R(O) as
or
the
system
Separate
be
initiated
The
DMA
from
M(0001)
the
program
RUN
switch
operation.
CLEAR
by
another
cycle
The
and
(S2)
and
counter.
is
turned
load
RUN
computer
caused
not
M(OOOO).
After
off.
operation
momentary
instead
37
R(O)
to
Note
initiation,
could
be
con-
of
by
38
I/O Interface
39
Programmed
The
following
under
program
Control
device
bus.
The
the
used
Interface.
or
to
gate
Data
output.
The
SCO line goes low
M(R(X))
bus until
to
set a byte
I/O
paragraphs
control.
can also be used
data
from
When 1=6
byte
will
after
the
TPB line
i ntQ a
SCO
COSMAC
TPB
indicate a few
It
should
be
an
I/O
device
and
N=O,l
and
the
appear
on
the
returns
two-hex-digit
N3
(HIGH'OUTPUT
SC
I
U
of
the
noted
that
the
in
conjunction
onto
the
bus.
,2,3,4,5,6,
or
SCI line goes high
data
bus
before
to
its high
state.
output
display
DURING
INPUT/OUTPUT
NOTE:
S
CO
' H ,
SC
INDICATES
EXECUTION
ways
MREAD
with
Sl"
7,
the
memory
to
indicate
the
Fig.
device.
4049
I ' L
AN
I~6
CYCLE
4049
in
which
I/O
data
signal, discussed in
(1=6)
to
transfer
byte
addressed
that
an
I/O
timing
pulse B (TPB)
45
shows
how
EXECUTION)
STROBE
01
5082-
7340
HIGH-ORDER
DIGIT
transfer
the
data
instruction
occurs,
the
output
BUS--DISPLAY
Lf
section
from
by
DO
5082-
7340
can
be
on
the
bus
R(X)
is
cycle
and
will
instruction
LOW-ORDER
DIGIT
accomplished
Memory
into
placed
is
and
an I/O
on
the
performed.
remain
on
might
be
Each
HP5082-7340
gate
causes
and
SCI
to
be
NO-3
indicate
set
are
only
high
the
when
when
byte
that
display
from
an
input/output
the
high-order
the
corresponding
Fig.
chip
memory
45
- Simple
contains a 4-bit
to
be
instruction
bit
of
the
strobed
is
N register
output
register,
into
being
the
executed.
equals
internal N-register bits equal
display logic.
decoder,
2-digit
hex
The
"0".
Note
"0".
92CS-26474
and
hex
display
N3
that
In
gate
Fig.
LED
display. A four-input
during
input
the
45,
four
any
TPB
permits
N-register
of
when
SCO
the
display
bit
lines
the 8 output
40
User Manual
for
the
instructions
display
different
signal. This
60, 62,
flag lines
structions
Fig.
switch
Each
stop
with
value
is
the
If
more
than
output
change
63,
64,
Data
input.
(EF1,
34,
46
illustrates
Turning
If
on
bounce.)
two-digit
the
counter.
the
switch
the
current
displayed. A portion
can be used
only
output
one
output
devices
would
65, 66,
The
simplest
EF2, EF3,
35,36,37,
one
method
COSMAC
the
switch
A COSMAC
count
can
is
in
the
value
to
and
of
transfer
device
in
device
or
channels.
permit
67
could
form
or
EF4). A Iowan
3C,
3D,
of
using a flag line
Fig.
sets
EFl
program
be
placed
"ON"
position,
the
count
of
a possible
the
the
system.
is
The
the
display
then
of
input
3E,
46
-
low.
can be
in
the
displayed.
M(R(X))
required,
N3 gate
to
designate
to
the
and
3F
Use
of
Turning
written
output
counting
"counter
byte
to
the
output
NO
through
input
be
set
other
COSMAC
a flag line places it
allow
programs
(EFl
in
4011
a flag
time
off
the
to
display
proceeds
Another
program"
N2 can be
of
Fig.
when
1=6
devices
microprocessor
this
case) as a
(EFT)
switch
simulate a free-running
of
Fig.
(00-99).
closure
is
shown
display.
45
might
and
or
to
determine
92C5-26478
as
an
sets
45.
will
initiate
below.
This logic
decoded
be
replaced
N=l
(a
61
channels
in
its
binary
NOTE:
input.
EFl
The
When it
to
utilizes
"true"
the
input.
FF
SET
high. (The flip-flop
switch
is
counting
is
suitable
to
specify
by a decoded.
instruction).
receive
one
of
state.
The
states
of
IRESET ~ LOW
two-digit
in
Fig.
turned
off,
again,
up
Instructions
the
output
the
four
BRANCH
these
decimal
46
will
counting
started
if
the
hex
to
eight
N=l
byte.
external
in-
flag lines.
eliminates
counter.
start
and
stops
at
the
M
The
switch
relay
contact
sequential
address
0018
I
I
I
I
I
I
I
I
states
of
Fig_
represent
of
the
46
M
the
EFl
byte
3C
18
I
I
I
I
I
I
61
30
18
might
bit-serial
line
operation
I
Initialize registers
and
•
I
BNl
I
I
I
I
Code
count
I
I
Output
BR
be
replaced
Teletype
to
provide
display
to
perform
function
1
by a Teletype®
character
an
extremely
code.
simple
comments
Loop
here
switch
"ON"
i.e.,
EFl
Output
Branch
output
the
to
relay.
A COSMAC
bit-serial
until
goes low.
counter
M(0018).
The
program
interface.
byte
opening
to
display.
and
could
closing
interpret
of
this
the
COSMAC
are
Microprocessor
Fig.
47
first set
places a low
program
branches
illustrates
to
represent
on
the
to
the
use
a desired
EFl
line.
an INPUT
of
the
input
The
instruction
INPUT
byte
program
instruction
(l=low,
monitors
(1=6
and
in
conjunction
O=high).
the
status
N3=1).
"1"
,-----0
-.L
"SW --BUS"
with
Momentarily
of
this
line. When a low
8 INPUT
~WITeHES
eON T ROL ION H)
a flag line. Eight
pressing
the
ENTER
input
switch
is
detected,
2
4066
41
switches
then
the
SCO
in a low
performed.
gate
gates.
Ouringthiscycle
in
Fig.
The
EFl
47
sion. This logic
If
more
than
different
permit
and
type
input
consistent
that
code
used
6F
The
of
device.
an
The
lines,
to
input
the
byte
could
eight
input
input
with
output
preceding
the
implement
COSMAC
transfers
line
is
suitable
devices.
to
then
device.
The
the
byte
two
TPA
u
EFI
state
and
is
forced
only
one
input
The
be
entered
designate
switches
The
program
input
transfer
examples
timing
more
sophisticated
4069
SCl
in
the
data
the
state
of
high
at
if
the
single set
device
N3 signal can be
when
other
devices
might
be replaced by
ENTER
must
sample
byte
transfer
is
required.
have
illustrated
lines,
and
n
Fig.
47
a high
byte
the
TPA
is
required,
1=6
switch
the
the
data
I/O
- Simple
state
is
stored
eight
to
assure
of
eight
replaced
and
N=9
or
channels
would
flag line
rate.
Output
the
bus
systems.
14------1Q
indicate
in
input
that
switches
NO
(a
the
byte
then
byte
input
that
the
memory
switches
only
through
by a decoded
69
instruction).
to
enter
output
be
replaced
and
execute
S
14-4>----D
R~~~Lw:c---'
logic.
an
input/output
location
to
the
one
byte
is
the
only
N2 can be
data.
of a paper-tape
by a strobing
input
bus
is
N=9 signal.
Instructions
devices can also utilize flag lines
use
of
the
four
flag lines,
for
simple
I/O
operations.
Fig.
48
shows
one
such
ENTER
92CM -264
addressed
through
entered
input
decoded
byte
transfer
the
These I/O
system.
Vee
79
byte
transfer
by
R(X).
eight
4066
per
ENTER
device in
to
This
68,
reader,
the
specify
arrangement
6A,
keyboard,
signal
instructions
to
4-bit N code,
interface
cycle
is
being
The
3-input
transmission
switch
depres·
system.
up
to
eight
would
68,
6C,
60,
or
other
generated
at
by
speeds
signal COSMAC
the
two
state
lines
can
6E,
the
be
The
N digit
control
signals.
select register.
provided
One
The
outputs
of
by
these
of
I/O devices.
A
60
instruction
quent
execution
is
of a 61
executed
instruction
the
input/output
signals
this
register
to
place an
will
(N=O
send
in
are
8-bit
an
instruction
this
example)
decoded
device
8-bit
to
selection
control
(on NO-3)
strobes
provide
code
code
to
is
decoded
an
output
selection
in
the
the
selected
to
byte
into
signals
for
I/O device
device
provide
an
up
to
select
or
channel.
16
8-bit
I/O
256
register.
separate
device
individual
Subse-
Control
42
1---~.2!.N£O.:.-3~_~
COS
MAC
SCO
TPB
codes
can
the
8-bit
output
data
executed
byte
from a selected
trol
other
be used
I/O device
to
system
byte
store
to
transfer
an
functions,
register.
flag line can be
A
would
be
gated
to
the
The
above
examples
I/O
interface
line can be used
4
TO
DECODE
start
or
select
register specifies an
to
input
byte
device.
either
shared
between
flag bus
indicate
in a great
N ~ F:
N~
E:
16
N~
N~I:TRANFER
N
=O:SELECT
Fig.
stop
electromechanical
selected
Instructions
only
device.
in
memory.
directly
several
when
only a few
variety
STORE DATA BYTE FROM
SELECTED
STORE STATUS BYTE FROM
SELECTED
2:
TRANSFER
SELECTED
SELECTED DEVICE
STROBE
48
DEVICE
DEVICE
DATA
BYTE
DEVICE
CONTROL
DEVIC E
8-BIT
DEV ICE
REGISTER
- Two-level I/O system.
devices,
output
After
Execution
an
device,
input
of a 6E
63,64,65,66,67,68,
(ignoring device
I/O
devices by
that
device
is
selected.
of
the
ways
in
of
ways,limited
TO
BYTE TO
I/O
SELECT
set
up
execution
device
selection)
treating
which
only
specific
is
selected, a 6F
instruction
6A,
6B, 6C,
or
it
as a bus.
I/O
instructions
by
the
ingenuity
92CM-26475
modes
of
of a 62
under
is
and
used
control
instruction
60
Individual device
can
of
User Manual
SELECT
DEVICE
SELECT
DEVICE
SELECT
DEVICE
SELECT
DEVICE No I
operations,
instruction
to
obtain a status code
could
of
will
be used
the
device
etc.
cause
could
to
conditions
be
implemented.
the
system
designer.
for
No256
No.255
No.2
When
con-
select
The
the
an
be
DMA
Operation
The
I/O
examples
techniques
to
have I/O
possible
transfer
also
byte
with
programmed
operations
During DMA
purposes.
memory.
Two
Also, a specific
described
require
several
transfers
independent
operation,
lines, DMA-IN
code
occur
I/O. A built-in
R(O)
above
require
instruction
without
of
normal
is
used as
and
DMA-OUT, are used
is
provided
DMA-IN ACTION
that a program
executions
burdening
for
each
the
program
direct-memory-access
program
the
execution.
memory
address register
to
on
the
state
code
lines (SCO, SC1)
periodically
I/O
byte
or
(DMA)
request
BUS
DMA-OUT ACTION M(R(O))
sample
transfer.
to
transfer
facility
and
DMA
.....
M(R(O));
.....
In
permits
should
byte
to
indicate
BUS;
I/O device
many
cases it
data
at
high-speed
not
transfer
a DMA
R(O)+l
R(O)+l
status.
higher
be used
to
and
cycle
is
desirable
rates
I/O
for
from
(S2).
These
than
byte
other
the
COSMAC Microprocessor
43
DMA-IN. Fig.
to
sample
the
be
the
same devices discussed
put
will
a low
state
on
49
illustrates
code
the
eOSMAe
A low DMA-IN line will
line
still
goes low
be
during
performed.
Following
DMA-I N line goes low
follow.
instruction
If
the
fetch
DMA-I N line
cycle
the
manner
to
avoid
the
state
in
conjunction
DMA-IN line instead
4069
~D~M~A~-~IN~
______________
Fig.
automatically
an
instruction
during
(SO) will be
this
an
instruction
is
reset
fetch
execute
to
performed
in
which a DMA
transition
with Fig.
of
on
a flag line.
49
-
modify
cycle
(SO)'
times
DMA
(after TPB
48.
~Q
input
the
normal
then
input
mode
In
the
logic.
fetch-execute
the
normally
might
be
implemented.
but
before
TPA).
DMA case, however, each
(ON=H)
INPUT
BYTE
2-4066
JrlL
ENTER
Vee
92CS -26480
sequences.
following
cycle (S1), a special DMA cycle (S2) will be
execute
its high
cycle (S1),
state
following
during
the
the
S2
cycle, as
then
DMA
the
DMA cycle (S2) will
~ycle
(S2)
shown
below:
The
PULSE
execute
performed.
then
the
TPA
input
device
ENTER
If
the
cycle
immediately
deferred
is
used
may
pulse
DMA-IN
(S1) will
If
the
next
DMA-IN
cycle
onto
ATES
mode
is
indicated
the
bus, as
CYCLES/ST
If
the
DMA-IN line remains low,
below. The DMA
An
S2
input
byte
addressed by R(O). R(O)
sequential
memory
however, be slowed
properly
memory
dress
use R(O)
area involved
of
the
desired first
locations. S2 cycles
down
and
to
Program Load Facility.
provides a built-in
program
S2
cycles will be
permits a maximum
DMA-IN
CYC LES/ST
by a high SCO line
shown
in Fig.
is
then
incremented
do
by
the
S2
cycles
memory
observe
input
areas in which
the
byte
location
The
DMA-I N
course
load mechanism. A low
I/O
ATES
and
49.
The
by 1 so
not
alter
that
input
of
the
in
memory
feature,
performed
byte
transfer
SO I
until
rate of
S1
a low SC1 line. This
S2
cycle
stores
that
subsequent
the
sequence
are
"stolen".
bytes
data
transfer.
before
in
conjunction
on
the
The
are
being
The
permitting
CLEAR
the
DMA-IN line goes high, as
one
byte
per
SO
S1
S2
condition
the
input
S2
of
program
concurrent
stored.
program
a DMA
with
the
line resets R
byte
cycles will
is
in
memory
execution.
program
It
may
must
also
input
LOAD
(0)
machine
S2
used
to
store
The
must,
examine
set
operation.
and
CLEAR
to
0000.
shown
cycle.
S2
I SO I S 1 I
place a DMA
at
the
location
input
bytes
program
of
course,
R(O)
and
R(O)
to
the
signals,
If
the
LOAD
in
will,
the
ad-
44
User Manual
for
the
line is.then held low,
stored
in
be
as explained
DMA-OUT. A low on
DMA-I
R(O)
TPB, as shown
memory
sequential
in
the
N line. The S2 cycle caused by a low
on
the
bus and increments R(O)
in
sequence before
COSMAC
the
DMA-In logic
memory
section
Fig. 50. The program must set R(O)
on
Memory
the
DMA-OUT line causes S2 cycles
the
DMA transfer requests occur.
of
Fig.
49
can be used
locations beginning
and
Control Interface.
on
the
by
1.
DMA
output
Ii
DMA-OUT
to
load a program
at
M(OOOO).
DMA-OUT line places
to
the
COSMAC will idle between DMA entries,
to
occur
in a similar
bytes can be
address
OUTPUT
of
the
H=
BYTE
strobed
"BUS
It
Vcc
into
the
memory
first
output
....
OUT."
REQUEST
memory.
manner
into
an
byte
output
byte
as a low
of
Bytes would
on
the
addressed by
device
by
the
desired
Interrupt
The
to
a program designed
alarm
urgent
flags.
A low
cycle, provided
andSCi'
INTERRUPT
IE
CYCLES/STATES I SO 1
Control
interrupt
conditions,
than
those
on
the
the
lines,
as
mechanism permits an external signal
initializing
handled
INTERRUPT line causes an
I E flip-flop
shown below:
to
handle
the
by
DMA
S1
Fig.
50
the
interrupt
DMA
memory
but
more urgent
is
set. Execution
'-----II
1 SO 1
S1 I S31
- DMA
interrupt
output
to
interrupt
condition. This
pointer,
of
r----
_____
SO 1
or,
than
response
an S3 cycle
S1
logic.
program
function
in
general, responding
those
which
cycle
(53)
is
indicated
_
I SO I
S1
1
92CM -26481
execution
is
useful
can be handled by sensing external
to
occur
by
for
a low
and
transfer
responding
to
real-time events less
following
on
both
to
the
the
control
next
SCO and
system
S1
COSMAC
Fig.
51
by
an
output
During
to
1, X
however,
addressed
It
saves
registers,
program
registers
RETURN,
described
Code
Programming.
Microprocessor
shows a typical
instruction.
the
S3
cycle,
to
2,
and
IE
changed P to
by R(1) will be
the
current
by
storing
will
disturb
to
their
original
DISABLE,
in
the
section
interrupt
COSMAC
the
to
O.
1, so
state
them
it.
The
states,
and
on
circuit.
TPA
Fig.
current
Following
that
executed.
of
the
COSMAC registers
in reserved
service
and
returns
SAVE
(70,71,
Instruction
The
flip-flop
51 - Typical interrupt circuit_
values
of
the X and
S3, a
normal
next
the
sequence
This
sequence
memory
program
locations.
then
control
and
78)
Repertoire;
is
P registers are
instruction
of
of
instructions
such
performs
to
execution
facilitate
their
use will be
reset
fetch
instructions
as
DF
during
Vee
92C5-26484
cycle (SO)
is
T,
D,
must
the
of
the
interrupt
the
S3
cycle,
jlREQUEST
stored
in
is
starting
called
the
and
possibly
also be saved
desired
original
functions,
program.
handling.
illustrated
but
the
T register. P
performed.
at
the
interrupt
some
if
the
Special
These
in
the
section
could
also
The
memory
service
of
the
scratch
interrupt
restores
instructions
instructions
on
be
reset
is
then
S3
cycle,
location
program.
service
the
saved
were
Machine-
45
set
pad
The
COSMAC
(IE). When IE
CLEAR
line.
automatically
line stays low.
line
with a number
When
the
program
counter
main programs
Programming.
microprocessor
is
set
to
IE
can be
set
to
"0"
The
program
of
interrupt
interrupt
and
R(2)
if
appropriate
"0",
set
to
by an
must
facility
is
normally
also provides a special
the
state
of
th!5.interrupt
"1"
or
"0"
by
S3
cycle,
preventing
set
I E
to
"1"
signal
sources
is
used
conventions
is
possible.
in a system,
used as a
pointer
are
RETURN
subsequent
to
permit
R(1)
to a storage
employed,
one-bit
line
is
and
subsequent
must
be reserved
as
described
register (flip-flop) called
ignored.
DISABLE
interrupt
interrupts.
area.
The
IE
is
set
to
instructions,
cycles even if
Sharing
for
use as
latter
may be
in
the
section
"1"
the
Interrupt
by a low
Enable
on
respectively. It
the
INTERRUPT
the
I NTE R
RUPT
interrupt
shared
on
service
with
Machine-Code
the
is
the
46
Sampte System and Program
47
Machine-Code
Programming
A simple program will illustrate
design. The demonstration system
shows a block diagram of
EFI=INPUT
Because a small memory
quires
less
than
64 bytes and could be stored
required. The switch
Fig. 47.
An
The 8-bit
8-bit
output
output
repeating sequence
be programmed
01, 02,
then
the
assume
the
to
apoear
03,
and
four low-order
states shown
sented by a single byte. in
lines at
01,
02,
03,
the
system.
MAO-7
BYTE
READY;
will
input
logic
register could be implemented
register provides 8
of
binary
output
on
the
04
represent four states for
output
at
02
the
sample program, four bytes are entered
and
04.
This sequence of states will repeat indefinitely
the
use
of
the
COSMAC instructions and provide an example
is
a programmed multiple-output sequencer, timer,
BYTE
INPUT
SWITCHES
-l....
0-
COS
MAC
68=
INPUT
BYTE-M(R(X))·,60=M(R(X))
Fig.
52
- Sample microprocessor system.
suffice for
is
used
to
output
states. Fig.
four low-order
lines will have
during the
T2
SWITCH
INPUT
LOG IC
this
application, no address latch
in
a single-chip
enter initial parameters and could
as
shown
bit lines. Each
53
shows an arbitrary sequence
output
the
lines.
the
eight
output
states shown during
time interval. The state
ENTER
OUTPUT
LOG I C
__
OUT,
ROM.
RAM
in
Fig. 50.
output
line can be programmed
lines. For example,
the
of
or
controller. Fig.
SWITC H
!-"":"':":'::..::j1Ool
R(Xl+1
8-BIT
OUTPUT
REGISTER
92CM-26477
is
required. The program re
capacity of 64 bytes or less
be
simil~r
to
that
to
of
output
T1
time interval. They will
all
eight
output
to
specify
as
Iorig
as
the
states
if
01
=03 (00000011),
lines can be repre-
the
value of
program runs.
the
of
system
BIT
0
BIT
I
BIT
2
BIT
3
BIT
4
BIT
5
BIT
6
BIT
7
is
also
shown
provide a
that
could
then
output
52
in
48
User Manual
for
the
BIT
BIT
I
BIT
BIT
The
time
(T1,
T2, T3,
to
be specified.
generator.
pendent
the
interval
external
54
Fig.
program
counter
outlines
sequential
time-control
table
pointer).
I-
-....JI
0
0
1
Z
,0
3
0
1
0
0 0
II
0
1
II
~TI--t-TZ+-T3+T4-t-T
01
(O~)
intervals between
and
The
The
output
functions
counter
called TC. The
memory
bytes
R(B)
02
CO2)
03
(05)
Fig.
53
output-line
T4).
The program can easily be modified
repetitive
output-register
lines might also activate relays for
or
devices.
the
manner
for the"entire
in
which five
program.
four
locations
(T1,
is
T2,
used
(01,
T3,
to
02,
and
T4).
address
1
II
II
04
(OE)
0
10
01
(03)
II
10
- Typical output-state sequence.
state
changes are specified by
state
sequences cou
bytes
03,
R(A)
the
scratchpad
R(3)
that
and
is
four
registers are utilized for this program. R(O)
is
used
specify
time
the
04
in Fig. 54). These
used
to
bytes and
BASI C SEOUENCE
0
1
0
0 0
I-+-TZ-+-T
02
(02)
to
permit
programmable
as
a loop
four
sets
address
the
is
called TP (time
II
0
1
II
Q 3
(05)
a larger
Id
be used
counter
of
output-line
four
four
-I
0
1
II
II
3~T4-+-T
04
(OE)
another
number
as a programmable
sequencing
called
bytes are followed by
state
bytes
table
10
10
01
(03)
92CM-
set
of
of
of
LC.
R(4)
values are
and
pointer).
II
26476
four
output-line
up
to
is
used as a
is
called OP (state
L2-
0
0
l-j
02
(02)
input
test
eight inde-
is
stored
the
bytes
states
pulse
used as
time
in
four
four
Fig.
bytes
of
set
to
8. The
The first
location.
After
memory
4-5
to
mented
input
eight
55
illustrates
R(A)
operator
input
the
location.
be
repeated,
and
bytes
and
R(B)
bytes
first
input
LC
and
LC
decremented.
to
the
operation
to
00.
must
now
will be
byte
is
decremented
the
next
be
stored
Step
enter
stored
is
stored
input
The
in
memory.
M
OP-
TP-"
Fig,
of
the
2 puts
a desired
at
the
in
by 1 so
byte
loop
01
02
03
04
TI
T2
T3
T4
54 - Register utilization.
program
the
memory
set
of
01
memory
memory,
win
OP
that
it will be equal
be
stored
comprising
The
first
four
RIO)'PROGRAM
R
(3)'
RI41'TC
RIA)'
RIB)'
in
flow-chart
address
four
state
LCILOOP
OP
TP(T
of
bytes
ITIME
(0
nes-
form.
the
TABLE
TABLE
COUNTER
COUNTER)
COUNTER)
POINTER)
POINTER)
26485
Step
first
state
by means
1 initializes
byte
of
the
location since OP was initially set
is
incremented
at
the
steps
4-5-6-7
bytes
02
by 1 so
to
7. A
memory
will be
represent
that
branch
location. OP will again be incre-
repeated
desired
output
the
high-order
(01)
into
R (A).
byte
input
switches.
to
address
it
is
addressing
instruction
causes
eight times, causing
line values and will
the
LC
is
this
02
steps
COSMAC Microprocessor
49
be stored
in
memory locations
Ql-Q4.
The second group
of
four input bytes represent
the
desired time
intervals between
output
states and will
be
stored
in
memory locations
Tl-
T4.
When
eight input bytes have been stored,
LC
will be equal
to
zero
in
step 7.
In
this case, steps 8·9·10 will
be performed next. QP
is
set
to
address
the
Q1
memory byte again. TP
is
set
to
address the
T1
byte.
LC
is
set equal
to
4 and step
11
is
performed
to
place
the
Q1
memory byte into the
output
register.
QP
is
incre·
mented by 1 so
that
the Q2 byte
will
be placed
in
the
output
register the next time step
11
is
performed.
Step
12
sets TC equal
to
the value
of
the
Tl
byte. TP
is
incremented by 1
so
that
TC will be set equal
to
the value of
the
T2 byte
the
next time step 12
is
performed.
Step
13
and 14 continually decrement
TC
until it reaches a value
of
zero. The time required for TC
to
reach zero determines the time interval between
the
current
output
state and
the
next
output
state. This
time
is
a function of the clock frequency, the number
of
instructions
in
the
loop comprising steps
13-14,
and
the
original value placed
in
TC.
At
the
end
of
the TC counting time,
LC
is
decremented by 1.
If
LC
does not equal zero,
the
step
11-17
loop
is
repeated. This loop causes the
Q1-Q2-Q3-Q4
output
sequence
to
occur at the specified
T1-
t2-
T3-
T4 time intervals. When
LC
equals zero
at
step 17, steps 8, 9, and
10
are performed again
to
repeat
the
Q1-Q2-Q3-Q4
sequence. This four·state
output
sequence
is
repeated until
the
system
is
stopped. After
applying a clear signal, a new set
of
state and time bytes can be entered
to
modify
the
output
sequence.
STEP
I
STEP
2-3
STEP
4-5
STEP
6
STEP
7
STEP
START
8-9-10
L-
__
~
___
--l
STEP
II
STEP
12
STEP
13
STEP
14
STEP
15
STEP
L-
___
,.-=-_--l
16-17
92CS-
26482
Fig.
55
- Sample program
flow
chart.
Fig.
56
shows
the
actual instruction bytes
in
memory required for
the
program. A low on
the
CLEAR
line sets P equal
to
0 and R(O) equal
to
0000. When execution
is
started, the instruction
in
memory location
0001 will
be
fetched and executed
as
described
in
the section on Memory and Control Interface. The in-
structions required for each
flow-chart step are shown.
Note
that
in
step 12
the
time-control byte
is
placed
in
the high-order half of R (4) or TC.
As
a result,
the
loop comprising steps
13
and 14
will
be executed
256
times
to
decrement the T byte value by 1. Steps
13
50
M AOORESS M BYTE OPERATION COMMENTS
0000 00
0001
0002
0003
0004
0005
0006
0007
0008
0009 A3
OOOA
noOB
OOOC
0000
OOOE
OOOF
0010 83
0011
0012
0013
0014
0015
0016
0017
0018 AB O+RIBI.O
0019
001A
001B
001C 60
0010
001E
00lF
0020
0021
0022
0023
0024 83 R(31.0+0
0025
0026
0027 30
0028 13 TO 0013
0029
002A
002B
002C
0020
002E
002F
0030
0031
R(01.1+0 lnitialize higher
90
BB
O+R(BI.l
O+R(AI.l
BA
M(R(PII+O Init'ialize lower byte
F8
2A
AA
D>R(AI.O
M(R(PII+O
F8
08
0+R(31.0
3C
IF
EFl
OA
EA
68
lA
23
3A
OA
F8
2A
AA
F8 MIRIPII+O
2E
F8 MIRIPII+O
04
A3 0+RI31.0
4B
B4
24 R(41-1 Decrement tim.e
94 R(41.1+0 Load
3A
lF
23
3A
lC
--
--
--
--
--
--
--
--
--
*1
GO
TO
OOOA
A+X
IN+M(R(XII
R(AI + 1
R(31-1
R(31.0+0 Load
IF
O#{)O
GO
TO
OOOA
M(R(PII'O
O+R(AI.O
MIR(XII+OUT
MIRIBII+O; RIBI + 1
D>RI41.1
IF
O#{)O
GO
TO 001F
R131-1
IF
O#{)O
GO
TOOO1C
BRANCH
Ql
02
03
04
T1
T2
T3
T4
Initialize
loop
Loop here until
Store
input
Advance table pointer STEP 6
Decrement
and
test loop
Reset Q table pointer STEP8
Set T table pointer STEP 9
Set loop counter
Output;
advance pointer STEP
time
Load
and
test
Decrement
Load
and
test
Repeat basic sequence STEP
o Table
Contains
State
Bytes
T·Table
Contains Time Count Bytes
byte
oftable
of
Q table pointer STEP 2
counter
to
8
byte
ready STEP4
byte STEP 5
loop
counter
counter
to
4
interval
counter
counter
time
counter
loop
counter
loop
counter
pointers
STEP 1
STEP 3
STEP
STEP
STEP
STEP 13
STEP 14
STEP
STEP
User Manual for
7
10
11
12
15
16'
17
the
and 14 comprise three instructions, or six machine cycles, or
clock cycle
equal (256 x
is
equivalent
48 x 10
to
10
x 10-6 x Tn), or 0.123Tn seconds. The maximum
would be obtained with a T byte value
Shorter
time
intervals can be achieved by using R(4).0
combining several scratchpad registers into a longer time interval counter. The clock frequency can also
be adjusted
to
provide a desired time interval range.
Fig.
56
- Sample program code.
48
clock cycles. With a 1
x 10-6 second. Time intervals between
of
"FF",
which would yield a delay
as
Te.
Longer
OO-kHz
output
time
time
register states would
interval
of
that
256 x 0.123,
could be specified
or
31.5
intervals could be obtained by
clock, each
then
seconds.
COSMAC Microprocessor
______________________________
_
51
Detailed
the
individual instructions.
study
of
Useful I nstructions
There
are
three
instructions
instructions
these
for
the
immediately following
output
This
section.
Interrupt
The use
aware
sequence
shares
program_
(60-67),
instructions
fetch
cycle when it acts as program
the
byte
technique
Service
of
the
of
the
fact
of
instructions
with
the
increments
"AD"
is
COSMAC
that
original program and restore these values before resuming
the
sample program shown in Fig.
with
X = P
which have particular usefulness when X
the
RETURN
the R (X)
the
instruction
by means
also useful
interrupt
an
interrupt
initiated by
instruction
register,
counter
byte
is
E3
60
AD
of
the
data
bus.
with
the
RETURN and DISABLE
line involves special programming considerations_
may
occur
the
interrupt
(70),
when
X=P
and
the
operand
Set
Output a byte
Immediate
Next instruction
between
routine
56
will provide a basic understanding
is
set
equal
and
the
DISABLE
the
R (P)/R (X) register will be
once
for
the
byte.
For
X=3_
from
byte
any
two
instructions
must
save
instruction
execute
example,
instructions,
the
cycle. As a result,
memory.
in
values
execution
if P=3,
as discussed later in
a program.
of
any
of
the
use
to
P:
the
OUTPUT
(71)_ Since each
incremented
the
sequenc~
The
user
Therefore,
machine registers it
of
the
once
the
byte
v/ill
this
should
be
the
interrupted
of
of
R(1) must always be initialized
allowed_ Fig.
permitting
storage area. This
like a
stack
interrupt
decreased
"U
FO"
When
pointing
occurred,
moved
from
The
the
interrupting
saved.
After
signal can be
pointer
counter
57
illustrates a
interrupt.
of
dishes
service
to
its original size when D
(Last·ln-First-Out) because
bytes
to
a free space.
so
the
the
stack
in
these
performed.
R(O), checking
register, branching
R(2)
stack
area grows in size
on
a table. Also like
example
are
pointer
stack
Fig.
program will
"housekeeping"
to
be
and
57
the
of
stored
In
decrements
the
is
used
This
to
to
the
address
hypothetical
is a stack
Fig.
the
pointer
modify
work
status
an emergency power-shut-down sequence,
pointer,
as
the
57,
the
stack
and
X,P were restored. Such a
the
first item removed
into
the
stack,
example
to
steps have been
shown,
to
OOEF
is
incremented.
store
the
values
any
other
may involve such tasks
of
peripheral devices, incrementing
of
the
interrupt
interrupt
i.e., it addressed
the
dish stack, it shrinks
grew by
to
service routine. R(1)
pointer
the
location
store
registers (scratch pad
completed,
moves upward (lower
two
bytes
from
the
of
pointer
X,P
R(2)
OOFO
X,P. When bytes are
and
D associated
the
as
the
as
may have been in use
transferring I/O
service program
is
topmost
bytes
are
removed
as
X,P
and
D were
stack
is
stack
is
the
last
is
first
decremented
no
with
or
DF),
"real
work"
or
decrementing
etc.
before
initialized
byte
in
memory
from
stored
sometimes
one
placed
longer
the
interrupted
their
contents
requested
bytes,
initializing
an
interrupt
to
0055
a variable-size
addresses),
the
top.
on
it,
and
referred
on
it.
to
assure
that
when
the
interrupt
needed,
they
program. If
must
by
the
interrupt
the
an internal
before
data
much
In
the
then
to
as a
it
is
are re-
also be
DMA
timer/
is
52
START
User Manual
for
the
ADDRESS
~"'"'
0053
0054 70
1'0055
0056
0057
0058
BYTE OPERATION
42
22
78
22
52
M(R(2))~D,
M(R(2))~X,
R(2) - 1
T~M(R(2))
R(2)
D~M(R(2))
1
-
-
R(2) + 1
P;
R(2) +
-
-
-
GO
30
53
-
-
-
OOEE
OOEF
OOFO
TO M(0053)
T
STACK STORAGE FOR T,i.e.
-
-
-
Upon
completion
registers saved
location M(0053). R(2) points
value of D and R(2) advances
original,
have been
process
were before
the
interrupt
interrupt
interrupted
executed
is
repeated). Note
the
When I E
is
reset
INTERRUPT line state. This setting prevents a second
is
being processed. The instruction (70)
routine
The RETURN
forming a branch. A convenient
RETURN (70)
if I
E=O,
X=5, and P=3,
of
the
"real
on
the
stack are now restored. I n
at
to
X and P register values. The
had
no
interrupt
that
R(1)
interrupt.
to
0 by
the
S3
sets
IE=1
so
that
subsequent
and
DISABLE instructions can be used
method
or
DISABLE (71)
the
sequence
instruction,
1
Fig.
57 - Interrupt service routine.
work",
M(OOEE). The LDA (42) instruction
M(OOEF). The RETURN instruction (70) sets IE=1
is
interrupt
return
occurred
(unless
left pointing
response cycle,
interrupts
is
to
using
the
next
that
set X equal
COMMENTS
1;
l~IE
housekeeping
example
instruction
the
at
M(0055) and R(2)
RESTORE D
RESTORE X, P
ENABLE INTERRUPTS
DEC
STACK POINTER
OLD
X,
P ONTO STACK
DEC
STACK POINTER
OLD D ONTO STACK
SAVE OTHER REGISTERS
IF-REQUIRED
PERFORM
RESTORE OTHER REGS'
PREPARE TO RETURN
STORAGE FOR OTHER REG.
STORAGE FOR D
STACK
OTHER STACK ENTRIES
of
"REAL
REQUESTED BY
TOP
must
be
Fig.
57,
executed
interrupt
further
interrupt
is
still present,
interrupts
response
restores original program
are permitted.
to
set
or
reset
to
the
current
the
desired X,P for
the
AND
R(2);
WORK"
INTERRUPT
OLD
WHEN INTERRUPTED
performed.
program
at
M(0053) restores
X, P
The
execution
and
will be
is
in
pointing
the
one
which case
at
M(OOFOl.
are inhibited regardless
from
occurring
IE
without
P value
exectuion
at
changing P
and
then
immediate byte. For
contents
branches
the
original
restores
the
which would
the
whole
as
they
whilean
the
end
of
and
per-
perform
the
example,
of
to
of
the
would have no
can be used
effect
other
than
to
disable interrupts during a critical instruction sequence.