You are on page 1of 14

4CS015 Fundamentals of Computing – Workshop-6

Workshop tasks:

1. Von Neumann Simulator. This program simulates a very simple computer with the von Neumann
architecture.

a. Download the von Neumann Simulator (VonNeumann.exe) program from WOLF in the
Week 5 folder. Save it in your Documents folder and run it. You will see a window similar
to this:

The simulator has a small program memory area which is available for programming. To
enter your program instructions simply click on the “Available” instruction on the list on the
right and then click on the “Memory” location you wish to put it in.

This simulator understands only the following ten instructions:

NOP No Operation, i.e. do nothing.


LOADTEMP Get a number from the keypad, completed
by the Enter key, into the Temporary
Register.
Get a number from the keypad, completed
LOADLOOP
by the Enter key, into the Loop Register.
CLRDISP Clear the Display.
Add the Temporary Register to the
ADD
Accumulator
Subtract the Temporary Register from the
SUB
Accumulator
DISPACC Display the contents of the Accumulator
STRTBLK Start of Loop Block
ENDBLK End of Loop Block
HALT Halt. Stop Program

b. Load the following program into the memory:


LOADTEMP
ADD
DISPACC
HALT

To do this, first click on the “LOADTEMP” in the list of instructions on the right of
simulator window. Then click on Memory location with “Address 0 Contains NOP”. This
will then change into “Address 0 Contains LOADTEMP”. Repeat the process with
“Address 1” and so on until the whole program is loaded.

c. Run the program by clicking on the “Run” button. The simulator would highlight the
Address 0 location and then pause. It is executing the instruction “LOADTEMP” which
requires you to input a number into the keypad.

Click 2 or 3 numbers on the keypad and then click the “Enter” button. The simulator will
then resume running the program and execute the instruction “ADD”. This adds the
number that you just entered, to the zero in the accumulator.

The next instruction is “DISPACC” which stands for “Display Accumulator”, and it does
exactly that. After than the simulator stops running the program when it executes the
instruction “HALT”.

d. Load the following program into the simulator:


LOADTEMP
ADD
LOADTEMP
ADD
DISPACC
HALT
What do you think it does? Write your answer below (10
marks)

Ans. On the given simulator, at first the following program is loaded serially on
memory where it starts from loading the value to simply halting the program.

The program begins by loading a value from a temporary location in memory into the
accumulator, which is a special register used for performing arithmetic and logic
operations. Next, it adds a value to the accumulator, which updates the current value
stored in the register. The program then repeats this process by loading another
value from memory into the accumulator and adding it to the current value. After
these operations, the program displays the final value stored in the accumulator and
then halts, terminating the program. For an instance, the screenshot below is an
example of how it actually works on given program. It shows when two numbers 2
and 3 is added it gives result as 5.

 LOADTEMP
 ADD
 LOADTEMP
 ADD
 DISPACC
 HALT
e. Write a program to add 3 numbers together. List your program
below (10 marks)

Ans. The list below given below is the program of adding three numbers together. It
shows that three numbers 2, 3 and 4 is added to give result as 9.
 LOADTEMP

 ADD

 LOADTEMP

 ADD

 LOADTEMP

 ADD

 DISPACC

 HALT

Here, at first instruction is loaded into the memory of simulator to perform the
operations simultaneously. Similarly, I chose three numbers which are 2, 3 and 4
entering through keypad in the input section. Then it adds these numbers serially
storing in temporary register where it performs arithmetic and logical operations
which is accumulator. After that, the following process is applied until three numbers
are entered. Finally, the output is displayed in the output section of simulator.
f. Write a program to subtract a number from another. List your
program below (10 marks)

Ans. Here, 3 is subtracted from 5 making result 2.It shows the subtraction of two
numbers where it includes program:

 LOADTEMP

 ADD

 LOADTEMP

 SUB

 DISPACC
 HALT

Here, at first instruction is loaded into the memory of simulator to perform the
operations simultaneously. Similarly, I chose two numbers which are 5 and 3
entering through keypad in the input section. After that it performs subtraction
between these numbers which is 3 from 5 storing in temporary register where it
performs arithmetic and logical operations which is accumulator. After the following
process program is halted. Finally, the output is displayed in the output section of
simulator.

g. Load the following program into the simulator:

LOADTEMP
ADD
LOADLOOP
STRTBLK
ADD
DISPACC
ENDBLK
HALT

Run it and when it reach the LOADTEMP instruction, enter 5


on the keypad and click the “Enter” button. When it reaches
the LOADLOOP instruction, enter 6. What do you think the
program does? Write your answer below in the form of an
equation (10 marks)

Ans. The program begins by loading a value from a temporary location in memory
into the accumulator, in this case the value is 5. This value is used as the starting
point for the calculation that the program will perform. Next, the program adds
another value to the accumulator, in this case the value is 6. This value is used to
update the current value stored in the register.

The program then enters a loop, which is defined by the instructions STRTBLK and
ENDBLK. Inside the loop, the program performs the operation ADD on the
accumulator. This operation is repeatedly executed for a number of iterations, as
defined by the programmer. The exact number of iterations is not specified in the
provided code, but it can be assumed that it is a variable that is determined at
runtime.

The program then displays the final value stored in the accumulator and halts,
terminating the program. The final value of the accumulator is the result of the
calculation performed by the program. It can be represented by the equation:
Accumulator = 5 + (6 * (number of iterations in the loop))

This equation states that the final value of the accumulator is equal to the initial value
of 5, plus the value of 6 multiplied by the number of iterations in the loop. The
program performs mathematical operations on values stored in memory, and
displays the result.

 LOADTEMP
 ADD
 LOADLOOP
 STRTBLK
 ADD
 DISPACC
 ENDBLK
 HALT
h. Write a program that will let you add 5, or 10 or 20 numbers
together. List your program below and explain how it works (25
marks)

Ans. Here, at first instruction is loaded into the memory of simulator to perform the
operations simultaneously. In this case, primarily load loop works as a loop to ensure
how many times user can enter random number. So, the loop works to add 5, 10 and
20 numbers together. Similarly, I chose random numbers which are entering through
keypad in the input section. Then it adds these numbers serially storing in temporary
register where it performs arithmetic and logical operations which is accumulator.
After that, the following process is applied until five numbers are entered. Finally, the
output is displayed in the output section of simulator.

 LOADLOOP

 STRTBLK

 LOADTEMP

 ADD

 ENDBLK

 DISPACC

 HALT

The screenshot below works to add 5 random numbers:


The screenshot below works to add 10 random numbers:
The screenshot below works to add 20 random numbers:
i. Write a program that will let you multiply 2 numbers together. List
your program below and explain how it works (35 marks)

Ans. Here, at first instruction is loaded into the memory of simulator to perform the
operations simultaneously. In this case, primarily load loop works as a loop to ensure
how many times user have to enter number to perform particular multiplication. So,
the loop works to multiply two numbers that is 7*3 where I entered 3 in load loop and
entered 7 three times to perform multiplication 7*3. Then it adds 7 serially storing in
temporary register which is accumulator. After that, the following process is applied
until 7 is entered three times. Finally, the output is displayed in the output section of
simulator.

 LOADLOOP

 STRTBLK

 LOADTEMP

 ADD

 ENDBLK

 DISPACC

 HALT

You might also like