• Keine Ergebnisse gefunden

1 }NOT EXECUTED

4. RDI 5. WDB

5. Analyze the following program. Give the written output that would be printed after the program has run. If you have trouble, go to the computer, load the program and run it. Be sure and turn the teletype to "line" when running the program.

Memory Symbolic Remarks Location

00,01 OCD 10 Sets Alpha Mode

02,03 LCI 09 One less than what is to be printed 04,05 WDB 10 Write Data

06,07 LCI OD One less than what is to be printed 08,09 WDB 1F Write Data

OA,OB BST 00

ASCII CHARACTER HEX

CODE

10 CARRIAGE RETURN 8D

11 LINE FEED OA

12 T D4

13 H 48

14 1 C9

15 S 53 What will this

16 Space AO program print

17 I C9 out?

18 S 53

19 Space AO

1A F C6

1B U 55

1C N 4E

1F A 41

20 Space AO

2i T D4

22 E C5

23 S 53

ASCII CHARACTER HEX CODE

24 T D4

25 Space AO

26 P 50

27 R D2

28 0 CF

29 G 47

2A R D2

2B A 41

2C M 4D

6. Match the following instructions with their functions.

__ ~_lUsed to manually input information through the Input Register.

l . 2.

3.

4.

5.

Used to check the status of the selected I/O device.

Used to move data from the specified memory location into the next memory location.

Will cause a change in the sequence of the program if the Carry flip-flop is clear.

LCC SST BNC MNI MNO,

PROCEDURES FOR WRITING PROGRAMS

In this section you will learn basic techniques used in developing a program for the machine to use. There are distinct steps which you must go through to write a program.

You will learn these steps and use them.

Before you get started there are some terms you need to know. These will be used throughout the remainder of the block. As they are used they will be explained, but here is a quick definition of some of the terms.

Instruction A code that the computer can decode, and because of it, can perform a preset sequence of events.

Program A .·sequence of instructions that perform a specific job to reach the desired end.

Subroutine Flow-Chart

A sequence of instructions that performs a specific task of a job. Sub-routines are used within programs.

A diagram that visually shows what needs to be done within the program to get a job done.

There are seven distinct steps involved in writing a program. You will not always do all seven steps on paper. Some of these steps will be done mentally. In fact,

104

sometimes you may not even realize that you did the step. Each step is performed whether you realize it or not. The first step is to analyze the problem.

Analyzing the problem is usually the most difficult part of writing a program. If it is done properly the other six steps will be easy.

This step involves finding out exactly what the desired results of the program are to be. We all know that we want our answer, but do we want it printed out, and, if so, in what format? Is our answer going to be used by other programs? If so, where are we to put our answer so the other programs can find it? Questions like these must be answered. Also in this step, we must determine what we have to work with. If we are to design a building, we must be told the number of rooms, the length of each wall, and the height of the building. We've got to find out what is known in our problem. We must also determine where these knowns are stated, or if they are going to come from I/O device, such as the Teletypewriter.

A good understanding of the problem is a must in determining how to solve it.

Let it be noted now that a program is never written for just one situation. You never write a program that is to be used only once. It would be ridiculous to write a program that will take the square root of 37. It would not be so ridiculous to write a program that will take the square root of any number. After a programmer has taken all the time to figure out how to solve the problem, he will have the answer for any value to the one time program. By the time the program is ,written he will know the square root of 37. If the program, however, will find the square root of any number, and you do not know the square root of all numbers, then the program has value.

The programs and programming problems that you will have in this course are to help teach you what the machine is doing and how it does it.

The second step in writing a program is to select a method to solve the problem.

This means that the programmer must figure out how he can take the knowns or the given information,' and come up with the desired answer. He must be able to work the problem himself. That does not mean he must be a mathmatician or an engineer, but simply means he must be able to look at the formula and determine what it takes to do that formula.

There is normally a number of different ways to solve a given problem. The programmer must be able to look at the problem and determine which way is the best way.

After this has been 'determined, the programmer will go on to the third step. This step is t? develop a flow chart. A flow chart is a pictoral representation of how you are going to solve the problem. In flow charting there are a few basic symbols you will need to know. These are not all of the symbols, but these are the major ones.

A rectangle is used to show an action that is to take place. This action ~ight be adding two numbers, or reading something from the teletypewriter, or taking something out of memory.

The symbol looks like this. ~

Another symbol we will use is a diamond~

This will be used to show when a question is to be asked and the different paths that can be followed depending on the answer to the question. It is called a decision block.

105

The next symbol is an oval. It is called a terminal symbol and it is used to show starting and stopping points of the program.

( )

Last is the connector symbol.

c=)

This symbol is used when it would be confusing to draw a line or when you go from one page to the next. Label the connector out and the connector in the same way to show that these points are the same. An example of a flow chart using these symbols is shown below.

ADD 1 TO COUNTER ON

BOYS

A

ADD 1 to COUNTER ON

GIRLS

RDA26-444

Remember, a flow chart is a programmer's tool. How detailed the flow chart is depends on the programmer, but the more detailed it is the easier it will be to write the program.

The fourth step in writing a program is to write the program. Using the flow chart, the programmer must write the instructions that will cause the action the flow chart describes. For us this means write the program using the symbolic name for the instruc-tions that the COM-TRAN TEN uses. You can see that the more detailed the flow chart the easier this s,tep will be.

The fifth step is to put the symbolic coding into machine language. This is usually, done by the programmer putting his symbolic program on punched cards and letting the computer code it into machine langugage for him, but, in our case, we will do this by looking up the hexadecimal code for each instruction.

The sixth step is to test the program. Here you will load the program into memory and run it to see if it gives the correct answer. This means that you will have to use' known values so you will know what the answer is supposed to be.

106

In the event that the program does not run correctly ,the first time, you will have to . perform the seventh step in writing a program; revise if necessary. Look at the results

your program gave you and find out why they are wrong. Change the program to make the results correct. In complicated programs, this step may be done several times before a good working program is finished.

You have just gone through the seven basic steps in writing a program. After learning , some instructions, we will go through these steps again.

These seven steps are used regardless of the computer programming language used.

Steps 4 and 5, writing the program and coding it, will differ from one machine to the next and from one language to the next.

PROGRAMMING PROBLEM

Using a branching program, generate a total sum for the contents of memory location 100 through 108. Check the sum to see if even or odd. If odd, store in memory location 350 and if the sum is even, store it in location 351.

a. What are the knowns and unknowns?

b. What general method are you going to use--to solve the problem?

c. Construct a flow chart.

d. Call the instructor to check your work.

e. Write the program; then code the program for loading in the COM-TRAN TEN Computer.

f. Call the instructor to check your work. , __________ __

108

60 ADD,m,x

NUMERICAL

SUMMARY OF INSTRUCTIONS

00 SST,k Sense status 60 ADD,m,x ADD

8-bit status word + ACC (ACC)

+

(m) + (ACC) 01 LCI,k Load COUNTDOWN immediate 68 SUB,m,x SUBtract

k + (C) (ACC) - (m) + (ACC)

02 LAI,.k Load ACCUMULATOR immediate 70 MPY,m,x Multiply

k + (ACC) (ACC)

*

(m) + (AQ)

03 INX,k Increase INDEX 78 DIV,m,x DIVide

(INDEX)

+

k + (INDEX) (AQ) f (m) + (Q)

08 SKI,k Skip on INTERrupt remainder + (ACC)

k instructions 80 RAO,m,x Replace ADD One

09 SKS,k Skip on SENSE (m)

+

1 + (m)

k instructions 88 RSO,m,x Replace Subtract One

OA SKF,k Skip on FLAG (m) - 1 + (m)

k instructions 90 BUN,m,x Branch UNconditional

OB SLA,k Shift LEFT Arithmetic m + (PA)

(AQ) to left k places 98 BST,m,x Branch & Stop 10 SRA,k Shift RIGHT Arithmetic m + PA & STOP

(AQ) to right k places AO BSB,m,x Branch to Subroutine

11 OCD,k Output Command 90 (BUN) + (m)

k + external device (PA) + (m

+

1)

12 LXI,k Load INDEX immediate (m

+

2) + (PA)

k + (INDEX) A8 BPS,m,x Branch on Positive

13 SLL,k Shift LEFT Logical >0 + m + (PA)

(ACC) to left k places BO BZE,m,x Branch on Zero

18 SRL,k Shift RIGHT Logical

=

0 + m + (PA)

(ACC) to right k places B8 BNG,m,x Branch on Negative

1A IOR,k Inclusive OR <0 + m + (PA)

k OR (ACC) + (ACC) CO BNC,m,x Branch on No Carry

19 AND,k AND CARRY

=

0 + m + (PA)

k AND (ACC) + (ACC) C8 BXZ,m,x Branch on INDEX Zero

1B XOR,k Exclusive OR (INDEX)

=

0 + m + (PA)

k EOR (ACC) + (ACC) DO WDB,m,x Write Data Block

20 LDA,m,x Load ACCUMULATOR (m) + external device

(m) + (ACC) D8 MNO,m,x Manual Output

28 FLC,k FLAG clear (m) + (INPUT) & (BUFFER)

o

+ FLAG bit EO RDB,m,x Read Data Block

30 LCC,m,x Load Consecutive Data + (m)

(m) + (m

+

1) E8 RDI,m,x Read until Interrupt 38 LAN,m,X Load ACCUMULATOR Negative Data + (m)

- (m) + (ACC) FO MNI,m,x Manual Input

40 . LDQ,m,x Load QUOTIENT register (INDEX) & (BUFFER) + (m)

(m) + (QUO) F8 FLS,k FLAG Set

48 STA,m,x Store ACCUMULATOR 1+ FLAG bit

"(ACC) + (m) 50 STX,m,x Store INDEX

(INDEX) + (m) 58 STQ,m,x Store QUOTIENT

(QUO) + (m)

110

MEM(IIRY

PAGE = 1 2 3

o

1 2

INDEXED

= x x x

LSD+O 1 2 3 4 5 6

MSD t

o

SST LCI LAI INX INVALID INST 1 SRA (IICD LXI SLL INVALID INST

C(IIM-TRAN TEN INSTRUCTI(1IN REPERT(IIIRE

3

o

1

x

7 8 9