0% found this document useful (0 votes)
8 views

Lab 4 Worksheet

The document outlines a lab assignment focused on the Super Simple CPU simulator, covering its components, instruction cycle, and programming in machine and assembly languages. It includes various exercises and pseudocode tasks aimed at analyzing and writing programs for the CPU simulator. The learning objectives emphasize understanding the fetch-execute cycle, machine language, assembly language, and pseudocode writing.

Uploaded by

vnsvaldez90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab 4 Worksheet

The document outlines a lab assignment focused on the Super Simple CPU simulator, covering its components, instruction cycle, and programming in machine and assembly languages. It includes various exercises and pseudocode tasks aimed at analyzing and writing programs for the CPU simulator. The learning objectives emphasize understanding the fetch-execute cycle, machine language, assembly language, and pseudocode writing.

Uploaded by

vnsvaldez90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Lab 4: Chapter 5, Computing Components. Lab7_Manual.

pdf,
Computer Cycling. Lab11_Manual.pdf, Low-level Languages.
Pseudocode.

[80 marks] In all of the problems, you must show your work to qualify for the mark.

Type your answer in this worksheet after each question. Submit the PDF version of the completed
worksheet with D2L.

Introduction
Super Simple CPU is a simple CPU simulator with 16 memory locations. Memory addresses are from 0 to FF or
15.
Each word in memory is 16 bits or 2 bytes. It is either instruction or data. Numbers are stored in two's
complement notation.
The input and output devices are merely text areas to the left.
There are three registers:
 PC (Program Counter): contains the address of the next instruction to be executed
 The Instruction Register (IR): contains a copy of the instruction being executed
 The Accumulator (A register): used to hold data and results of operations
Each instruction is 16 bits containing:
 4-bit opcode: represents the instruction
 12-bit operand holds one of the following:
o a constant (like LDI)
o the address of where the operand is found (like ADD, SUB, STO, and LOD)
o nothing (like STP, IN, OUT)
As the program runs, it cycles through the basic instruction cycle, which is called the fetch-execute cycle. The
steps are shown in the blue text area in the middle.
In Super Simple CPU, the instructions are shown in machine language (binary codes) as well as assembly
(mnemonic codes).

Learning Objectives
At the end of this lab, you should be able to:
 analyze the fetch-execute cycle of computers
 analyze machine language programs
 analyze assembly language programs
 understand, write simple pseudocodes

1
Lab Readings
1. Chapter 5 - Computer Components
2. Chapter 6 - Pseudocodes
3. Lab 7 Computer Cycling (Lab7_Manual.pdf)
4. Lab 11 Low-Level Languages (Lab11_Manual.pdf)

Lab Questions
1. Lab 7 Computer Cycling (Lab7_Manual.pdf)
a. [3] Exercise 1 – Note there are 4 instructions in this program (and not 3 as stated in the pdf file), STP is
an instruction and causes one fetch-execute cycle.

b. [6] Repeat Exercise 1 for examples 2, 3 in the super simple cpu applet.

c. [3] Exercise 2

d. [4] Exercise 3

2. [2] What is the printout of the following pseudocode if the user inputs 4 and 10?
2
Display "Enter two numbers: "
Input num1
Input num2
Set sum to num1 + num2
Set average to sum / 2
Display "Average of " + num1 + " and " + num2 + " is " + average

3. [2] (Input and Output) Write a pseudocode for example 2 of Super Simple CPU Applet.

4. [4] (Temperature Conversion) Write a pseudocode that:


a. reads a Celsius degree from input
b. converts it to Fahrenheit (you need the formula to convert from Celsius to Fahrenheit)
c. displays the result as shown in the sample run below
Note: 25 is an example input for Celsius in the sample run, your program should work correctly for
any input.
Here is a sample run:
Enter Celsius degree: 25
Degree in Fahrenheit is 77.0.

5. Given the following "Super Simple CPU" program:


LDI 6 ; Load 6 into accumulator
SUB ONE ; Subtract the value in memory location ONE from
accumulator
ADD TWO ; Add the value in memory location TWO to
accumulator
DONE STO ONE ; Store accumulator in memory location ONE
STP ; Stop the program
ONE DAT 1 ; A data value, the constant 1
TWO DAT 2 ; A data value, the constant 2

3
a. [4] Trace the code, write the values of Accumulator, Memory (ONE), and Memory (TWO) in a table
(sample table is shown below), and record their changes after each instruction.

Assembly instruction Accumulator ONE TWO

LDI 6 6 1 2

b. [4] Write a pseudocode that performs the same program.

4
6. Given the following "Super Simple CPU" program:
LOD X ; Load X into accumulator
ADD X ; Add the value in memory location X to accumulator
ADD X ; Add the value in memory location X to accumulator
SUB Y ; Subtract the value in memory location Y from
accumulator
DONE STO Z ; Store accumulator in memory location Z
STP ; Stop the program
X DAT 3 ; A data value, the constant 3
Y DAT 5 ; A data value, the constant 5
Z DAT 0 ; A data value, the constant 0

a. [4] Trace the code, write the values of Accumulator, Memory (X), Memory (Y), and Memory (Z) in a table
shown below (sample table).

Assembly instruction Accumulator X Y Z

LOD X 3 3 5 0

b. [4] Write a pseudocode that performs the same program.

7. Lab 11 Low-Level Languages (Lab11_Manual.pdf)


c. [4] Exercise 1

d. [4] Exercise 3

5
8. [3] (Counting Loop) Write a pseudocode that performs example 5 of Super Simple CPU Applet.

9. [8] Given the following "Super Simple CPU" program, assume three different values for INPUT (1, 2, or 3).
For each input value, trace the code by writing the values of Accumulator, Memory (ONE), Memory (TWO),
and OUTPUT in a table (shown below) and recording their changes after each instruction. You should have 3
trace tables for 3 different values of input.
INP ; Assume three different values for input (1,2,3)
SUB ONE
JZR ZERO
SUB TWO
JNG NEG
ADD TWO
OUT
STP
NEG ADD TWO
OUT
STP
ZERO OUT
STP
ONE DAT 1 ; A data value, the constant 1
TWO DAT 2 ; A data value, the constant 2

Assembly instruction Accumulator ONE TWO OUT


INPUT 1 1 2 -

6
10. Given the following pseudocode:
Set num to 10
WHILE (num is greater than 0)
Print num
Set num to num – 2

a. [4] Trace the program by writing the values of variables, conditions, and printout in a table (shown below).

num num > 0 printout


10 True 10

b. [4] Write the pseudocode in Super Simple CPU Assembly language.

c. [1] Explain the function of the program in one sentence. (Hint: For the function of the program, you can
explain the printout of the program).

7
11. Given the following pseudocode, assume the sequence of input numbers is: 4, 5, -1, 2, -4, -2, 6, 8. (Note: The
program may not read all these numbers).
Set sum to 0
Set count to 1
WHILE (count <= 4)
Read number
Set sum to sum + number
Increment count
Write "Sum is " + sum
 [4] Trace the program by writing the values of variables, conditions, and printout in a table (shown below).

Sum count count <= 4 number printout


0 1 true 4 -

 [1] How many numbers does the program read?

 [1] Explain the function of the program in one sentence. (Hint: For the function of the program, you can
explain the printout of the program in terms of input values).

8
12. Given the following pseudocode, assume the sequence of input numbers is: 4, 5, -1, 2, -4, -2, 6, 8, -1, 0.
(Note: The program may not read all these numbers).
Set sum to 0
Set count to 1
WHILE (count <= 4)
Read number
IF (number > 0)
Set sum to sum + number
Increment count
Write "Sum is " + sum

 [4] Trace the program by writing the values of variables, conditions, and printout in a table (shown below).

Sum count count <= 4 number number < 0 printout


0 1 true 4 -

 [1] How many numbers does the program read?

 [1] Explain the function of the program in one sentence. (Hint: For the function of the program, you can
explain the printout of the program in terms of input values).

Submit the PDF version of the completed worksheet with D2L

You might also like