Instruction Guide: Microprocessors

Note: This lesson in common to both the NXT and EV3 versions of STEM Robotics 101.

This lesson delves into the technology behind microprocessors. Students learn how incredibly fast microprocessor hardware runs, how tedious microprocessor software can be, and how the two combine to give amazing results.

Start by watching this Code.org "Hardware and Software" video.

Review the Microprocessors worksheet  with students before watching the Intel Video: "Microprocessors".

Have student take notes during video

Note: some answers on the worksheet come from the subsequent PowerPoint presentation and discussion

Hardware (use Microprocessor PPT file: slides 1-3)

If you have a demo computer, show the students the microprocessor on the motherboard

The goal is to show students the microprocessor is the silicon chip hidden under cooling components

Slide 1: Locate the packaged chip under the cooling apparatus

  • Cooling system is different in every computer
  • Usually consists of a heat sink and fan combination
  • The microprocessor is in the package connected directly to motherboard

Slide 2: Locate the silicon chip inside the package

  • The package protects the chip and provides a means to connect the inputs and outputs on the silicon chip to the metal pins on the package
  • Through these package pins, the microprocessor silicon is connected by the metal traces (wires) on the motherboard to all the other parts of the computer
  • All the microprocessor workings are on the silicon chip

Slide 3: Locate the microprocessor units on the silicon chip

  • All the units are made of transistors and wires. The transistors act as both switches and loads, while the wires are the conducting paths and distribute the power supply (remind students of the four parts of a circuit – and that a computer chip is an “integrated circuit”)
  • Transistors that work together are clustered adjacent to each other in units:
    • The Fetch Unit finds the next instruction to be used in an area of memory called the instruction cache
    • The Decode Unit interprets this instruction, determines which operations and data are being called upon, and passes this information to the appropriate part of the Execution Unit
    • The Execution Unit carries out the operation called for, and controls the flow of the next instruction
  • The sequence of Fetch/Decode/Execute is repeated continuously

Software (use Microprocessor PPT file: slides 4 & 5)

The goal is to show students how “stupid” microprocessors actually are (their perception is usually the opposite -–microprocessors are extremely smart: look at all the amazing things they can do)

Slide 4: Microprocessors are very simple minded

  • They can only understand VERY simple instructions – only 1’s and 0’s
  • They understand VERY few instruction – like having a vocabulary of only a couple of hundred words
  • They are VERY picky about how instructions are worded – this is called syntax
  • As a results, instructions for a microprocessor are VERY tedious

Slide 5: Machine language vs higher level languages

  • Machine language is the 1’s and 0’s level instructions that a microprocessor can understand
  • Most programming is done in higher level languages and then it is compiled into machine language in a separate step, before it is given to the microprocessor
  • Java, C and BASIC are some higher level languages students may have heard of
  • NXT-G is a very high level language – it is compiled into the NXT’s machine language automatically every time a program is downloaded into the NXT
    • Note: This is why a program cannot be uploaded from the NXT brick to the computer. This would require a reverse compiler, which does not exist. As a result, students always need to save changes to their programs on the computer – if a program on the brick is erased/lost on the computer, there is no way to get it back on the computer (even though it may be running just fine on the brick)

Microprocessor Labs

Print material supplies for the Microprocessor Labs are located here

Hardware Lab

Supplies

  • Two copies of pages 3 – 18 in the Lab supplies doc
  • One copy of page 19 in the Lab supplies doc
  • One recipe card holder (or similar size box)

Supply Preparation

  • Fold each copy for pages 3 – 18 in half, so that the 10 lines of gibberish are on the inside on one half of the sheet
  • Fold each again sheet again in the opposite direction
  • Each set of pages 3 – 18 contains four groups of four sheets each with the word “addition”, “subtraction”, “multiplication” or “division” hidden within the 10 lines of gibberish
  • Use page 19 as your guide to mark up the sheets
  • Use the 16 “Challenge Series” or the 16 “Easy Series” questions from page 19 depending on the level of your students
  • For one set of 16 sheets, write the appropriate equation on the inner most portion of the sheet and the corresponding line number on the outside (when folded).
    • For example, on the Challenge set, starting with the first line on page 19, select a “multiplication” gibberish sheet and write “48” on the outside (when completely folded) and “14*6=” on the innermost page when completely unfolded.
  • On the second set of 16 sheets, write any number on the outside that does not appear in your selected answer set (93, 11, 26, etc.). This set is used as “distracters” in the card box, so there is no need to write an equation on the inside.

Student Preparation (use Microprocessor PPT file: slides 6 -10 )

  • Tell students they are going to act out the Microprocessor Hardware role-play they saw in the video
  • Assign students to the roles a “Fetch”, Decode” and “Execute”. Fetch and Decode should be one person each. Execute can be two to four students depending on the class size (if less than four, double up “addition”, “subtraction”, “multiplication” or “division” roles)
  • Slide 6: Fetch’s job is to search through the recipe box (our instruction cache) and find the required instruction sheet. To start the Lab, the teacher will call out one of the numbers from page 19
  • Slide 7: Fetch hands the folded instruction to Decode, who opens it up to find 10 lines of gibberish
  • Slide 8: Decode opens the sheet one fold and decodes the gibberish to find the word “addition”, “subtraction”, “multiplication” or “division”. Once found, Decode hands the sheet to the appropriate person in Execute who handles that type of mathematical operation
  • Slide 9: Execute opens the sheet one fold and proceeds to solve the math question. Once solved, Execute yells out the answer. (The teacher should use sheet 19 to ensure the correct answer is given before proceeding)
  • Slide 10: As soon as Fetch hears the number called by Execute, Fetch immediately begins looking for that number instruction.

Running the Lab

  • Someone should time the Lab and stop after a pre-determined number of instructions (usually at least 4)
  • Given 16 questions, the Lab can be run several times. Be sure to record the fastest time/team
  • Note: Each unit must do their own work without help from others. After all, the transistors in the Fetch Unit cannot help the transistors in the Decode Unit.

Software Lab

Supplies

  • Several copies of page 2 (one per software team)
  • Peanut Butter in jar (or Nutella,or butter, if allergies are an issue), Jam in Jar, Bread in bag with plastic twist seal, Plate, Knife, Spoon and Desk

Supply Preparation

  • Ensure jar lids can be opened easily and that bread bag can be opened grasping bag with one hand and twisting the seal with the other hand
  • Note: if peanut allergies are an issue, the material can be modified to create a “Butter and Jam Sandwich Processor”

Student Preparation ((use Microprocessor PPT file: slides 11 & 12 )

  • Tell students they are going to write machine language instructions for a very special processor: The Peanut Butter and Jam Sandwich Processor (a.k.a. the teacher)
  • Like any processor, the PB&JSP has a syntax which it adheres to strictly
  • Each instruction must consist of a Register, a Command and a Resource (in that order)
  • The processor only recognizes two Registers, four Commands and 13 Resources
  • The processor will crash if any words other than these are used
  • The processor will crash if any instruction does not follow the syntax
  • The processor will crash if any instruction conflicts with previous instructions
  • The processor will crash if any instruction cannot be carried because a required preceding instruction was omitted
  • All instructions must be in written down and read verbatim by the student – abbreviations may be used
  • Slide 12 contains two sample instruction to give students a feel for the syntax

Running the Lab

  • To prevent students from making corrections on-the-fly, have the student who is reading the instructions face away from the processor, or have another team read the instructions
  • Cycle through the teams quickly – as soon as faulty instruction is encountered, have that team sit down and work on a fix, while another “runs their code”.
  • Run as many iterations as desired. The goal is to have student realize that something as intuitive to them as making a sandwich is very tedious to accomplish in the simple and limited machine language of a processor.

Lab Analysis

Hardware

  • Have the fastest team exercise their bragging rights
  • Use the fastest time to calculate how many seconds per instruction the team performance represented (typically 30 to 50 sec/instr)
  • Scenario: Your fastest Hardware Lab Team comes to school and does fetch-decode-execute every class, all day long (6 hours per day). Have students guess how long they think this team would take to complete what a modern processor can do in just one second.
  • A well written program can run at roughly 1 instr/cycle on a modern microprocessor
  • A modern Quad Core Microprocessor can run at 3.3GHz (3,300,000,000 cycles per second) with each core (a complete processor) running independently.
  • So modern processor can run 13,200,000,000 instr/sec (3.3G x 4)
  • Solution: assuming fastest team is 40 sec/instr, 216,000 sec/school day, 175 school days per year, ~~ 140,000 years!!! And that was the fastest team!
  • Modern processors execute instructions at incredible speeds.
  • This is the “faster” part of Moore’s Law’s “Better, Faster, Cheaper” (see Moore's Law lesson)

Software

  • Every member of every software team knew how to make a peanut butter and jam sandwich, so ask them why the Lab was so challenging?
  • You should get passionate responses that fall into one of the three “very” categories from the PPT – Very Simple Instructions, Very Few Instructions, and Very Precise Instructions
  • Explain that with more time and effort (and much debugging and tweaking), students could come up with about 60 instruction that would do the job.

Conclusion

  • Although it would take a lot of work to get the 100 or so instruction correct, if the Peanut Butter & Jam Sandwich Processor ran as fast as a modern Quad Core Processor, you could make 132 million sandwiches every second! (3.3G x 4 / 100)
  • This is the magic of microprocessors: For software engineers they are tediously, annoyingly and frustratingly “stupid”, BUT, they are incredibly (almost inconceivably) fast.
  • Microprocessor’s make up for their “stupidity” with their speed – and perform all the amazing feats we have come to appreciate and depend upon.