go to previous page   go to home page   hear noise   go to next page

Answer:

Yes. Programs and data are both in main memory when they are active.


Example of Machine Language

toothbrush

Let us say that an electric toothbrush has a processor and main memory. The processor can rotate the bristles left and right, and can check the on/off switch. The machine instructions are one byte long, and correspond to the following machine operations:

Machine InstructionMachine Operation
0000 0000Stop
0000 0001Rotate bristles left
0000 0010Rotate bristles right
0000 0100Go back to start of program
0000 1000Skip next instruction if switch is off

Here (let us pretend) is the main memory for the toothbrush system:

AddressMachine Instruction
0
1
2
3
4

The toothbrush is wired so that when the switch is first turned on the instruction at address zero is performed. Then, instructions are performed one at a time, in order, until the "Stop" instruction is encountered.

The "Skip" instruction checks the on/off switch and skips over one instruction if the switch is "off".

The "Go back" instruction causes the processor to start again with the instruction at address 0.

You want a program for the toothbrush. The bristles should repeatedly move back and forth, left and right, while the switch is on. When the switch is moved to "off" the bristles should stop moving.


QUESTION 4:

Fill in main memory starting at address 0 with the machine instructions to control the toothbrush. Copy and paste from the list of machine instructions.

(Please take the time to do this. If you do, you will be able to tell people that the first program you ever wrote was for an electric toothbrush. You do not want to pass up this opportunity.)