1 ROBOT Computer and its Programs. 2 Key Concepts n Some important concepts: Computers are not able to do anything with the data they have stored until.

Post on 22-Dec-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

1

ROBOT Computer and its Programs

2

Key Concepts

Some important concepts:• Computers are not able to do anything with the data they have

stored until they are given instructions for processing it.

• All data that computers contain and manipulate must be in binary form.

• The only thing a computer understands is binary

• Computer instructions must be performed sequentially, in the order presented.

• Every instruction in a program must have one meaning.

3

Key Concepts

Concepts continued:• Computer instructions are divided into two parts: operation

code (opcode) and operand.

• In every language, there are commands that make no use of the operand part of an instruction. (STOP)

• Programs, written in any language, are translated into binary form by assigning a numeric form to each instruction, then converting each numeric value to its binary equivalent.

• Once a program is expressed in binary form, the computer can use it directly. (Machine language program)

Opcode Operand

4

Conceptual Computers

Robot Computer • Using a conceptual computer allows us to strip away the

complexity,

• We see the underlying simplicity of operation.

5

ROBOT

• ROBOT Each stores a program in its own memory.

• ROBOT executes instructions sequentially.

• ROBOT has very limited capabilities. (small memory and instruction set.)

6

The ROBOT Computer

The ROBOT’s domain• The room is empty.

• The room is rectangular.

• The floor is paved with square tiles

• The size of the room is unknown to us at any given time.

• The size of the room does not change during the execution of a program.

7

The ROBOT Computer: Programs and Algorithms

Hardware: Defining ROBOT Capabilities• Limitations:

– The ROBOT has no eyes: Can’t see its surroundings.

– The ROBOT has no numerical capacity: Can’t count the number of squares before it reaches a wall.

8

The ROBOT Computer: Programs and Algorithms

Hardware Features:• Locomotion:

– Forward motion from one square to an adjacent square within its domain (STEP).

– Pivot: Only to the right, 90 degrees to the Right (TURN).

• Arms (two - one at each side)– Can be raised (RAISE) and lowered (LOWER).

– Extension: arms reach to the far side of the next square.

– ROBOT also senses a wall if instructed to RAISE its arms and a wall is directly in front of the ROBOT.

9

Robot Memory

Hardware: ROBOT’s Memory:

• 32 memory locations numbered 0 to 31.

• Each memory location holds one ROBOT instruction

• Each instruction is 8 binary digits (Each bit is either On = 1 Off = 0)

10

The ROBOT Computer: Programs and Algorithms

Hardware: ROBOT’s Memory:

• Located on the ROBOT’s torso.

• 32 memory locations numbered 0 to 31.

• Each memory location is a set of 8 toggle switches.

On = 1 Off = 0

• Each location is capable of storing one ROBOT instruction.

• Loading a program: setting the switches.

11

The ROBOT Computer: Programs and Algorithms

ROBOT Hardware:• Fetch: Electronic circuits cause it to fetch (or retrieve)

instructions from memory one at a time, and usually in the order in which they are stored.

• Decode: An Instruction Decoder is a set of circuits which causes the appropriate actions to be taken based on the particular binary number instruction that is received as input.

– ROBOT instructions are split into two parts.

Opcode(Command)

Operand(Address)

12

Program Instructions

ROBOT instructions are split into two parts.

Opcode(Command)

Operand(Address)

13

The ROBOT Computer: Programs and Algorithms

Software: The ROBOT’s Language.• The ROBOT has no intelligence and must have instructions

• Instructions come in the form of a program.

• The ROBOT’s language consists of seven different commands. These make up the ROBOT’s Instruction Set.

STEP RAISE TURN OFF LIGHT

TURN LOWER GOTO STOP

– These commands are used to form instructions.

– The ROBOT can store 32 instructions in its memory.

14

The ROBOT Computer: Programs and Algorithms

The ROBOT’s Instruction Set

Opcode The action taken by the ROBOT, in English:000 STEP The ROBOT takes one STEP forward if possible.001 TURN The ROBOT pivots 90 degrees to the right.010 RAISE The ROBOT raises its arms if possible. If can’t RAISE: There MUST be

a wall directly in front of the ROBOT. The ROBOT’s warning light comes on. No other commands will be recognized until the light is turned off.

011 LOWER The ROBOT lowers its arms if they are raised. 101 GOTO The ROBOT takes the next command out of normal order. The Operand,

the last 5 bits of the instruction, tells which memory location is to be performed next.

110 TURN OFF IF the light is turned on, this command turns it off. The ROBOT will again LIGHT recognize instructions in the program.

111 STOP The ROBOT shuts off its own power.

15

The ROBOT Computer: Programs and Algorithms

Problem: Cause the ROBOT to walk to the wall it is initially facing and then stop with its arms lowered and facing against the wall.

First, find the Algorithm:

• An algorithm is a step-by-step process used to solve a problem.

• The solution to the problem must be general.– Raise arms & Lower arms– See if a wall is in front of the ROBOT.– Take a step.– Repeat until a wall is found.

16

The ROBOT Computer: Programs and Algorithms

Why isn’t this a “good enough” solution to the problem of finding the wall in front of the ROBOT?

0 RAISE

1 STEP

2 GOTO 1

3 TURN OFF LIGHT

4 STOP

17

The ROBOT Computer: Programs and Algorithms

Why is this a better solution to the problem of finding the wall in front of the ROBOT?

0 RAISE

1 LOWER

2 STEP

3 GOTO 0

4 TURN OFF LIGHT

5 STOP

18

The ROBOT Computer: Programs and Algorithms

Programming the ROBOT - Taking the “English” steps and writing them in the language the ROBOT understands (Machine Language).

• Machine Language - Written in binary code, the program is in the form the computer understands.

“English” Version Machine Language Version0 RAISE 010000001 LOWER 011000002 STEP 000000003 GOTO 0 101000004 TURN OFF LIGHT 110000005 STOP 11100000

19

The ROBOT Computer: Programs and Algorithms

Loop - A sequence of instructions which is repeated one or more times when a program is executed.

Infinite loop - A set of instructions which causes the program to repeat the same commands over and over with no possible way of stopping.

20

The ROBOT Computer: Programs and Algorithms

Cause the ROBOT to walk around the perimeter of the room.

0 RAISE1 LOWER2 STEP3 GOTO 04 TURN OFF LIGHT5 TURN6 GOTO 07 STOP

Does the program ever stop? What kind of loop does this program contain?

21

ROBOT

Have ROBOT locate any corner of the room and stop there with its arms lowered.

To find a corner, ROBOT must find two walls. It needs to turn 90 degrees and repeat the process to

find the second wall.

22

FIND CORNER0 0 0 0 0 010 00000 Try to RAISE arms0 0 0 0 1 011 00000 If arms raised, LOWER arms 0 0 0 1 0 000 00000 STEP 0 0 0 1 1 101 00000 GOTO location 00000 0 0 1 0 0 110 00000 Turn off the LIGHT0 0 1 0 1 001 00000 TURN to face new wall0 0 1 1 0 010 00000 Try to RAISE arms (6) 0 0 1 1 1 011 00000 If arms raised, LOWER arms 0 1 0 0 0 000 00000 STEP 0 1 0 0 1 101 00110 GOTO location 00110 (6)

0 1 0 1 0 110 00000 Turn off the LIGHT0 1 0 1 1 111 00000 STOP

top related