Computer Science 161.01

Professor Valente

 

Monday,  October 2nd        

 

Assembly Language Programming on the VSC-32 Computer

 

By now, you’ve experienced machine language programming.

So what did you think?

 

If you are like most people, you found it to be tedious, because you had to encode everything (instructions, data, addresses) into binary.error-prone, because you had to encode everything into binary (it’s easy to type 1 instead of 0).

You also found it to be cryptic, because programs don’t seem readable to humans, because (yes) they are encoded in binary.

 

Indeed, the programmers of those early digital computers in the 1940s must have had experiences similar to yours, and, if you could imagine, with larger programs!  They had to forego human like language when programming, and use binary, the language of the machine.  What they (and you) needed were languages that make more sense to humans.

 

The first development along these lines was the invention of assembly language.  As with machine language, each machine had its own assembly language.  Not surprisingly, you’ll find the VSC-32 has one as well.

 

Even when you developed a machine language program, you likely found yourself outlining how you were going to go about solving the problem and using actual words like READ, ADD, and WRITE, instead of binary codes like 011, 101, 100.  For example, in the Echo program, you probably thought of the 3 instructions needed as

READ x, WRITE x,  and STOP.   Then, convinced that x corresponded to address 3 in memory, you set about encoding the instructions:  01100011, 10000011, and 00000000 for “read into location 3”, “write what’s in location 3”, and “stop”.

 

The beauty about assembly language programming, it that we can actually enter the program READ x, WRITE x, STOP essentially as is, and the translation into binary will occur automatically.

 

Notice that we would use key words for operations, and symbolic names (such as x) for addresses.

We would have to somehow notify the translator that we wanted x associated with address 3.

We would do so by including the directive “x: DATA 0” immediately after the STOP. 

This would not only associate x with address 3 but x’s value would be initially 0 prior to having its value READ in.

 

Let’s try this out!  Enter the following VSC-32 assembly language program in the Assembly Language text area

at this web site.  Then press the Assemble button to see it translated into binary, followed by Load and Go.

 

READ x

WRITE x

STOP

x: DATA 0

 

Wasn’t that nice?

 

Note that the word Assemble means to “translate from assembly language into machine language”.

 

 

What are some of the advantages of Assembly Language programming as opposed to Machine Language Programming?

 

Well, the obvious ones we’ve noted having to do with using English like words and symbols instead of binary.

But other advantages should have occurred to you as well. 


Did you notice that you didn’t have to deal with actual addresses?

You simply used x as a label on the line after STOP, but at no time did you have to know the actual address x represented.

That worry was left up to the assembler.

 

It also is much easier in assembly language to build on an existing program to create a new one.

Thus, to do an  EchoTwo program, I could start with the Echo program I just wrote, and insert

a second READ, a second WRITE, and a second spot for DATA labeled y.

 

I do this below, again not worrying about and never making mention of actual addresses!

 

EchoTwo

READ x

READ y

WRITE x

WRITE y

STOP

x: DATA 0

y: DATA 0

 

Think about why you couldn’t simply insert  instructions into a machine language program like we just did here!

 

 

EXAMPLE:  A VSC-32 program to do EchoPlus1, which was solved in last Wednesday's notes in machine language.

 

SOLUTION:  We need to READ x, then somehow add 1 to it, STORE the answer DATA 1.

What’s a good name for that label?  How about “one”?  Why not?

Let’s try it:

 

READ x

LOAD x

ADD one

STORE result

WRITE result

STOP

x: DATA 0

one: DATA 1

result: DATA 0

 

So I have three memory locations:

One will hold the value x that we read in.

The second will have the value 1 for the program to use.

The third will hold the result and is aptly named.

 

Copy and paste (or type in) the VSC-32 program above into the Assembly Language text area at this web site.  Then press the Assemble button to see it translated into binary, followed by Load and Go.

 

 

VSC-32 Assembly Language Programming Exercises

 

  1. Solve the “reverse echo” problem in assembly language.

Enter the program and run it at this web site.

 

  1. Write a VSC-32 assembly language program to read in two numbers, sum them,

and write the result to the screen.  Enter the program and run it at this web site.

 

  1. Write a VSC-32 assembly language program to read in two numbers x and y, compute (x + y) – 5, and write the result to the screen.  Enter the program and run it at this web site.

 

  1. Write a VSC-32 assembly language program to read in one number x, compute 4x and

write the result to the screen.  Enter the program and run it at this web site.

 

  1. Study the following VSC-32 assembly language program and predict what it does!

Do so by running it in your mind for various small values of x. 

 

READ x

LOAD x

ADD x

STORE x

ADD x

STORE x

ADD x

STORE x

WRITE x

STOP

x: DATA 0

 

  1. Write a VSC-32 assembly language program to read in one number x, compute 32x, and write the result.

Note first that you should not load x, then have 31 add instructions in order to compute the result.

Why?  Instead, be creative (and efficient) and use only 5 add instructions!  (Take a hint from problem 5).

 

 

On To Wednesday!