IO Programming
IO Programming
student workbook
introduction to
the pdp11
Printed in U.S.A.
. - - - - - - - - - - - - - - course m a p - - - - - - - - - - - -.. . . .
PDP-"
FAMILY
MEMORY
AND
PRIORITY
CONTROL
UNIBUS
CONCEPTS
NOTE
SYSTEM A study unit should not
be started until all of the
units with arrows pointing
into it have been completed.
read on t
'--------------------------------iii ---------------------------------
READ LEARNING
OBJECTIVES
(page 1)
REVIEW MATERIAL
(pages 10-14)
GOOD WORK!
NOW GO ON TO THE
NEXT STUDY UNIT. read on •
~ ______--______~~~~____--_w ------------------------~--~
~-----------------------objectives----------------------~
* Analyze and write small I/O programs that are used by the CPU to communicate with
peripheral devices.
* Explain how the device interface registers are used to transfer data and control information
between the CPU and a peripheral.
* Explain how program subroutines and interrupt service routines are used in I/O
programming.
* Describe how the Bootstrap Loader is used to bring the Absolute Loader program into
memory and how the Absolute Loader, in tum, is used to enter other paper tape programs.
* Explain why the Bootstrap Loader and Absolute Loader programs share several memory
locations and show how they interact when they are executed.
~--------------------------------------l--------------------------------------'
._._--------- add itiona I resou r c e s - - - - - - - - -.....
• PDP-II Paper Tape Read Chapter 6. (Paragraph 6.1 describes the Bootstrap
Software Programming Loader; Paragraph 6.2 describes the Absolute Loader.)
Handbook
'-------------------------------------2------------------------------------,
~----------review material----------...........
• Buffer data
data buffer * Holds data sent to or from the peripheral. Used 10-14
register (DBR) in most peripheral interfaces, it is usually an
8-bit byte buffer or a 16-bit word buffer.
read on t
~-------------------------------------3--------------------------------------
~----------review material------------.......
read on t
'-------------------------------------4------------------------------------'
review material-----------,
Topic Key Pain ts Visual Ref I
CSR-DBR, * The CSR and DBR function together. 27-32
integrated Example: read data -
operation
• Set CSR control bits (start and interrupt
enable) which start read operation
read on t
'-------------------------------------5----------------------------------~
~----------review material------------....
instruction set * The PDP-I I has one instruction set. These 58-63
instructions can be used in I/O programming.
Examples:
INCB@#177560
(Set reader enable bit)
MOVB#101, TKS
(Set reader enable and
interrupt enable bits)
MOYB@#177562,R3
(Move data in reader
DBR to GPR 3)
TSTB@#177564
(Test state of ready bit
in punch status register.
Used with a branch instruction)
MOY#340,@#PS
(set processor priority
level to 7; PS=177776)
read on t
~------------------------------------6----------------------------------~
~---------- review material-----------i
l
--------7-------'
read on t
- - - - - - - - - - - - - review material----------~
read on t
~------------------------------------8------------------------------------'
-------------review material------------
l
"'------9-------""""
readont
- - - - - - - - - - - - - review materia 1------------.......
program loaders * Program loaders are small programs that allow 138
the operator to input or load other larger and
more complex programs into PDP-II memory.
bootstrap and * The PDP-II uses two loader programs to bring 147
absolute loader in other programs stored on paper tape - a
programs bootstrap loader and an absolute loader.
read on t
'-----------------------------------10----------------------------------'
. - - - - - - - - - - - - - review material-----------
read on t
~------------------------------------ll-------------------------------------'
,-------------review material-----------
TABLE A
BOOTSTRAP LOADER PROGRAM
NOTE
a. LOAD=START- 344. Data cannot be loaded into
memory below this address.
b. e=LOAD+344 defines the starting address (017 744) of
the Bootstrap Loader.
read on t
~-------------------------------12--------------------------------'
------------review material-----------.
r Instruction Mnemonic
THE BOOTSTRAP LOADER (TABLE A)
General Statement
Visual Ref
163-201
Analysis/Comments
START: MOV DEVICE,R1 GPR 1 is loaded with the address Input device is usually a
of the input device's CSR. high speed paper tape
reader or teletype.
LOOP: MOV #.- LOAD+2,R2 GPR 2 is loaded with an address Since immediate mode is
displacement. used, the address displace-
ment is in location LOOP+2.
ENABLE: INC @R1 The input device is enabled. The increment instruction
places a logical 1 into the
reader enable bit (the
LSB).
WAIT: TSTB@R1 The program waits until a byte Monitors the reader CSR
is read from the absolute done bit (7). When bit 7
loader tape and assembled in is a logical 1, the DBR
the DBR. is ready to transfer data.
BPL WAIT When a byte is read, the program The branch instruction
counter falls through the branch keeps the CPU in a wait
to next instruction. loop until bit 7 is a 1;
when bit 7 switches to a
1, the loop is broken.
The relationship between the bootstrap loader and absolute loader is shown in Figure 1.
NOTE
For an additional explanation, refer to Paragraph [Link]
in the PDP-ll Paper Tape Software Handbook.
read on t
'-----------------------------------13-----------------------------------'
.,.-----------review materia 1 - - - - - - - - - -..........
Figure 1
MEMORY LAYOUT OF BOOTSTRAP & ABSOLUTE LOADER
c
XX7 724 012 767
7 726 352 Absolute Loader
7 730 20
7 732 012 767
7 734 765
7 736 34
7 740 000 167
7 742 177 532
XX7 744 016 701
I!
016 701
7' 746 26 26
t
Overlay
7 750 012 702 012 702
b 7
7
752
754
352
005 211
373
(353)
!
7 756 105 711
7 760 100 376
7 762 116 162
7 764 2 Boot strap Loader
"7 "7t::.t::. vv-' A""
I IVV AA/ ...UU
L 7
7
7
XX7
770
772
774
776
L 005 267
177 756
000 765
TK or PR
j
TK = 177 560 Keyboard
PR = 177 550 Hi Speed Reader
XX is a function of memory size
0Branch in Loc. XX7 774 returns PC to Loc. XX7 750 before 373 is overlayed in
Loc. XX7 752.
®Branch in Loc. XX7 774 directs PC to Loc. XX7 724 after 373 is overlayed in
Loc. XX7 752.
0Absolute loader jumps to Halt in Loc. XX7 476 after restoring Bootstrap Loader.
I/O PROGRAMMING
The study exercises in this section of your workbook are intended to increase your familiarity
. with I/O programming concepts. Check the answer at the back of the workbook after working
each problem. Remember, this answer reflects one possible solution to the problem. It is not the
only answer; yours may be just as correct. After you've completed all the exercises, turn the A/V
playback unit back on and complete parts C and D of this study unit. You may also wish to
replay the first portion of this study unit - feel free to do so.
EXERCISE 1
The status register may be used to indicate an error or a fault in the peripheral device. For
example, bit 15 is set in the high speed paper tape reader CSR, or PRS, if the reader is out of
15
tape. Before each read operation it is desirable to test the state of this bit. If bit of the status
register is set, the data in the register is considered a negative value. The following two
instructions provide one way to test this bit:
TST PRS
BMI NOTAPE
What happens in this program when the reader has run out of tape?
read on t
~-----------------------------------15-------------------------------------
~-------------------study exercises--------------------'~
EXERCISE 2
The BIT instruction can be used for testing any of the 16 bits in a status register. For example,
the following two instructions are used to check on the availability of data in the Teletype reader
buffer. As you recall, this is indicated by bit 7 of the TKS being set:
BEQWAIT
Here the contents of TKS is logically ANDed with 200. Until the DONE bit (#7) is set,- the sum is
zero; the conditions for the BEQ are met and the program remains in the loop. The DONE bit is
then set when the data is available in the TKB. Now the sum of 200 and the TKS contents is no
longer zero and the program falls through to the next instruction.
At this time we'd like you to use the BIT instruction in ~ two instruction sequence that causes a
branch to an error routine (NOCARD) if the input hopper of the high-speed punched card reader
(CD 11) is found to be empty. The card reader CSR is called the CDST and its address is 172460.
Bit 2 of the CDST is the hopper check bit.
read on t
------------------------------------16-----------------------------------'
~-------------------study exercises--------------------~
EXERCISE 3
What is the purpose of the following subroutine? Also indicate, in the space provided, the
function of each instruction.
(Rl) = 5000
ADD #200, R2
BEQWAIT
DECRO
BNEENCODE
RTSR5
l
"---------17----------'
read on t
~-------------------study exercises--------------------~
EXERCISE 4
Write a subroutine that allows 100 8 keyboard generated characters to be stored in a memory area
with a starting address of INDATA. Afterwards return to the main program. Explain what each
of your instructions does.
read on t
'------------------------------------18-----------------------------------'
---------------------study exercises--------------------~
EXERCISES
In the preceding problem (Exercise 4) we stored lOOs characters in a memory area with a starting
address of INDATA. The stored data is in the Teletype code. Write a subroutine (TRANS) that
converts the Teletype-coded data to the ASCII code and stores it in a memory area with a
starting address of TDAT A. Explain what each instruction does.
read on t
~----------------------------------19-----------------------------------'
~-------------------study exercises--------------------,
EXERCISE 6
Programs can be written that allow the computer operator to manually control the program's
operation. In the program below the operator is allowed to store up to 64 10 (100 8 ) characters
from the keyboard. If the SPACE bar is pressed before all 64 characters are stored, the program is
halted; additional characters are not stored.
CLR TALLY
MOV # INDATA, RI
BPLPAWS
BEQ FINI
MOVB TKB,(Rl)+
INC TALLY
BLTPAWS
FINI: HALT
Modify the program so that when the space bar is pressed, or 64 characters have been stored, the
program types out all the stored characters and then halts.
read on t
'----------------------------------20--------------------------------~
study exerCises--------------------'1
EXERCISE i
The BIS and BIC instructions are useful for modifying one bit of a peripheral status register while
leaving the other bits undisturbed. For example, bit 9 of the VR 20 Color CRT status register
controls the color of the display, 0 for green and 1 for red. To change the color, it is necessary to
change only this one bit. The instruction BIS #1000, CRTSR sets bit 9 in the status register
without disturbing the other bits. They remain set or clear as the case may be. Write the
instruction to set the interrupt enable bit of the Teletype reader status register, TKS.
read on t
'-----------------------------------21-----------------------------------'
~-------------------study exercises--------------------,
EXERCISE 8
Individual bits in a status register can be cleared with the BIC instruction. Write an instruction to
clear the external clock enable bit, bit 1, of the ADCS, the Analog to Digital Subsystem CSR.
read on t
~------------------------------------22------------------------------------
~-------------------study exercises--------------------~
EXERCISE 9
The interrupt mode of operation is used to reduce computer waiting time. In the program loop
method, as we learned, the computer continually checks the state of the DONE flag (bit 7) in the
peripheral CSR. Using the interrupt mode, the computer actually ignores the peripheral, running
its own low-priority program until the peripheral requests service by setting the DONE bit. (The
interrupt enable bit in the CSR must have been set at some prior point.) The computer completes
the instruction being executed and then starts the interrupt service routine. The service routine
rrfay transfer the data involved and then perform some calculations with it. After the interrupt
service routine has been completed, the computer resumes the program that was interrupted by
the peripherals higher priority request.
In the program below assume that the high speed reader, which at some earlier time had been
commanded to read a character, now initiates an interrupt while the instruction opposite the
arrow is being executed.
INC COUNT
BLOSMOREAD
What instruction in this program is executed first after the interrupt service routine has been
completed?
read on
' -_________________________________ 23 ________________________________ ~ t
~~--------------------stUdY exercises
EXERCISE 10
For peripheral devices there are four different interrupt priority levels, 4 to 7, of which 7 is the
highest. Some peripherals are assigned a higher priority than others. For example, the Teletype
keyboard and the high speed punch both operate at a priority level of 4, while the card reader has
a priority level of 6. The CPU normally operates its background program at a level below 4 so
that it may be interrupted by any of the peripherals mentioned above. A peripherals service
routine can be interrupted, but only by a peripheral which has a higher priority than the one
being serviced.
Assume that the above mentioned peripherals are included in a system. At this time the CPU is
running its background program. What happens if -
b) Then, while the card reader service routine is running, the Teletype keyboard requests
service?
EXERCISE 11
Considering the same system (Exercise 10), what happens if the CPU program is running and the
keyboard requests service? Then, what happens when the card reader requests service after the
keyboard service routine has been started.
read on t
'-______----------------------------25----------------------------------~
~-------------------study exercises---------------------
EXERCISE 12
A Teletype keyboard service routine might store data in memory as in the example below. Each
time the keyboard is hit the service routine is entered.
RTI
read on t
~----------------------------------26------------------------------------
,--------------------study exercises--------------------~
EXERCISE 13
It cannot be assumed that registers used in an interrupt service routine are not used
elsewhere - in the main or background program, for example. Other peripheral service routines
may also require the use of the same register. Therefore, there are two basic considerations when
programming service routines:
b) Register data needed in a service routine should be stored via a label at the end of the
service routine, freeing the register for use in the background program or in other
service routines.
Write the PUSH and POP instructions needed to preserve the original contents of RI and R2
during the keyboard service routine.
'-__________________________________ 27 __________________________________-'
read on t
study exercises--------------------~'I
EXERCISE 14
During a service routine, the data produced by a peripheral could be stored in memory, say at an
address defined by the label STORWD. Two instructions are required for this purpose:
b) An instruction within the interrupt service routine to initialize a register with the
contents of DASTOR.
MOV DASTOR, RI
•
•
•
MOV (SP)+, R I ; Restore RI
read on t
'-----------------------------------28----------------------------------~
~-------------------study exercises---------------------
EXERCISE 15
TITLE, a service routine for the Teletype printer, causes a character to be printed from a list
whose first address is identified by the label MESAGE. Write the address initialization instruction
required at the beginning of the background program as well as the service routine itself.
EXERCISE 16
Write an interrupt service routine that starts at an address with a label of PROFIL and keeps
track of the number of times each letter (A through Z) is pressed on the keyboard. Use the label
OCCUR as the starting address for the memory area where the individual counts are stored. If
you refer to the ASCII code listing, you can see that an offset address can be derived from the
code for each character. Remember, there is a difference between the ASCII code and the
transmitted Teletype code.
read on t
~-----------------------------------30------------------------------------
,-----------answers to exercises---------.. . . .
EXERCISE 1
Bit 15 is set. Then, when the TST instruction is executed, the N bit in the PSW is set because the
PRS data appears as a negative value. With the N bit set, the BMI instruction causes the program
to branch to the NOT APE subroutine. This subroutine might, for example, type an error message
on the teletypewriter.
EXERCISE 2
BNENOCARD
The contents of the CDST is logically ANDed with 4. If the hopper check bit is set prior to the
BIT instruction being executed, the sum is 4 (not equal to zero) and the program branches to
NOCARD.
Remember, the BIT instruction can be used to check more than one bit in a CSR.
31
answers to exercises---------i
EXERCISE 3
This subroutine uses the Teletype printer/punch to punch 64 1 0 (1 OOs) characters on paper tape.
The data is obtained from successive memory locations starting at address 5000. Each character is
converted from ASCII to Teletype code before it is transferred to the data buffer.
; Conversion
BEQWAIT ; Is set
; And punch
; Byte count = 0
32
~---------answers to exercises---------.. . .
EXERCISE 4
; stored
In the compare (CMP) instruction the destination is subtracted from COUNT. Until COUNT =
100 the result is a negative number (less than zero). Therefore, until 100 characters have been
stored, the BLT instruction conditions are met and the program loops on WAITK.
33
answers to exercises---------..... i
EXERCISE 5
;GPRO
;GPR 1
; with 100
; count = 0
34
".----------answers to exercises---------.. . .
EXERCISE 6
CLR TALLY
MOV#INDATA,Rl
PAWS: TSTBTKS
BPL PAWS
BEQOUTPUT
INC TALLY
BLTPAWS
BEQWAITPR
CMP Rl, R2
BGTWAITPR
HALT
Care must be used in selecting the branch instruction that follows the CMP Rl, R2 instruction.
If, for example, only one character has been stored, then R 1 and R2 would have the same
contents after this single character was printed. At this point the program should halt, not branch
back. Therefore, branching back must take place if the contents of R 1 are greater than that of
R2, and halt when they are equal. The BGT instruction provides the correct branching in this
case. Most branching errors involve one loop too many or one too few.
' -_______________________________ 35
(
answers to exercises--------......... i
EXERCISE 7
; previously clear
EXERCISE 8
This instruction clears bit 1 without disturbing the other bits. The BIC instruction is also useful
for masking out unwanted portions of a data word. For example BIC 40, XXXX would convert
lower case ASCII characters a through z to upper case characters A through Z.
EXERCISE 9
EXERCISE 10
a) The CPU background program is stopped and the card reader service routine is run.
b) The Teletype keyboard's request is accepted only after the card reader service routine
is completed.
When all interrupt service routines have been completed, the CPU background program is
resumed at the point where it was interrupted.
36
~---------answers to exercises---------.. . . .
EXERCISE 11
d) The card reader service routine (Priority Level 6) is started and run to completion.
e) The keyboard service routine is resumed at the point where it was stopped and run to
compietion.
EXERCISE 12
The instruction RTI, Return From Interrupt, is always the last executed instruction of a service
routine. It causes a return to the previously interrupted program.
EXERCISE 13
MOV (SP)+, R2
MOV (SP)+, R I
37
------------answers to exercises - - - - - - - - -.. . .
EXERCISE 14
KEYSRV: MOVRl,-(SP)
MOV DASTOR, Rl
MOV (SP)+, R 1
RTI
EXERCISE 15
; address
The TITLE service routine is entered each time a character is to be printed. This happens each
time the peripheral raises its DONE flag, indicating readiness to print another character.
'--------------------------------- 38
~---------answers to exercises---------.. . .
EXERCISE 16
; character. Destination
; address is determined by
39 ------------------------------~
.,.---------test-i/o programming---------
When you have completed the study unit, please take this self-scoring test. Then compare your
answers against the "answer sheet" which can be obtained from your supervisor. Based on your
test results, either review the appropriate material in this study unit or proceed to the next unit
in the series.
b. Convert parallel data from the device to a serial format for the
Unibus.
3. Explain how the TSTB instruction is used with the CSR READY or
DONE bit to control program operation.
read on t
'-----------------------------------42----------------------------------~
- - - - - - - - - - - test-i/o programming - - - - - - - -..........
7. Two loader progranls were discussed in this study unit. The first
program is deposited in memory through the console and is called the
_ _ _ _ _ loader program. The second loader prognuli is entered
through the paper tape reader and is called the loader
program.
8. The starting address of the bootstrap loader program is xx7 744, 'Nhere
"xx" is a function of the memory size.
r 9. Listed below are the instructions that make up the bootstrap program.
Briefly, explain the function of each instruction.
e. BPL WAIT
'-__________________________________44 ________________________________--'
read on t
~--------test-i/o programming----------
g. INC LOOP+2
h. BRNCH: BR LOOP
12. The following steps occur when the absolute loader is deposited in
memory. Place these steps in the correct order.
I
( ) The CPU stops executing the bootstrap loader and starts
executing the absolute loader.
( ) The leader code is read from the absolute loader tape and the
CPU continues looping through the bootstrap program.