Way Back When

Way-back when computers did NOT have monitors, keyboards, or compilers, the programmers wrote programs as numbers.  Executable programs (e.g. applications) still consist of numbers, but nobody actually writes these numbers any more.  Instead, a compiler changes source code into executable object code (numbers).  So we type Java commands like  System.out.println(3 + 4);, and the Java compiler translates this into machine code (actually, it isn't really "native" code for the CPU, but rather for the Java Virtual Machine.)

But... back in the 1950's, there were NO High Level Programming Languages like Java, Basic, C++, etc.   Instead, there was only machine language.  LUCKY/LAZY programmers used an assembler, so they could type assembly language mnemonics and have those translated into machine language (numbers).  This assembly translation was very direct - one assembly language command produce 1 or 2 bytes of machine code.

== Debug ==

You can try this out by using the Windows DEBUG tool.  This is a legacy tool from MS-DOS (Microsoft Disk Operating System).  

If you run debug, you will see something like this:

img1.gif

That little dash is the command prompt - so you are supposed to type something.  Maybe you'll need a hint or two.

== Storage ==

Try typing D - that stands for Display.  That displays a bunch of bytes to the screen.  Each 00 entry represents one byte of memory.  

img8.gif

The memory is the place where the computer stores data.   We can put the number 14 into the memory.
e 100 means "enter data into location 120.  Then type 14 and press [enter].
 Now memory location 120 contains the value 14.
Then put the number 35 into memory location 130.
You can type  d 100  if you want to see what's in the memory.

img10.gif

So entering numbers into the memory is no problem, except that it is time-consuming.  

== Processing ==

The most basic, useful task a computer can perform is .... COMPUTING ...  - that means calculating.  It must be possible to write a program to ADD our two numbers together.  

== Machine Language ==

First, we will do it the hard way - by typing numbers in for the commands.  These numbers are called Machine Code.  We need to enter the following numbers, starting at memory location 100.   

img11.gif

Now RUN the program by typing g (for go).  Then type d 100 to display the memory.  You will see that the program correctly added the numbers in locations 120 and 130, and stored the answer in location 140.

Try changing the data (locations 120, 130) to some other numbers, like 6 + 13.  Then type G to run the program again, and use D 100 to display the memory.

img12.gif

WOW!  It worked.  So the computer really can do arithmetic.  Try adding 15 + 37.

img13.gif

.... oops ....

== Some Bad News ==

All numbers inside computers are stored in binary - base 2.  More about that later.  But the display above is in hexadecimal (Base 16).  This is an easy translation from binary.  It is also fairly easy for people to read, so hexadecimal is a compromise between the binary stored inside the computer and the decimal numbers that people normally read.  Hexadecimal looks a lot like decimal, but not always.  And it means something quite different.  Very briefly:

So if you read the numbers above as hexadecimal numbers, the addition is actually correct.

== Assembly Language ==

The number in locations 100 ...  represent machine language commands.  The CPU (microprocessor) understands them and can execute them.  People would never try to make sense out of those numbers.  Instead, we use Assembly Language.

Assembly Language is very similar to machine code.  Each Assembly Language command translates into just a few bytes.  Below is an example of a summing loop written in assembly language.  Type a 100, then you can type assembly language mnemonics and the computer will translate them into machine code numbers.

img14.gif

The equivalent Java code is:

   ax = 0;
cx = 5;
do
{ ax = ax + cx;
cx = cx + 5;
} while (cx != 35)
mem[336] = ax;
System.exit(0);

Don't worry if you don't understand the assembly language perfectly.  But we would like to see whether it has placed the correct total in location [150].

    5 + 10 + 15 + 20 + 25 + 30 = 105 dec  ==>     69 hex  =  6 * 16 + 9  = 96 + 9  = 105.   Correct!

You can view the machine code numbers for the program by typing  u 100 :

img15.gif

== Saving the Program ==

You can save this program, but it is pretty much a waste of time, as it doesn't actually display anything.  The user won't be able to see what's in the memory anyway, and you really don't want users messing around with Debug - too dangerous!