Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science Illuminated Programming: Controlling the Hardware.

Similar presentations


Presentation on theme: "Computer Science Illuminated Programming: Controlling the Hardware."— Presentation transcript:

1 Computer Science Illuminated Programming: Controlling the Hardware

2 Two Conceptual Computers n The ROBOT Computer –Domain: a room surrounded with walls which may or may not contain doors; the floor is composed of squares like a chess board; there are no obstructions in the room; the dimensions of the room are unknown –Movement: the Root always occupies one and only one square; if the Robot takes a step it stops in the next consecutive square it is facing; if the Robot turns it remains in the same square; the Robot’s arm (when extended) will occupy the square directly in front of the Robot; the Robot’s movements are controlled by a program –Language: the Robot programming language has only eight instructions; all but one instruction has a physical response from the Robot; all but one instruction have no operand

3 The Robot Instruction Set n 000 Step move forward one square n 001 Turn turn 90 degrees to the right n 010 Raise raise the Robot’s arm if possible n 011 Lower lower the arm if it was raised n 100 Sense [we aren’t going to use this] n 101 Goto change order of instruction execution n 110 Light turn off the Robot’s light n 111 Stop the Robot turns off its power

4 The Robot Instruction Set n Notes on usage: Instructions are executed sequentially from the Robot’s memory, unless a GOTO instruction changes the order of execution If the Robot attempts to raise its arm and cannot (due to an obstruction), its light will turn on and instruction execution will be ignored. If the Robot’s light is on, the only instruction it will not ignore is the LIGHT instruction, which will turn off the light and resume normal instruction execution.

5 The Robot Operation n The Robot can only do what it is instructed to do n The Robot has a memory into which programs are loaded n There are only 32 memory locations 0 – 31 n The Robot instructions must be specified in binary n The Robot will fetch instructions sequentially n When the Robot decodes an instruction it will know what to do based on the opcode n When the Robot executes an instruction there will be an observable action.

6 A Robot Program n What would a program look like to make the Robot walk to the wall and stop? StepStepStepStepStop n Will this program get the Robot to the wall and make it stop? n Assume the Robot is positioned as shown and facing the bottom

7 A Robot Program n Will the program work if the Robot is positioned as in Fig 1? Why or why not? n Will the program work if the Robot is positioned as in Fig 2? Why or why not? n What needs to happen to the program so that it will work no matter where the Robot is placed in the room? n How can we make the Robot “aware” of its surroundings? Fig 1 Fig 2

8 A Robot Program n We need to use the Robot’s arm to check out the square that is in front of it 00000 Raise 00001 Lower 00010 Step 00011 Goto 00000 00100 Light 00101.... The above sequence creates a “loop” back to location 00000 from location 00011. What will make the loop stop?

9 A Robot Challenge n Have the Robot find a corner and stop 00000 Raise 00001 Lower 00010 Step Walk to 1 st wall 00011 Goto 00000 00100 Light 00101 Turn Head towards second wall 00110 Raise 00111 Lower 01000 Step Walk to 2 nd wall 01001 Goto 00110 01010 Light 01011 Stop Stop

10 2 nd Conceptual Computer n The Pencil & Paper Computer –Domain: the primary domain of the P&P computer is contained within the CPU and RAM; input and output capabilities are provided to allow the user to interact with the P&P computer; the primary function of the P&P computer is to manipulate numbers –Operations: all operations take place in the accumulator or in memory; input and output devices share a common area on the screen allowing the user to communicate with the P&P computer; changes are subtle –Language: the P&P programming language has only eight instructions; all but one instruction has an operand

11 The P&P Instruction Set n 000 Stop stop executing the program n 001 Add add the contents of memory to accumulator n 010 Sub subtract the contents of memory from accumulator n 011 Load load the contents of memory into accumulator n 100 Store place a copy of accumulator into memory location n 101 Read obtain a value from keyboard and store it in memory n 110 Print display the contents of a memory location n 111 Pjump jump to specified memory location if accum > 0

12 The P&P Instruction Set n Notes on usage: Instructions are executed sequentially from the P&P’s memory, unless a PJUMP instruction changes the order of execution Subtracting a one from a zero will produce a negative number which looks like a very large positive number If the accumulator is not zero, the PJUMP instruction will always “jump”. This includes negative numbers. The only way a PJUMP will “fall through” is if the accumulator is equal to zero.

13 The P&P CPU Operation n The P&P Computer can only do what it is instructed to do n The P&P Computer has a memory into which programs and data are loaded n There are only 32 memory locations 0 – 31 n The P&P instructions are specified in assembly n The P&P Computer will fetch instructions sequentially n An assembler will convert the source program to binary n When the P&P Computer executes an instruction all observable actions occur in the accumulator or memory

14 A P&P Program n Assume you want to read in two numbers and add them together, displaying the result at the end Read A Read A Read B Read B Load A Load A Add B Add B Store C Store C Print C Print C Stop Stop n Memory locations have to be reserved to “hold” A, B, and C n The “read” and “print” instructions take care of converting to and from binary

15 A P&P Challenge n Multiply two numbers together –3 X 5 is the same as 3 + 3 + 3 + 3 + 3 Num1: 0 Num2: 0 Answer: 0 One: 1 Read Num1 Read Num1 Read Num2 Read Num2 Loop: Load Answer Add Num1 Add Num1 Store Answer Store Answer Load Num2 Load Num2 Sub One Sub One Store Num2 Store Num2 Pjump Loop Pjump Loop Print Answer Print Answer Stop Stop


Download ppt "Computer Science Illuminated Programming: Controlling the Hardware."

Similar presentations


Ads by Google