You are on page 1of 5

CEN 261 - Midterm Exam - Group A

International Burch University


22/11/2021

SOLUTIONS
Question Points Score
1 30
2 10
3 30
4 30
Total 100

Question 1: Cache Memory


[30 pts] Explain the advantages and disadvantages (in couple of sentences or a bullet-ed list)
of using a direct mapped cache instead of an 8-way set associative cache.

As there is only one block where the data for a physical address can be mapped to, a
direct mapped cache has a faster hit time than the set associative cache. But this is also a
disadvantage in the case where two separate addresses map to the same cache block, because
a cache hit will never happen in that case. This affects performance. In the case of 8-way
associative cache, where we have 8 blocks within one set, a block from main memory can map
to any of the 8 blocks within a set. This gives flexibility, but also in case of 2 main memory
blocks that map to the same cache block (direct-mapped case), here in set-associative cache,
both references will be a cache hit, so no misses. The disavantage of a set-associative cache,
compared to a direct-mapped cache, is that it takes a long time to search (all the TAG
registers, for all the blocks).

(a) Consider a direct-mapped cache design with a 32-bit address. Memory is byte-addressable.
A scheme for the address bits used to access the cache is shown below:
Tag Index Offset
31-13 12-5 4-0
31-13 12-7 6-0

For each of these designs, determine: 1. What is the cache block size, in words? and 2.
How many cache blocks the cache has?

design 1: offset is 5 bits, which means there are 32 bytes/block = 8 words/block.


design 2: offset is 7 bits, which means there are 128 bytes/block = 32 words/block.
design 1: index is 8 bits, which means there are 256 blocks in the cache.

1
design 2: index is 6 bits, which means there are 64 blocks in the cache.

(b) Assume you have a 8-way set associative cache. Words are 4 bytes. Addresses are to the
byte. Each block holds 256 bytes. There are 512 blocks in the cache. If you reference
a 32-bit physical address D A B 1 5 3 8 9 (in hex) (and the cache is initially empty):
1. How many data words are brought into the cache with this reference? 2. Which set
does the data (that is brought in) go to with the given physical address supplied to the
cache?

1. The entire block will be  filled. Words are 4 bytes long, each block holds 256 bytes,
28 bytes/block
so there are 22 bytes/word = 26 words/block = 64words/block.
Offset bits = 6 + 2 = 8 bits (byte-addressable cache);
2. As the question asks ”which set does the data go to?” we need to determine what
the index bits are. As we know the offset is 8 bits, because data is byte addressable.
If we write the hex address in binary, we have: 1101 1010 1011 0001 0101 0011 1000
1001
Offset is: 1000 1001
   
512blocks 29
Number of sets: 8blocks/set
= 23
sets = 26 sets = 64sets,
so 6 bits of index are required. These are 01 0011 which implies the address is mapped
to 19th set.

Question 2: Number Systems


[10 pts] Perform the following conversions:

(a) Write the hexadecimal numbers 19A and 28 in binary.

0001 1001 1010; 0010 1000;

(b) Convert the hexadecimal number B14E16 to octal number, via binary.

754247026

(c) Convert the (binary) number 111010001 to decimal. Convert the (decimal) number 145
to binary.

465; 10010001;

(d) Convert the (hexadecimal) number 13C to decimal. Convert the (decimal) number 19
to hexadecimal.

2
316; 13;

(e) Convert the (binary) number 111010001 to decimal. Convert the (decimal) number 145
to binary.

same as (c)

(f) Convert the octal number 345 to hexadecimal, via binary.

E5;

(g) Convert the hexadecimal number AEC3 to octal, via binary.

127303

Question 3: Memory System


[30 pts] What is the main design issue of a memory system? Identify the challenges and
explain possible solutions.

The main design issue is how to bridge the CPU-memory speed gap. i.e. How to make
memory system work faster? How to increase data transfer rate between CPU and memory?
How to address the ever increasing storage needs of applications? Possible solutions: cache
memory and virtual memory. CACHE: fast memory, organized possibly in several levels,
that sits between CPU and MM. Faster than MM and small. Frequently accessed data and
instructions stored here. Uses SRAM technology. VIRTUAL MEMORY: technique used by
the OS to provide an illusion of very large memory to the CPU. Program and data actually
stored on secondary memory that is much larger. Transfer parts of program and data from
secondary memory to main memory only when needed. +illustrations.

(a) Use the example of a 4K x 16 memory system to: (1) explain the organization of
memory cells, and (2) calculate the total number of external connections to the memory
system.

2n × m;
n is a number of address lines, m is a number of data lines - maximum number of
memory locations 2n
will be represented through m bits of data in each storage location.
For this example, 212 ,

3
means there are n=12 bits for address lines; m = 16, 16 bits for data lines, 2 power
and ground signals, 2 control signals RD/W and CS. Total 32 external connections.

(b) Consider a word-addressable computer with 64KB of memory and a 16-bit word size.
Its memory is built out of 4K x 4 chips. How many chips make up memory? How many
bits make up an address?

64K×16
4K×4
) = 64chips;

64K×8bit
16bit/words
) = 32Kwords = 215 words;
15 bits make up an address.

Question 4: Instruction Formats Basics & Registers


[30 pts] Describe the instruction format and the types of instruction formats, and provide
examples. What is the purpose of the MAR, MDR (MBR), IR, PC and ACC registers?

Instruction format: an instruction consists of 2 parts: opcode or operation code and operand(s).
There are various categories of instructions: data transfer (MOVE R1, R2), arithmetic and
logical (ADD R1, R2), control, I/O and special machine control instructions. Opcode speci-
fies the operation to be performed by an instruction, depending on the category of instruction.
Operands specify source(s) and destination of the operation. Source operand can be spec-
ified by an immediate data, by naming register, or specifying address of memory location.
Destination can be specified by a register or memory address. The number of operands may
vary, so we can have 0-address instruction (opcode ), 1-address (opcode memory address),
2-address (opcode memory addr memory addr), 3-address instructions (opcode reg reg reg).
Also while specifying operands we need to know various addressing modes (addressing mode
is a way by which the location of the operand is specified in the instruction).
Registers: MAR holds the memory address of the data needing to be accessed by the CPU.
MDR holds the data being transferred to or from the memory location by the CPU. IR
holds the encoded instruction that is currently being executed or decoded. PC holds the
memory address of the next instruction to be executed. ACC holds the result of a calculation
performed by the arithmetic/logic unit.

(a) The two registers are initialized as R1 = 20, R2 = 14. The instruction SUB R1,R2 is
in memory location 2020H. The size of an instruction is 4 bytes. After the instruction
execution, what will be the values in PC and R1?

PC=2024H (gets incremented by 4), R1=6

4
(b) Consider a 32-bit machine where an instruction ADD R1, LOCA is stored at location
102AH. LOCA is a memory location whose value is 200BH. How many memory accesses
are required to execute this instruction assuming the instruction is stored in memory?
In addition, what will be the content of PC after the instruction is fetched? Individual
instruction is 32-bit.

Requires 2 memory accesses: first to read the instruction, second to read the value
from memory location whose address is in LOCA (reads 2 sources and uses 1 source as
destination, 2 mem acc total); PC: 102EH;

(c) How many bits of opcode is required to implement a CPU with 12 arithmetic and logical
instructions, 2 control instructions, and 5 data transfer instructions?

12+2+5=19 instructions, 5 bits opcode we need.

(d) A computer uses a memory unit with 64K words of 32 bits each. A binary instruction
code is stored in one word of memory. The instruction has four parts: an indirect bit,
an operation code, a register code part to specify one of the 32 registers, and an address
part. How many bits are there in the operation code, the register code part, and the
address part?

16 bits address, 5 bits registers, 1 bit, 10 bits opcode

You might also like