Machine Language Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

The embedded control program for the dental appliance is given below.

Machine Language Program

There are at least two sensible programs for the toothbrush. Here is one program:

AddressMachine InstructionMeaning
0 0000 0001 Rotate bristles left
1 0000 0010 Rotate bristles right
2 0000 1000 Skip next instruction if switch is off
3 0000 0100 Go back to start of program
4 0000 0000 Stop running

In the electronic memory of the toothbrush the program is stored as a sequence of bits:

0000 0001 0000 0010 0000 1000 0000 0100 0000 0000 

The processor starts at the beginning and performs the action described by each code. This is, of course, a silly example. Electric toothbrushes are not controlled by computer processors. And, the machine instructions of actual processors are much more detailed. But the essential ideas of the example are these:

  • A machine language program is a sequence of machine language instructions in main memory.
  • A machine instruction consists of one or more bytes (in the example, only one).
  • The processor runs a program one machine instruction at a time.
  • All the little machine operations add up to something useful.

If toothbrush user leaves the switch "on" for a while, the program repeats its operations many times. This is how most programs in real computers run — many little operations add up to a useful function, which is then repeated many times.

QUESTION 5:

Will the electric toothbruch stop immediately when the switch is turned off? (Follow through the program to see if this happens.)