CH6

34
1 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

Transcript of CH6

Page 1: CH6

1

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

Page 2: CH6

2

Programming the Basic Computer

INTRODUCTION

Symbol Hexa code Description

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

m: effective addressM: memory word (operand)

found at m

Introduction

AND 0 or 8 AND M to ACADD 1 or 9 Add M to AC, carry to ELDA 2 or A Load AC from MSTA 3 or B Store AC in MBUN 4 or C Branch unconditionally to mBSA 5 or D Save return address in m and branch to m+1ISZ 6 or E Increment M and skip if zeroCLA 7800 Clear ACCLE 7400 Clear ECMA 7200 Complement ACCME 7100 Complement ECIR 7080 Circulate right E and ACCIL 7040 Circulate left E and ACINC 7020 Increment AC, carry to ESPA 7010 Skip if AC is positiveSNA 7008 Skip if AC is negativeSZA 7004 Skip if AC is zeroSZE 7002 Skip if E is zeroHLT 7001 Halt computerINP F800 Input information and clear flagOUT F400 Output information and clear flagSKI F200 Skip if input flag is onSKO F100 Skip if output flag is onION F080 Turn interrupt onIOF F040 Turn interrupt off

Instruction Set of the Basic Computer

Page 3: CH6

3

Programming the Basic Computer

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)

Machine Language

Page 4: CH6

4

Programming the Basic Computer

COMPARISON OF PROGRAMMING LANGUAGESMachine Language

ORG 0 /Origin of program is location 0LDA A /Load operand from location AADD B /Add operand from location BSTA C /Store sum in location CHLT /Halt computer

A, DEC 83 /Decimal operandB, DEC -23 /Decimal operandC, DEC 0 /Sum stored in location C

END /End of symbolic program

Assembly-Language Program

000 LDA 004 Load 1st operand into AC001 ADD 005 Add 2nd operand to AC002 STA 006 Store sum in location 006003 HLT Halt computer004 0053 1st operand005 FFE9 2nd operand (negative)006 0000 Store sum here

Program with Symbolic OP-Code

000 2004001 1005002 3006003 7001004 0053005 FFE9006 0000

Hexadecimal Program

Int A,B,C;

Cin >> A;

Cin >> B;

C = A + B;

C++ Program

Program to Add Two Numbers

Page 5: CH6

5

Programming the Basic Computer

COMPARISON OF PROGRAMMING LANGUAGESMachine Language

0 0010 0000 0000 01001 0001 0000 0000 0101

10 0011 0000 0000 011011 0111 0000 0000 0001

100 0000 0000 0101 0011101 1111 1111 1110 1001110 0000 0000 0000 0000

Binary Program

000 2004001 1005002 3006003 7001004 0053005 FFE9006 0000

Hexadecimal Program

Program to Add Two Numbers

Page 6: CH6

6

Programming the Basic Computer

ASSEMBLY LANGUAGEAssembly Language

ORG 0 /Origin of program is location 0LDA A /Load operand from location AADD B /Add operand from location BSTA C /Store sum in location CHLT /Halt computer

A, DEC 83 /Decimal operandB, DEC -23 /Decimal operandC, HEX 0 /Sum stored in location C

END /End of symbolic program

Syntax of the BC Assembly Language

label

Instruction

MRI

non-MRI

comment

pseudo instruction

Page 7: CH6

7

Programming the Basic Computer

ASSEMBLY LANGUAGESyntax of the BC assembly language:

Each line of code is arranged in three columns called fields:

Assembly Language

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 instructionsNon-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

1. Label field- May be empty or may specify a symbolic address of up to 3 characters- Terminated by a comma

Page 8: CH6

8

Programming the Basic Computer

ASSEMBLY LANGUAGE

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

Assembly Language

Pseudo-instructions

Example: Assembly language program to subtract two numbersORG 100LDA SUBCMAINCADD MINSTA DIFHLTDEC 83DEC -23HEX 0END

/ Origin of program is location 100/ Load subtrahend to AC/ Complement AC/ Increment AC/ Add minuend to AC/ Store difference/ Halt computer/ Minuend/ Subtrahend/ Difference stored here/ End of symbolic program

MIN,SUB,DIF,

Page 9: CH6

9

Programming the Basic Computer

ASSEMBLY LANGUAGE

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 Instruction010 CLA011 ADD 016012 BUN 014013 HLT014 AND 017015 BUN 013016 C1A5017 93C6

Problem 6-3: List the assembly language program for the following Fortran program.

SUM = 0SUM = SUM + A + BDIF = DIF – C SUM = SUM + DIF

Page 10: CH6

10

Programming the Basic Computer

TRANSLATION TO BINARY

ORG 100LDA SUBCMAINCADD MINSTA DIFHLTDEC 83DEC -23HEX 0END

MIN,SUB,DIF,

Symbolic Program

Assembly Language

Address symbol Hex addressMIN 106 SUB 107DIF 108

Address-Symbol Table

100101102103104105106107108

107

106108

100 2107101 7200102 7020103 1106104 3108105 7001106 0053107 FFE9108 0000

Location ContentHexadecimal Code

non-MRI Table

Symbol Hexa codeAND 0 or 8ADD 1 or 9LDA 2 or ASTA 3 or BBUN 4 or CBSA 5 or DISZ 6 or ECLA 7800CLE 7400CMA 7200CME 7100CIR 7080CIL 7040INC 7020SPA 7010SNA 7008SZA 7004SZE 7002HLT 7001INP F800OUT F400SKI F200SKO F100ION F080IOF F040

MRI Table

Page 11: CH6

11

Programming the Basic Computer

ASSEMBLER - FIRST PASS -Assembler

Source Program - Symbolic Assembly Language ProgramObject Program - Binary Machine Language Program

Assembler

First pass First pass

LC ← 0

Scan next line of code

Label

Set LC

yesno ORG

no

END

yes

Store symbolin address-symbol tabletogether withvalue of LC

Increment LC

no Go tosecondpass

yes

Two pass assembler1st pass: generates a table that correlates all user defined

(address) symbols with their binary equivalent value2nd pass: binary translation

Page 12: CH6

12

Programming the Basic Computer

ASSEMBLER - SECOND PASS -

Machine instructions are translated by means of table-lookup procedures:

1. Pseudo-Instruction Table2. MRI Table3. Non-MRI Table4. Address Symbol Table

Assembler

Second pass

LC ← 0

Scan next line of code

Pseudoinstr.

Set LC

yes

ORGyes ENDno

Done

yes

MRI

no

Validnon-MRI

instr.

noyes

Get operation codeand set bits 2-4

Search address-symbol table forbinary equivalentof symbol addressand set bits 5-16

I

Setfirst

bit to 0

Setfirst

bit to 1

yes no

Store binaryequivalent ofinstructionin locationgiven by LC

yes

Error inline ofcode

no

Assemble all parts ofbinary instruction andstore in location given by LC

Convertoperandto binaryand storein locationgiven by LC

no

DEC or HEX

Increment LC

Second Pass

AddressI1 2 4 5 16

Opcode

memory word contains MRI:

Page 13: CH6

13

Programming the Basic Computer

ASSEMBLER - ExampleProblem 6-7:a. Obtain the address-symbol table generated for the

following program during the first pass of the assembler.b. List the translated program in hexadecimal.

ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

...

Symbol Hexa codeAND 0 or 8ADD 1 or 9LDA 2 or ASTA 3 or BBUN 4 or CBSA 5 or DISZ 6 or ECLA 7800CLE 7400CMA 7200CME 7100CIR 7080CIL 7040INC 7020SPA 7010SNA 7008SZA 7004SZE 7002HLT 7001INP F800OUT F400SKI F200SKO F100ION F080IOF F040

Page 14: CH6

14

Programming the Basic Computer

PROGRAM LOOPSProgram Loops

Loop: A sequence of instructions that are executed many times,each time with a different set of data

int a[100], sum, i;

sum = 0;

for (i = 0; i < 100; i++)

sum = sum + a[i];

C program to add 100 numbers:

Add 100 numbers:ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

/ Origin of program is HEX 100/ Load first address of operand/ Store in pointer/ Load -100/ Store in counter/ Clear AC/ Add an operand to AC/ Increment pointer/ Increment counter/ Repeat loop again/ Store sum/ Halt/ First address of operands/ Reserved for a pointer/ Initial value for a counter/ Reserved for a counter/ Sum is stored here/ Origin of operands is HEX 150/ First operand

/ Last operand/ End of symbolic program

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

...

Page 15: CH6

15

Programming the Basic Computer

PROGRAM LOOPSProgram Loops

Loop: A sequence of instructions that are executed many times,each time with a different set of data

Add 100 numbers:

Reserve memory for 100 operands

ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

/ Origin of program is HEX 100/ Load first address of operand/ Store in pointer/ Load -100/ Store in counter/ Clear AC/ Add an operand to AC/ Increment pointer/ Increment counter/ Repeat loop again/ Store sum/ Halt/ First address of operands/ Reserved for a pointer/ Initial value for a counter/ Reserved for a counter/ Sum is stored here/ Origin of operands is HEX 150/ First operand First operand = 75

/ Last operand Last operand = 23/ End of symbolic program

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

......

int a[100], sum, i;

sum = 0;

for (i = 0; i < 100; i++)

sum = sum + a[i];

C program to add 100 numbers:

Page 16: CH6

16

Programming the Basic Computer

PROGRAM LOOPSProgram Loops

Loop: A sequence of instructions that are executed many times,each time with a different set of data

Define program variables

ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

/ Origin of program is HEX 100/ Load first address of operand/ Store in pointer/ Load -100/ Store in counter/ Clear AC/ Add an operand to AC/ Increment pointer/ Increment counter/ Repeat loop again/ Store sum/ Halt/ First address of operands ADS = 150/ Reserved for a pointer PRT = 0/ Initial value for a counter NBR = -100/ Reserved for a counter CTR = 0/ Sum is stored here SUM = 0/ Origin of operands is HEX 150/ First operand First operand = 75

/ Last operand Last operand = 23/ End of symbolic program

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

......

Add 100 numbers:

int a[100], sum, i;

sum = 0;

for (i = 0; i < 100; i++)

sum = sum + a[i];

C program to add 100 numbers:

Page 17: CH6

17

Programming the Basic Computer

PROGRAM LOOPSProgram Loops

Loop: A sequence of instructions that are executed many times,each time with a different set of data

Initialize loop variables

ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

/ Origin of program is HEX 100/ Load first address of operand AC = ADS/ Store in pointer PTR = AC/ Load -100 AC = NBR/ Store in counter CTR = AC/ Clear AC AC = 0/ Add an operand to AC/ Increment pointer/ Increment counter/ Repeat loop again/ Store sum/ Halt/ First address of operands ADS = 150/ Reserved for a pointer PRT = 0/ Initial value for a counter NBR = -100/ Reserved for a counter CTR = 0/ Sum is stored here SUM = 0/ Origin of operands is HEX 150/ First operand First operand = 75

/ Last operand Last operand = 23/ End of symbolic program

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

...

Add 100 numbers:

int a[100], sum, i;

sum = 0;

for (i = 0; i < 100; i++)

sum = sum + a[i];

C program to add 100 numbers:

Page 18: CH6

18

Programming the Basic Computer

PROGRAM LOOPSProgram Loops

Loop: A sequence of instructions that are executed many times,each time with a different set of data

Execute loop

...

ORG 100LDA ADSSTA PTRLDA NBRSTA CTRCLAADD PTR IISZ PTRISZ CTRBUN LOPSTA SUMHLTHEX 150HEX 0DEC -100HEX 0HEX 0ORG 150DEC 75

DEC 23END

/ Origin of program is HEX 100/ Load first address of operand AC = ADS/ Store in pointer PTR = AC/ Load -100 AC = NBR/ Store in counter CTR = AC/ Clear AC AC = 0/ Add an operand to AC AC = AC + operand/ Increment pointer PTR = PRT + 1/ Increment counter CTR = CTR + 1/ Repeat loop again/ Store sum SUM = AC/ Halt/ First address of operands ADS = 150/ Reserved for a pointer PRT = 0/ Initial value for a counter NBR = -100/ Reserved for a counter CTR = 0/ Sum is stored here SUM = 0/ Origin of operands is HEX 150/ First operand First operand = 75

/ Last operand Last operand = 23/ End of symbolic program

LOP,

ADS,PTR,NBR,CTR,SUM,

...

10010110210310410510610710810910A10B10C10D10E10F

150

1B3

...

Add 100 numbers:

int a[100], sum, i;

sum = 0;

for (i = 0; i < 100; i++)

sum = sum + a[i];

C program to add 100 numbers:

Page 19: CH6

19

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 IISZ PTRISZ CTRBUN LOPHLT

:

Page 20: CH6

20

Programming the Basic Computer

LOGIC OPERATIONS

- BC instructions: AND, CMA

LDA A / Load 1st operand AC = ACMA / Complement to get A’ AC = A’STA TMP / Store in a temporary location TMP = A’LDA B / Load 2nd operand B AC = BCMA / 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’)’

Programming Arithmetic and Logic Operations

- Program for OR operation

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

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

Page 21: CH6

21

Programming the Basic Computer

SHIFT OPERATIONS

CLESPACMECIR

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

Programming Arithmetic and Logic Operations

- Arithmetic shift-right operation

CLECIR

- Logical shift-right operation

- Logical shift-left operation

CLECIL

- BC has Circular Shift only

0 0E AC

0 0EAC

AC positive

AC negative

0 0E

1 1E

AC

AC

Page 22: CH6

22

Programming the Basic Computer

SUBROUTINES

ORG 100LDA XBSA SH4STA XLDA YBSA SH4STA YHLTHEX 1234HEX 4321

HEX 0CILCILCILCILAND MSKBUN SH4 IHEX FFF0END

/ Main program/ Load X/ Branch to subroutine/ Store shifted number/ Load Y/ Branch to subroutine again/ Store shifted number

/ Subroutine to shift left 4 times/ Store return address here/ Circulate left once

/ Circulate left fourth time/ Set AC(0-3) to zero/ Return to main program/ Mask operand

X,Y,

SH4,

MSK,

100101102103104105106107108

10910A10B10C10D10E10F110

Loc.

Subroutines

- 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

Subroutine

Example: Shift the value of X and Y four times to the left

return address

0 BSA 109Next instruction

Subroutine

101102

10910A

1 BUN 109

Memory

10F

Page 23: CH6

23

Programming the Basic Computer

SUBROUTINE PARAMETERS AND DATA LINKAGE

ORG 200LDA XBSA ORHEX 3AF6STA YHLTHEX 7B95HEX 0HEX 0CMASTA TMPLDA OR ICMAAND TMPCMAISZ ORBUN OR IHEX 0END

/ Load 1st operand into AC/ Branch to subroutine OR/ 2nd operand stored here/ Subroutine returns here

/ 1st operand stored here/ Result stored here/ Subroutine OR/ Complement 1st operand/ Store in temporary location/ Load 2nd operand/ Complement 2nd operand/ AND complemented 1st operand/ Complement again to get OR/ Increment return address/ Return to main program/ Temporary storage

X,Y,OR,

TMP,

20020120220320420520620720820920A20B20C20D20E20F210

Loc.

Example: Subroutine performing LOGIC OR operation; Need two parameters

Subroutines

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

return address

0 BSA 207

Next instruction

Subroutine

201

203

207208

1 BUN 207

Memory

20F

202 3AF6

0 ISZ 207

Page 24: CH6

24

Programming the Basic Computer

SUBROUTINE - Moving a Block of Data -

BSA MVEHEX 100HEX 200DEC -16HLTHEX 0LDA MVE ISTA PT1ISZ MVELDA MVE ISTA PT2ISZ MVELDA MVE ISTA CTRISZ MVELDA PT1 ISTA PT2 IISZ PT1ISZ PT2ISZ CTRBUN LOPBUN MVE I------

/ Main program/ Branch to subroutine/ 1st address of source data/ 1st address of destination data/ Number of items to move

/ Subroutine MVE/ Bring address of source/ Store in 1st pointer/ Increment return address/ Bring address of destination/ Store in 2nd pointer/ Increment return address/ Bring number of items/ Store in counter/ Increment return address/ Load source item/ Store in destination/ Increment source pointer/ Increment destination pointer/ Increment counter/ Repeat 16 times/ Return to main program

MVE,

LOP,

PT1,PT2,CTR,

• C Functionvoid Move (int Src[], int Dest[], int N){

int i;for (i=0; i < N; i++)

Dest[i] = Src [i]}

Subroutines

MVE = address of “HEX 100”

MVE = address of “HEX 200”

MVE = address of “DEC -16”

MVE = address of “HLT“ (return address )

Page 25: CH6

25

Programming the Basic Computer

SUBROUTINES

Problem 6-22: Write a subroutine to complement each word in ablock of data. In the calling program, the BSA instruction is followedby two parameters: the starting address of the block and the numberof words in the block.

Problem 6-21: Write a subroutine to subtract two numbers. In thecalling program, the BSA instruction is followed by the subtrahendand minuend. The difference is returned to the main program in thethird location following the BSA instruction.

BSA SUBDEC -23 /SubtrahendDEC 83 /MinuendHEX 0 /DifferenceHLT

SUB, HEX 0:

BSA COMHEX 100 /1st address of blockDEC 16 /Number of items in blockHLT

COM, HEX 0:

Page 26: CH6

26

Programming the Basic Computer

INPUT OUTPUT PROGRAM

Program to Input one Character (Byte)

SKIBUN CIFINPSTA CHRHLT--

/ Check input flag/ Flag=0, branch to check again/ Flag=1, input character/ Store character

/ Store character here

CIF,

CHR,

Input Output Program

LDA CHRSKOBUN COFOUTHLTHEX 0057

/ Load character into AC/ Check output flag/ Flag=0, branch to check again/ Flag=1, output character

/ Character is "W"

COF,

CHR,

Program to Output one Character

Page 27: CH6

27

Programming the Basic Computer

CHARACTER MANIPULATION

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

SKIBUN FSTINPBSA SH4BSA SH4SKIBUN SCDINPSTA WRDHLT--

/ Input 1st character/ Shift left four times/ Shift left four more times

/ Input 2nd character/ Store both characters

/ Two characters stored here

FST,

SCD,

WRD,

Input Output Program

1st Char

15 8 7 0

1st Char

1st Char 2nd Char

AC

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.

Page 28: CH6

28

Programming the Basic Computer

PROGRAM INTERRUPT

0 BUN 112001

PC = 256255

1 BUN 0

Before interrupt

MainProgram

1120I/O

Program

Memory

After interrupt cycle

0 BUN 11200

PC = 1

256255

1 BUN 0

MainProgram

1120I/O

Program

256

SKIBUN NEXTINP

NEXT, SKOBUN EXITOUT

EXIT, ION

Store return addressin location 0M[0] ← PC

Branch to location 1PC ← 1

IEN ← 0R ← 0

Interrupt cycle

Input Output Program

Page 29: CH6

29

Programming the Basic Computer

PROGRAM INTERRUPT

- Service the device whose flag is set(Input Output Subroutine)

Input Output Program

Tasks of Interrupt Service Routine

- Save the Status of CPUContents of processor registers and Flags

- Identify the source of InterruptCheck which flag is set

- Restore contents of processor registers and flags

- Turn the interrupt facility on

- Return to the running programLoad PC of the interrupted program

Page 30: CH6

30

Programming the Basic Computer

INTERRUPT SERVICE ROUTINE

-BUN SRVCLAIONLDA XADD YSTA Z

STA SACCIRSTA SESKIBUN NXTINPOUTSTA PT1 IISZ PT1SKOBUN EXTLDA PT2 IOUTISZ PT2LDA SECILLDA SACIONBUN ZRO I----

/ Return address stored here/ Branch to service routine/ Portion of running program/ Turn on interrupt facility

/ Interrupt occurs here/ Program returns here after interrupt

/ Interrupt service routine/ Store content of AC/ Move E into AC(15)/ Store content of E/ Check input flag/ Flag is off, check next flag/ Flag is on, input character/ Print character/ Store it in input buffer/ Increment input pointer/ Check output flag/ Flag is off, exit/ Load character from output buffer/ Output character/ Increment output pointer/ Restore value of AC(15)/ Shift it to E/ Restore content of AC/ Turn interrupt on/ Return to running program/ AC is stored here/ E is stored here/ Pointer of input buffer/ Pointer of output buffer

ZRO,

SRV,

NXT,

EXT,

SAC,SE,PT1,PT2,

01

100101102103104

200

Loc.

Input Output Program

Memory

0 BUN 20001

104103

1 BUN 0

MainProgram

200 I/OProgram

return address

Page 31: CH6

31

Programming the Basic Computer

INTERRUPT SERVICE ROUTINE

-BUN SRVCLAIONLDA XADD YSTA Z

STA SACCIRSTA SESKIBUN NXTINPOUTSTA PT1 IISZ PT1SKOBUN EXTLDA PT2 IOUTISZ PT2LDA SECILLDA SACIONBUN ZRO I----

/ Return address stored here/ Branch to service routine/ Portion of running program/ Turn on interrupt facility

/ Interrupt occurs here/ Program returns here after interrupt

/ Interrupt service routine/ Store content of AC/ Move E into AC(15)/ Store content of E/ Check input flag/ Flag is off, check next flag/ Flag is on, input character/ Print character/ Store it in input buffer/ Increment input pointer/ Check output flag/ Flag is off, exit/ Load character from output buffer/ Output character/ Increment output pointer/ Restore value of AC(15)/ Shift it to E/ Restore content of AC/ Turn interrupt on/ Return to running program/ AC is stored here/ E is stored here/ Pointer of input buffer/ Pointer of output buffer

ZRO,

SRV,

NXT,

EXT,

SAC,SE,PT1,PT2,

01

100101102103104

200

Loc.

Input Output Program

Save contents of AC and E

Page 32: CH6

32

Programming the Basic Computer

INTERRUPT SERVICE ROUTINE

-BUN SRVCLAIONLDA XADD YSTA Z

STA SACCIRSTA SESKIBUN NXTINPOUTSTA PT1 IISZ PT1SKOBUN EXTLDA PT2 IOUTISZ PT2LDA SECILLDA SACIONBUN ZRO I----

/ Return address stored here/ Branch to service routine/ Portion of running program/ Turn on interrupt facility

/ Interrupt occurs here/ Program returns here after interrupt

/ Interrupt service routine/ Store content of AC/ Move E into AC(15)/ Store content of E/ Check input flag/ Flag is off, check next flag/ Flag is on, input character/ Print character/ Store it in input buffer/ Increment input pointer/ Check output flag/ Flag is off, exit/ Load character from output buffer/ Output character/ Increment output pointer/ Restore value of AC(15)/ Shift it to E/ Restore content of AC/ Turn interrupt on/ Return to running program/ AC is stored here/ E is stored here/ Pointer of input buffer/ Pointer of output buffer

ZRO,

SRV,

NXT,

EXT,

SAC,SE,PT1,PT2,

01

100101102103104

200

Loc.

Input Output Program

Check I/O flags, Service I/O device

Page 33: CH6

33

Programming the Basic Computer

INTERRUPT SERVICE ROUTINE

-BUN SRVCLAIONLDA XADD YSTA Z

STA SACCIRSTA SESKIBUN NXTINPOUTSTA PT1 IISZ PT1SKOBUN EXTLDA PT2 IOUTISZ PT2LDA SECILLDA SACIONBUN ZRO I----

/ Return address stored here/ Branch to service routine/ Portion of running program/ Turn on interrupt facility

/ Interrupt occurs here/ Program returns here after interrupt

/ Interrupt service routine/ Store content of AC/ Move E into AC(15)/ Store content of E/ Check input flag/ Flag is off, check next flag/ Flag is on, input character/ Print character/ Store it in input buffer/ Increment input pointer/ Check output flag/ Flag is off, exit/ Load character from output buffer/ Output character/ Increment output pointer/ Restore value of AC(15)/ Shift it to E/ Restore content of AC/ Turn interrupt on/ Return to running program/ AC is stored here/ E is stored here/ Pointer of input buffer/ Pointer of output buffer

ZRO,

SRV,

NXT,

EXT,

SAC,SE,PT1,PT2,

01

100101102103104

200

Loc.

Input Output Program

Restore contents of AC and E

Page 34: CH6

34

Programming the Basic Computer

INTERRUPT SERVICE ROUTINE

-BUN SRVCLAIONLDA XADD YSTA Z

STA SACCIRSTA SESKIBUN NXTINPOUTSTA PT1 IISZ PT1SKOBUN EXTLDA PT2 IOUTISZ PT2LDA SECILLDA SACIONBUN ZRO I----

/ Return address stored here/ Branch to service routine/ Portion of running program/ Turn on interrupt facility

/ Interrupt occurs here/ Program returns here after interrupt

/ Interrupt service routine/ Store content of AC/ Move E into AC(15)/ Store content of E/ Check input flag/ Flag is off, check next flag/ Flag is on, input character/ Print character/ Store it in input buffer/ Increment input pointer/ Check output flag/ Flag is off, exit/ Load character from output buffer/ Output character/ Increment output pointer/ Restore value of AC(15)/ Shift it to E/ Restore content of AC/ Turn interrupt on/ Return to running program/ AC is stored here/ E is stored here/ Pointer of input buffer/ Pointer of output buffer

ZRO,

SRV,

NXT,

EXT,

SAC,SE,PT1,PT2,

01

100101102103104

200

Loc.

Input Output Program

Turn Interrupt facility on