Computer Science 161.01

Professor Valente

 

Monday September 23rd      

 

Introducing the VSC-32

 

In week 1, we were introduced briefly to the VSC-32 machine, and agreed that it was a von-Neumann machine.

Indeed it has 32 memory locations which will contain both a program’s instructions and its data. 

 

This Very Simple Computer is ridiculously simple in many ways. 

First, its limited memory is such that it cannot solve anything but small, “toy” problems, like adding two numbers and subtracting a third.

In particular, it cannot run a program that will have as many as 32 instructions nor can it have 32 data values.

So don’t expect it to sort 1000 numbers in order or to have a browser or a word-processor running on it!

 

It is meant as a teaching tool only, so that you’ll at least get a feeling of what the earliest programmers had to contend with when they were required to program at the level of the machine. 

This is called low-level programming in this case, in machine language.

When you program in machine language you enter everything in binary (or possibly hex or octal for shorthand).

 

Let’s see what binary the VSC-32 requires of us machine language programmers:

 

First, each data item is nothing more than an 8-bit unsigned integer.

As you well know, our range is therefore restricted to 0..255.

 

In general, all data items will be loaded into memory right after the program’s instructions, each of

which is 8 bits.  The program’s final instruction will always be 00000000 or STOP.

 

There are seven other types of instructions, with 3-bit codes

001 for LOAD, 010 for STORE, 011 for READ, 100 for WRITE,

101 for ADD, 110 for SUBTRACT, and 111 for JUMP.


Thus an WRITE instruction will look like 100xxxxx. 

You see that an 8-bit instruction has its left 3 bits indicating the operation

(these bits are called the opcode) and the remaining 5 bits will indicate

a memory address in the range 0..31, covering all 32 possible addresses!

 

Let’s practice some writing instructions:

1) “ADD what’s at memory address 6”.   

The 3 bit opcode for ADD is 101 and the 5 bits representing 6 are 00110.

Thus “ADD what’s at memory address 6” is simply 10100110.

 

2) “STORE at memory address 17”.

The 3 bit opcode for STORE is 010 and the 5 bits representing 17 are 10001.

Thus “STORE at memory address 17” is simply 01010001.

 

On your own, try “READ into address 4”.

 

 

OK, Let’s Program the VSC-32!

 

We’ll start with something real simple.

We’ll write a program that causes the VSC-32 to write the number 17 to the screen.

 

How many instructions will the program have?

Just two!  One to WRITE, and one to STOP.

 

The WRITE will look like 100xxxxx because 100 is the opcode for WRITE.

Remember that the xxxxx will have to be the 5 bits representing an address.

(Why is it wrong to do 10010001 as in WRITE a 17?)

 

We’ll figure out those unknown x-bits now by thinking ahead.

The two instructions (WRITE and then STOP) will be loaded into the VSC-32

main memory at the first two locations, that is, addresses 0 and 1.

 

After STOP, we can have it load the 8-bit unsigned representation of 17 into

the next available address, which is address 2.  Those 8-bits are 00010001.

 

Now, back to those unknown x-bits in the address portion of the WRITE instruction.

The 17 will be at address 2, as we just said, so the VSC-32 needs to

“WRITE what’s at address 2”.  That instruction is 10000010.

 

Thus the program is as follows:

10000010  (WRITE what’s at address 2)

00000000  (STOP)

00010001  (8-bit unsigned representation for 17)

 

Type in the 3 binary lines into the VSC-32 and see if it does what you programmed it to.

 

Exercise 1: Write a program that READs a number into a memory location and WRITEs it back to the screen.

We can call this the “echo” program because it echoes back the number the user enters.

You should develop this program carefully as we did our first, by planning ahead to figure out which

memory location will be available for you after the instructions have been loaded.

 

The echo program should consist of three instructions (READ, WRITE, STOP).

Enter it at the VSC-32 site and see if it echoes your input!

 

Exercise 2: Write a program that READs two numbers into two different memory locations

then WRITEs them back to the screen in the opposite order.  We’ll call this program “reverse echo”.

 

You should develop this program carefully as we did our first, by planning ahead to figure out which

memory location will be available for you after the instructions have been loaded.

 

The “reverse echo” program should consist of five instructions.

Enter it at the VSC-32 site and see if it “seohce esrever” your input!

(And if you don’t understand what’s in quotes, find a mirror).

 

On to Wednesday's Notes