You are on page 1of 34

Programming the Basic Computer

PROGRAMMING THE BASIC COMPUTER

• Introduction

• Machine Language

• Assembly Language

• Assembler

• Program Loops

• Programming Arithmetic and Logic Operations

• Subroutines

• Input-Output Programming

1
Programming the Basic Computer Introduction

INTRODUCTION
Those concerned with computer architecture should have a knowledge
of both hardware and software because the two branches influence
each other.

Instruction Set of the Basic Computer


Symbol Hexa code Description
AND 0 or 8 AND M to AC m: effective address
ADD 1 or 9 Add M to AC, carry to E M: memory word (operand)
LDA 2 or A Load AC from M found at m
STA 3 or B Store AC in M
BUN 4 or C Branch unconditionally to m
BSA 5 or D Save return address in m and branch to m+1
ISZ 6 or E Increment M and skip if zero
CLA 7800 Clear AC
CLE 7400 Clear E
CMA 7200 Complement AC
CME 7100 Complement E
CIR 7080 Circulate right E and AC
CIL 7040 Circulate left E and AC
INC 7020 Increment AC, carry to E
SPA 7010 Skip if AC is positive
SNA 7008 Skip if AC is negative
SZA 7004 Skip if AC is zero
SZE 7002 Skip if E is zero
HLT 7001 Halt computer
INP F800 Input information and clear flag
OUT F400 Output information and clear flag
SKI F200 Skip if input flag is on
SKO F100 Skip if output flag is on
ION F080 Turn interrupt on
IOF F040 Turn interrupt off

2
Programming the Basic Computer Machine Language

MACHINE LANGUAGE
Program:
is a list of instructions or statements for directing the computer to
perform a required data processing task

Various types of programming languages


- Hierarchy of programming languages

• Machine-language
- Binary code
- Octal or hexadecimal code

• Assembly-language (Assembler)
- Symbolic code

• High-level language (Compiler)

3
Programming the Basic Computer Machine Language

COMPARISON OF PROGRAMMING LANGUAGES

Program to Add Two Numbers

C++ Program Assembly-Language Program

Int A,B,C; ORG 0 /Origin of program is location 0


LDA A /Load operand from location A
Cin >> A; ADD B /Add operand from location B
STA C /Store sum in location C
Cin >> B; HLT /Halt computer
A, DEC 83 /Decimal operand
C = A + B; B, DEC -23 /Decimal operand
C, DEC 0 /Sum stored in location C
END /End of symbolic program

Hexadecimal Program Program with Symbolic OP-Code

000 2004 000 LDA 004 Load 1st operand into AC


001 1005 001 ADD 005 Add 2nd operand to AC
002 3006 002 STA 006 Store sum in location 006
003 7001 003 HLT Halt computer
004 0053 004 0053 1st operand
005 FFE9 005 FFE9 2nd operand (negative)
006 0000 006 0000 Store sum here

4
Programming the Basic Computer Machine Language

COMPARISON OF PROGRAMMING LANGUAGES

Program to Add Two Numbers

Hexadecimal Program Binary Program


000 2004 0 0010 0000 0000 0100
001 1005 1 0001 0000 0000 0101
002 3006 10 0011 0000 0000 0110
003 7001 11 0111 0000 0000 0001
004 0053 100 0000 0000 0101 0011
005 FFE9 101 1111 1111 1110 1001
006 0000 110 0000 0000 0000 0000

5
Programming the Basic Computer Assembly Language

ASSEMBLY LANGUAGE

Syntax of the BC Assembly Language


pseudo
instruction ORG 0 /Origin of program is location 0
MRI LDA A /Load operand from location A
Instruction ADD B /Add operand from location B
STA C /Store sum in location C comment
non-MRI HLT /Halt computer
label A, DEC 83 /Decimal operand
B, DEC -23 /Decimal operand
C, HEX 0 /Sum stored in location C
END /End of symbolic program

6
Programming the Basic Computer Assembly Language

ASSEMBLY LANGUAGE
Syntax of the BC assembly language:
Each line of code is arranged in three columns called fields:
1. Label field
- May be empty or may specify a symbolic address of up to 3 characters
- Terminated by a comma
2. Instruction field
- Specifies a machine or a pseudo instruction
- May specify one of the following:
* Memory reference instructions (MRI)
MRI consists of two or three symbols separated by spaces.
ADD OPR (direct address MRI)
ADD PTR I (indirect address MRI)
* Register reference or input-output instructions
Non-MRI does not have an address part
* Pseudo instruction with or without an operand
- Symbolic address used in the instruction field must be defined as a label

3. Comment field
- May be empty or may include a comment
7
Programming the Basic Computer Assembly Language

ASSEMBLY LANGUAGE

Pseudo-instructions
ORG N Hexadecimal number N is the memory location for
the instruction or operand listed in the following line
END Denotes the end of symbolic program
DEC N Signed decimal number N to be converted to binary
HEX N Hexadecimal number N to be converted to binary

Example: Assembly language program to subtract two numbers


ORG 100 / Origin of program is location 100
LDA SUB / Load subtrahend to AC
CMA / Complement AC
INC / Increment AC
ADD MIN / Add minuend to AC
STA DIF / Store difference
HLT / Halt computer
MIN, DEC 83 / Minuend
SUB, DEC -23 / Subtrahend
DIF, HEX 0 / Difference stored here
END / End of symbolic program

8
Programming the Basic Computer

ASSEMBLY LANGUAGE

Problem 6-3: List the assembly language program for the following
Fortran program.
SUM = 0
SUM = SUM + A + B
DIF = DIF – C
SUM = SUM + DIF

Problem 6-1: The following program is stored in the memory. Show


the contents of AC, PC, and IR after each instruction is executed.
Location Instruction
010 CLA
011 ADD 016
012 BUN 014
013 HLT
014 AND 017
015 BUN 013
016 C1A5
017 93C6

9
Programming the Basic Computer Assembly Language

TRANSLATION TO BINARY

Symbol Hexa code


Hexadecimal Code
Symbolic Program AND 0 or 8
Location Content ADD 1 or 9
ORG 100 MRI LDA 2 or A
100 2107 100 LDA SUB 107 Table STA 3 or B
BUN 4 or C
101 7200 101 CMA BSA 5 or D
102 7020 102 INC ISZ 6 or E
103 1106 103 ADD MIN 106 CLA 7800
104 3108 104 STA DIF 108 CLE 7400
105 7001 105 HLT CMA 7200
106 0053 MIN, 106 DEC 83 CME 7100
107 FFE9 SUB, 107 DEC -23 CIR 7080
CIL 7040
108 0000 DIF, 108 HEX 0 non-MRI INC 7020
END Table SPA 7010
SNA 7008
SZA 7004
SZE 7002
Address-Symbol Table HLT 7001
INP F800
Address symbol Hex address OUT F400
SKI F200
MIN 106 SKO F100
SUB 107 ION F080
DIF 108 IOF F040

10
Programming the Basic Computer Assembler

ASSEMBLER - FIRST PASS -


Assembler
Source Program - Symbolic Assembly Language Program
Object Program - Binary Machine Language Program
Two pass assembler
1st pass: generates a table that correlates all user defined
(address) symbols with their binary equivalent value
2nd pass: binary translation
First pass
First pass
LC ← 0

Scan next line of code Set LC


yes
no no
Label ORG

yes
yes
Store symbol END
in address-
symbol table
together with no Go to
value of LC second
pass
Increment LC

11
Programming the Basic Computer Assembler

ASSEMBLER - SECOND PASS -


Second pass
Second Pass
LC ← 0

Machine instructions are Done


Scan next line of code
translated by means of Set LC

table-lookup procedures: yes yes

Pseudo yes no
ORG END
instr.
1. Pseudo-Instruction Table no
no
2. MRI Table DEC or
3. Non-MRI Table yes
MRI
no HEX
Convert
4. Address Symbol Table operand
Get operation code to binary
and set bits 2-4 Valid
no and store
non-MRI
instr. in location
Search address- given by LC
symbol table for yes
memory word contains MRI: binary equivalent
of symbol address
1 2 4 5 16 and set bits 5-16
Store binary Error in
I Opcode Address equivalent of line of
yes no instruction code
I in location
given by LC
Set Set
first first
bit to 1 bit to 0

Assemble all parts of


Increment LC
binary instruction and
store in location given by LC

12
Programming the Basic Computer

ASSEMBLER - Example
Problem 6-7:
a. Obtain the address-symbol table generated for the Symbol Hexa code
following program during the first pass of the assembler. AND 0 or 8
ADD 1 or 9
b. List the translated program in hexadecimal. LDA 2 or A
STA 3 or B
ORG 100 BUN 4 or C
100 LDA ADS BSA 5 or D
101 STA PTR ISZ 6 or E
102 LDA NBR CLA 7800
103 STA CTR CLE 7400
104 CLA CMA 7200
105 LOP, ADD PTR I CME 7100
106 ISZ PTR CIR 7080
107 ISZ CTR
CIL 7040
108 BUN LOP
INC 7020
109 STA SUM
10A SPA 7010
HLT
10B SNA 7008
ADS, HEX 150
10C PTR, HEX 0 SZA 7004
10D NBR, DEC -100 SZE 7002
10E CTR, HEX 0 HLT 7001
10F SUM, HEX 0 INP F800
ORG 150 OUT F400
150 DEC 75 SKI F200
. . SKO F100
. . ION F080
. .
1B3 DEC 23 IOF F040
END

13
Programming the Basic Computer Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each time with a different set of data
C program to add 100 numbers: int a[100], sum, i;
sum = 0;
for (i = 0; i < 100; i++)
Add 100 numbers: sum = sum + a[i];

ORG 100 / Origin of program is HEX 100


100 LDA ADS / Load first address of operand
101 STA PTR / Store in pointer
102 LDA NBR / Load -100
103 STA CTR / Store in counter
104 CLA / Clear AC
105 LOP, ADD PTR I / Add an operand to AC
106 ISZ PTR / Increment pointer
107 ISZ CTR / Increment counter
108 BUN LOP / Repeat loop again
109 STA SUM / Store sum
10A HLT / Halt
10B ADS, HEX 150 / First address of operands
10C PTR, HEX 0 / Reserved for a pointer
10D NBR, DEC -100 / Initial value for a counter
10E CTR, HEX 0 / Reserved for a counter
10F SUM, HEX 0 / Sum is stored here
ORG 150 / Origin of operands is HEX 150
150 DEC 75 / First operand
. .
. .
. .
1B3 DEC 23 / Last operand
END / End of symbolic program

14
Programming the Basic Computer Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each time with a different set of data
C program to add 100 numbers: int a[100], sum, i;
sum = 0;
for (i = 0; i < 100; i++)
Add 100 numbers: sum = sum + a[i];

ORG 100 / Origin of program is HEX 100


100 LDA ADS / Load first address of operand
101 STA PTR / Store in pointer
102 LDA NBR / Load -100
103 STA CTR / Store in counter
104 CLA / Clear AC
105 LOP, ADD PTR I / Add an operand to AC
106 ISZ PTR / Increment pointer
107 ISZ CTR / Increment counter
108 BUN LOP / Repeat loop again
109 STA SUM / Store sum
10A HLT / Halt
10B ADS, HEX 150 / First address of operands
10C PTR, HEX 0 / Reserved for a pointer
10D NBR, DEC -100 / Initial value for a counter
10E CTR, HEX 0 / Reserved for a counter
10F SUM, HEX 0 / Sum is stored here
ORG 150 / Origin of operands is HEX 150
Reserve 150 DEC 75 / First operand First operand = 75
memory . . .
. . .
for 100 . . .
operands 1B3 DEC 23 / Last operand Last operand = 23
END / End of symbolic program

15
Programming the Basic Computer Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each time with a different set of data
C program to add 100 numbers: int a[100], sum, i;
sum = 0;
for (i = 0; i < 100; i++)
Add 100 numbers: sum = sum + a[i];

ORG 100 / Origin of program is HEX 100


100 LDA ADS / Load first address of operand
101 STA PTR / Store in pointer
102 LDA NBR / Load -100
103 STA CTR / Store in counter
104 CLA / Clear AC
105 LOP, ADD PTR I / Add an operand to AC
106 ISZ PTR / Increment pointer
107 ISZ CTR / Increment counter
108 BUN LOP / Repeat loop again
109 STA SUM / Store sum
10A HLT / Halt
Define 10B ADS, HEX 150 / First address of operands ADS = 150
10C PTR, HEX 0 / Reserved for a pointer PRT = 0
program 10D NBR, DEC -100 / Initial value for a counter NBR = -100
variables 10E CTR, HEX 0 / Reserved for a counter CTR = 0
10F SUM, HEX 0 / Sum is stored here SUM = 0
ORG 150 / Origin of operands is HEX 150
150 DEC 75 / First operand First operand = 75
. . .
. . .
. . .
1B3 DEC 23 / Last operand Last operand = 23
END / End of symbolic program

16
Programming the Basic Computer Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each time with a different set of data
C program to add 100 numbers: int a[100], sum, i;
sum = 0;
for (i = 0; i < 100; i++)
Add 100 numbers: sum = sum + a[i];

ORG 100 / Origin of program is HEX 100


100 LDA ADS / Load first address of operand AC = ADS
Initialize 101 STA PTR / Store in pointer PTR = AC
loop 102 LDA NBR / Load -100 AC = NBR
variables 103 STA CTR / Store in counter CTR = AC
104 CLA / Clear AC AC = 0
105 LOP, ADD PTR I / Add an operand to AC
106 ISZ PTR / Increment pointer
107 ISZ CTR / Increment counter
108 BUN LOP / Repeat loop again
109 STA SUM / Store sum
10A HLT / Halt
10B ADS, HEX 150 / First address of operands ADS = 150
10C PTR, HEX 0 / Reserved for a pointer PRT = 0
10D NBR, DEC -100 / Initial value for a counter NBR = -100
10E CTR, HEX 0 / Reserved for a counter CTR = 0
10F SUM, HEX 0 / Sum is stored here SUM = 0
ORG 150 / Origin of operands is HEX 150
150 DEC 75 / First operand First operand = 75
. .
. .
. .
1B3 DEC 23 / Last operand Last operand = 23
END / End of symbolic program

17
Programming the Basic Computer Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each time with a different set of data
C program to add 100 numbers: int a[100], sum, i;
sum = 0;
for (i = 0; i < 100; i++)
Add 100 numbers: sum = sum + a[i];

ORG 100 / Origin of program is HEX 100


100 LDA ADS / Load first address of operand AC = ADS
101 STA PTR / Store in pointer PTR = AC
102 LDA NBR / Load -100 AC = NBR
103 STA CTR / Store in counter CTR = AC
104 CLA / Clear AC AC = 0
105 LOP, ADD PTR I / Add an operand to AC AC = AC + operand
Execute 106 ISZ PTR / Increment pointer PTR = PRT + 1
loop 107 ISZ CTR / Increment counter CTR = CTR + 1
108 BUN LOP / Repeat loop again
109 STA SUM / Store sum SUM = AC
10A HLT / Halt
10B ADS, HEX 150 / First address of operands ADS = 150
10C PTR, HEX 0 / Reserved for a pointer PRT = 0
10D NBR, DEC -100 / Initial value for a counter NBR = -100
10E CTR, HEX 0 / Reserved for a counter CTR = 0
10F SUM, HEX 0 / Sum is stored here SUM = 0
ORG 150 / Origin of operands is HEX 150
150 DEC 75 / First operand First operand = 75
. .
. .
. .
1B3 DEC 23 / Last operand Last operand = 23
END / End of symbolic program

18
Programming the Basic Computer

PROGRAM LOOPS

Problem 6-13: Write a program loop, using a pointer and a counter,


that clears to 0 the contents of hexadecimal locations 500 through 5FF.

:
CLA
LOP, STA PTR I
ISZ PTR
ISZ CTR
BUN LOP
HLT
:

19
Programming the Basic Computer Programming Arithmetic and Logic Operations

LOGIC OPERATIONS

- BC instructions: AND, CMA

- Program for OR operation

A ∨ B = (A’ ∧ B’)’

LDA A / Load 1st operand AC = A


CMA / Complement to get A’ AC = A’
STA TMP / Store in a temporary location TMP = A’
LDA B / Load 2nd operand B AC = B
CMA / Complement to get B’ AC = B’
AND TMP / AND with A’ to get A’ ∧ B’ AC = A’ ∧ B’
CMA / Complement again to get A ∨ B AC = (A’ ∧ B’)’

Problem 6-19: Write a program that evaluates the logic exclusive-OR of


two logic operands.

20
Programming the Basic Computer Programming Arithmetic and Logic Operations

SHIFT OPERATIONS

- BC has Circular Shift only

- Logical shift-right operation

E AC
CLE
0 0
CIR

- Logical shift-left operation

AC E
CLE
0 0
CIL

- Arithmetic shift-right operation

E AC
CLE / Clear E to 0
AC positive 0 0
SPA / Skip if AC is positive E AC
CME / AC is negative; set E to 1 AC negative 1 1
CIR / Circulate E and AC

21
Programming the Basic Computer Subroutines

SUBROUTINES
Subroutine
- A set of common instructions that can be used in a program many times.
- Subroutine linkage : a procedure for branching
to a subroutine and returning to the main program
Example: Shift the value of X and Y four times to the left
Memory Loc. ORG 100 / Main program
100 LDA X / Load X
101 0 BSA 109 101 BSA SH4 / Branch to subroutine
102 Next instruction 102 STA X / Store shifted number
103 LDA Y / Load Y
104 BSA SH4 / Branch to subroutine again
105 STA Y / Store shifted number
106 HLT
107 X, HEX 1234
108 Y, HEX 4321
/ Subroutine to shift left 4 times
109 return address 109 SH4, HEX 0 / Store return address here
10A Subroutine 10A CIL / Circulate left once
10B CIL
10C CIL
10D CIL / Circulate left fourth time
10E AND MSK / Set AC(0-3) to zero
10F 1 BUN 109 10F BUN SH4 I / Return to main program
110 MSK, HEX FFF0 / Mask operand
END

22
Programming the Basic Computer Subroutines

SUBROUTINE PARAMETERS AND DATA LINKAGE


Linkage of Parameters and Data between the Main Program and a Subroutine
- via Registers
- via Memory locations

Example: Subroutine performing LOGIC OR operation; Need two parameters


Memory Loc. ORG 200
200 LDA X / Load 1st operand into AC
201 0 BSA 207 201 BSA OR / Branch to subroutine OR
202 3AF6 202 HEX 3AF6 / 2nd operand stored here
203 Next instruction 203 STA Y / Subroutine returns here
204 HLT
205 X, HEX 7B95 / 1st operand stored here
206 Y, HEX 0 / Result stored here
207 return address 207 OR, HEX 0 / Subroutine OR
208 208 CMA / Complement 1st operand
Subroutine
209 STA TMP / Store in temporary location
20A LDA OR I / Load 2nd operand
20B CMA / Complement 2nd operand
20C AND TMP / AND complemented 1st operand
20D CMA / Complement again to get OR
0 ISZ 207 20E ISZ OR / Increment return address
20F 1 BUN 207 20F BUN OR I / Return to main program
210 TMP, HEX 0 / Temporary storage
END
23
Programming the Basic Computer Subroutines

SUBROUTINE - Moving a Block of Data -


/ Main program
BSA MVE / Branch to subroutine
HEX 100 / 1st address of source data
HEX 200 / 1st address of destination data
DEC -16 / Number of items to move
HLT
MVE, HEX 0 / Subroutine MVE MVE = address of “HEX 100”
LDA MVE I / Bring address of source
STA PT1 / Store in 1st pointer
ISZ MVE / Increment return address MVE = address of “HEX 200”
LDA MVE I / Bring address of destination
STA PT2 / Store in 2nd pointer
ISZ MVE / Increment return address MVE = address of “DEC -16”
LDA MVE I / Bring number of items
STA CTR / Store in counter
ISZ MVE / Increment return address MVE = address of “HLT“ (return address )
LOP, LDA PT1 I / Load source item
STA PT2 I / Store in destination
ISZ PT1 / Increment source pointer • C Function
ISZ PT2 / Increment destination pointer
ISZ CTR / Increment counter void Move (int Src[], int Dest[], int N)
BUN LOP / Repeat 16 times {
BUN MVE I / Return to main program int i;
PT1, -- for (i=0; i < N; i++)
PT2, -- Dest[i] = Src [i]
CTR, -- }

24
Programming the Basic Computer

SUBROUTINES
Problem 6-21: Write a subroutine to subtract two numbers. In the
calling program, the BSA instruction is followed by the subtrahend
and minuend. The difference is returned to the main program in the
third location following the BSA instruction.

BSA SUB
DEC -23 /Subtrahend
DEC 83 /Minuend
HEX 0 /Difference
HLT
SUB, HEX 0
:
Problem 6-22: Write a subroutine to complement each word in a
block of data. In the calling program, the BSA instruction is followed
by two parameters: the starting address of the block and the number
of words in the block.
BSA COM
HEX 100 /1st address of block
DEC 16 /Number of items in block
HLT
COM, HEX 0
:
25
Programming the Basic Computer Input Output Program

INPUT OUTPUT PROGRAM

Program to Input one Character (Byte)

CIF, SKI / Check input flag


BUN CIF / Flag=0, branch to check again
INP / Flag=1, input character
STA CHR / Store character
HLT
CHR, -- / Store character here

Program to Output one Character


LDA CHR / Load character into AC
COF, SKO / Check output flag
BUN COF / Flag=0, branch to check again
OUT / Flag=1, output character
HLT
CHR, HEX 0057 / Character is "W"

26
Programming the Basic Computer Input Output Program

CHARACTER MANIPULATION

Program to input two characters and pack them into one 16-bit word

AC
FST, SKI
BUN FST 15 8 7 0

INP / Input 1st character 1st Char


BSA SH4 / Shift left four times
BSA SH4 / Shift left four more times
SCD, SKI 1st Char

BUN SCD
INP / Input 2nd character
STA WRD / Store both characters 1st Char 2nd Char
HLT
WRD, -- / Two characters stored here

Problem 6-25: Write a program to unpack two characters from location


WRD and store them in bits 0 through 7 of locations CH1 and CH2. Bits
8 through 15 should contain zeros.

27
Programming the Basic Computer Input Output Program

PROGRAM INTERRUPT

Memory
Before interrupt After interrupt cycle
Interrupt cycle
0 0 256
1 0 BUN 1120 PC = 1 0 BUN 1120
Store return address
in location 0
M[0] ← PC 255 255
Main Main
PC = 256 Program 256 Program

Branch to location 1 SKI


PC ← 1 1120
BUN NEXT
1120 INP
I/O I/O
NEXT, SKO
Program Program
IEN ← 0 BUN EXIT
R←0 OUT
1 BUN 0 1 BUN 0 EXIT, ION

28
Programming the Basic Computer Input Output Program

PROGRAM INTERRUPT

Tasks of Interrupt Service Routine

- Save the Status of CPU


Contents of processor registers and Flags

- Identify the source of Interrupt


Check which flag is set

- Service the device whose flag is set


(Input Output Subroutine)

- Restore contents of processor registers and flags

- Turn the interrupt facility on

- Return to the running program


Load PC of the interrupted program

29
Programming the Basic Computer Input Output Program

INTERRUPT SERVICE ROUTINE


Loc.
0 ZRO, - / Return address stored here
1 BUN SRV / Branch to service routine
100 CLA / Portion of running program
101 ION / Turn on interrupt facility Memory
102 LDA X
103 ADD Y / Interrupt occurs here 0 return address
104 STA Z / Program returns here after interrupt 0 BUN 200
1
/ Interrupt service routine
200 SRV, STA SAC / Store content of AC Main
103 Program
CIR / Move E into AC(15) 104
STA SE / Store content of E
SKI / Check input flag 200
BUN NXT / Flag is off, check next flag I/O
INP / Flag is on, input character Program
OUT / Print character
STA PT1 I / Store it in input buffer 1 BUN 0
ISZ PT1 / Increment input pointer
NXT, SKO / Check output flag
BUN EXT / Flag is off, exit
LDA PT2 I / Load character from output buffer
OUT / Output character
ISZ PT2 / Increment output pointer
EXT, LDA SE / Restore value of AC(15)
CIL / Shift it to E
LDA SAC / Restore content of AC
ION / Turn interrupt on
BUN ZRO I / Return to running program
SAC, - / AC is stored here
SE, - / E is stored here
PT1, - / Pointer of input buffer
PT2, - / Pointer of output buffer

30
Programming the Basic Computer Input Output Program

INTERRUPT SERVICE ROUTINE


Loc.
0 ZRO, - / Return address stored here
1 BUN SRV / Branch to service routine
100 CLA / Portion of running program
101 ION / Turn on interrupt facility
102 LDA X
103 ADD Y / Interrupt occurs here
104 STA Z / Program returns here after interrupt
/ Interrupt service routine
200 SRV, STA SAC / Store content of AC Save contents
CIR / Move E into AC(15) of AC and E
STA SE / Store content of E
SKI / Check input flag
BUN NXT / Flag is off, check next flag
INP / Flag is on, input character
OUT / Print character
STA PT1 I / Store it in input buffer
ISZ PT1 / Increment input pointer
NXT, SKO / Check output flag
BUN EXT / Flag is off, exit
LDA PT2 I / Load character from output buffer
OUT / Output character
ISZ PT2 / Increment output pointer
EXT, LDA SE / Restore value of AC(15)
CIL / Shift it to E
LDA SAC / Restore content of AC
ION / Turn interrupt on
BUN ZRO I / Return to running program
SAC, - / AC is stored here
SE, - / E is stored here
PT1, - / Pointer of input buffer
PT2, - / Pointer of output buffer

31
Programming the Basic Computer Input Output Program

INTERRUPT SERVICE ROUTINE


Loc.
0 ZRO, - / Return address stored here
1 BUN SRV / Branch to service routine
100 CLA / Portion of running program
101 ION / Turn on interrupt facility
102 LDA X
103 ADD Y / Interrupt occurs here
104 STA Z / Program returns here after interrupt
/ Interrupt service routine
200 SRV, STA SAC / Store content of AC
CIR / Move E into AC(15)
STA SE / Store content of E
SKI / Check input flag
BUN NXT / Flag is off, check next flag
INP / Flag is on, input character
OUT / Print character Check I/O flags,
STA PT1 I / Store it in input buffer Service I/O device
ISZ PT1 / Increment input pointer
NXT, SKO / Check output flag
BUN EXT / Flag is off, exit
LDA PT2 I / Load character from output buffer
OUT / Output character
ISZ PT2 / Increment output pointer
EXT, LDA SE / Restore value of AC(15)
CIL / Shift it to E
LDA SAC / Restore content of AC
ION / Turn interrupt on
BUN ZRO I / Return to running program
SAC, - / AC is stored here
SE, - / E is stored here
PT1, - / Pointer of input buffer
PT2, - / Pointer of output buffer

32
Programming the Basic Computer Input Output Program

INTERRUPT SERVICE ROUTINE


Loc.
0 ZRO, - / Return address stored here
1 BUN SRV / Branch to service routine
100 CLA / Portion of running program
101 ION / Turn on interrupt facility
102 LDA X
103 ADD Y / Interrupt occurs here
104 STA Z / Program returns here after interrupt
/ Interrupt service routine
200 SRV, STA SAC / Store content of AC
CIR / Move E into AC(15)
STA SE / Store content of E
SKI / Check input flag
BUN NXT / Flag is off, check next flag
INP / Flag is on, input character
OUT / Print character
STA PT1 I / Store it in input buffer
ISZ PT1 / Increment input pointer
NXT, SKO / Check output flag
BUN EXT / Flag is off, exit
LDA PT2 I / Load character from output buffer
OUT / Output character
ISZ PT2 / Increment output pointer
EXT, LDA SE / Restore value of AC(15) Restore contents
CIL / Shift it to E of AC and E
LDA SAC / Restore content of AC
ION / Turn interrupt on
BUN ZRO I / Return to running program
SAC, - / AC is stored here
SE, - / E is stored here
PT1, - / Pointer of input buffer
PT2, - / Pointer of output buffer

33
Programming the Basic Computer Input Output Program

INTERRUPT SERVICE ROUTINE


Loc.
0 ZRO, - / Return address stored here
1 BUN SRV / Branch to service routine
100 CLA / Portion of running program
101 ION / Turn on interrupt facility
102 LDA X
103 ADD Y / Interrupt occurs here
104 STA Z / Program returns here after interrupt
/ Interrupt service routine
200 SRV, STA SAC / Store content of AC
CIR / Move E into AC(15)
STA SE / Store content of E
SKI / Check input flag
BUN NXT / Flag is off, check next flag
INP / Flag is on, input character
OUT / Print character
STA PT1 I / Store it in input buffer
ISZ PT1 / Increment input pointer
NXT, SKO / Check output flag
BUN EXT / Flag is off, exit
LDA PT2 I / Load character from output buffer
OUT / Output character
ISZ PT2 / Increment output pointer
EXT, LDA SE / Restore value of AC(15)
CIL / Shift it to E
LDA SAC / Restore content of AC Turn Interrupt
ION / Turn interrupt on facility on
BUN ZRO I / Return to running program
SAC, - / AC is stored here
SE, - / E is stored here
PT1, - / Pointer of input buffer
PT2, - / Pointer of output buffer

34

You might also like