Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# Variables: # NBA: number of bits in the virtual address # NBO: number of bits

ID: 3593069 • Letter: #

Question


# Variables:
# NBA: number of bits in the virtual address
# NBO: number of bits for offset in the virtual address
# NBP: number of bits for VPN in the virtual address
# NP: number of pages
# SA: size of the virtual address space
# SP: size of a virtual page
#
# The units of SA and SP are bytes, and I'm assuming that
# each byte of memory has its own address.

# For example, suppose a virtual address has 32 bits, and the
# size of a page is 4 KB. How many page bits and offset bits
# in the virtual address?
#
# Solution: Since the page size is 4 KB, the number of offset
# bits must be 12, because log2(4*1024) is 12. Then the
# the number of page bits must be 20, since there are 32 bits
# in the virtual address, and subtracting the 12 offset bits
# we get 20.

# To solve the problems you need to know these relationships
# between the variables:
#
# NBA = log2(SA), or equally SA = 2^NBA
# NBP = log2(NP), or equally NP = 2^NBP
# NBO = log2(SP), or equally SP = 2^NBO
# NBO + NBP = NBA
#
# For example, suppose SP (size of a page) is 1024 bytes. Then
# the number of offset bits in the virtual address must be log2(1024),
# which is 10.

#######################################################################
#
# PROBLEMS
#
# After each problem, enter the correct values for the variables shown.
# Put your answer right after the equals sign.
# Note that 32 KB means 32*1024, and similarly for MB.
#
#######################################################################

#@ 1 If the size of the virtual address space is 32 KB, and
# each page is 2 KB, how many page bits and offset bits in the
# virtual address?

NBP=
NBO=

#@ 2 If a page is 4 KB, and there are 32 virtual pages, how
# many page bits and offset bits in the virtual address?

NBP=
NBO=

#@ 3 If the size of the virtual address space is 32 MB, and there are
# 2048 virtual pages, how many page bits and offset bits in the virtual address?

NBP=
NBO=

#@ 4 If a virtual address is 8 bits, and there are 32 virtual pages,
# how many page bits and offset bits in the virtual address?

NBP=
NBO=

#@ 5 If a virtual address is 32 bits, and a page is 4 KB, how
# many page bits and offset bits in the virtual address?

NBP=
NBO=

#@ 6 If there are 1024 virtual pages, and 10 offset bits in a
# virtual address, then what is the size of the virtual address space
# (in bytes)?

SA=

#@ 7 If the virtual address space is 64 MB, and there are 12
# page bits in a virtual address, then what is the page size?

SP=

#@ 8 If the virtual address space is 32 KB, and each page is 2 KB,
# then how many virtual pages are there?

NP=

#@ 9 If there are 4096 pages, and each page is 8 KB, then
# how many bits in a virtual address?

NBA=

#@ 10 If a virtual address has 32 bits, and the number of pages
# is 1024*1024, then how many offset bits in the virtual address?

NBO=

Explanation / Answer

Variables:

# NBA: number of bits in the virtual address

# NBO: number of bits for offset in the virtual address

# NBP: number of bits for VPN in the virtual address

# NP: number of pages

# SA: size of the virtual address space

# SP: size of a virtual page

# NBA = log2(SA), or equally SA = 2^NBA

# NBP = log2(NP), or equally NP = 2^NBP

# NBO = log2(SP), or equally SP = 2^NBO

# NBO + NBP = NBA

1. SA = 32 KB, SP = 2 KB

NP = SA/SP = 32/2 = 16

NBP = log2(16) = 4

NBO = log2(SP) = log2(2*1024)= 11

2. NBO = log2(SP) = log2(4*1024) = 12

Since NP = Number of pages = 32

NBP = log2(NP) = log2(32)= 5

3. NP = 2048,  

NBP = log2(NP) = log2(2048)=11

SP = SA/NP = 32MB / 2048 = 16 KB

NBO = log2(SP)=log2(16*1024)=14

4. NP = 32

NBP = log2(32) = 5

Since NBA=8

NBO = NBA-NBP = 8-5=3

5. Since NBA=32, SP=4 KB

NBO = log2(SP)=log2(4*1024)=12

NBP = NBA-NBO = 32-12 = 20

6. Since NBP = 10, NP = 1024

SP = 2^NBP = 1024 Bytes = 1 KB

SA = NP*SP = 1024*1 KB = 1 MB

7. SA = 64 MB, NBP = 12

NBA = log2(64*1024*1024) = 26

NBO = NBA-NBP = 26-12 = 14

SP = 2^NBO = 2^14 Bytes = 16 KB

8. SP = 2 KB, SA = 32 KB

NP = SA/SP = 32/2 = 16

9. NP = 4096, SP = 8 KB

SA = NP* SP = 4096*8 KB

NBA = log2(SA) = log2(4096*8*1024)= 25

10. NP = 1024*1024, NBA = 32

NBP = log2(NP) = log2(1024*1024)= 20

NBO = NBA - NBP = 32-20 = 12