Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# ! / usr / bin / env python import matplotlib.pyplot as plt import sys from optparse import OptionParser import random import math bounds _

#!/usr/bin/env python
import matplotlib.pyplot as plt
import sys
from optparse import OptionParser
import random
import math
bounds_values = range(0,4097,100)
valid_fractions =[]
for bound in bounds_values:
# Run relocation.py with bound value and capture valid fraction
# Here we assume capture_fraction is a function that runs relocation.py and returns the valid fraction
fraction = capture_fraction(bound)
valid_fractions.append(fraction)
plt.plot(bounds_values, valid_fractions)
plt.xlabel('Bounds Register Value')
plt.ylabel('Fraction of Valid Addresses')
plt.title('Fraction of Valid Virtual Addresses vs Bounds Register Value')
plt.show()
def convert(size):
length = len(size)
lastchar = size[length-1]
if (lastchar =='k') or (lastchar =='K'):
m =1024
nsize = int(size[0:length-1])* m
elif (lastchar =='m') or (lastchar =='M'):
m =1024*1024
nsize = int(size[0:length-1])* m
elif (lastchar =='g') or (lastchar =='G'):
m =1024*1024*1024
nsize = int(size[0:length-1])* m
else:
nsize = int(size)
return nsize
# main program
parser = OptionParser()
parser.add_option('-s','--seed', default=0, help='the random seed', action='store', type='int', dest='seed')
parser.add_option('-a','--asize', default='1k', help='address space size (e.g.,16,64k,32m,1g)', action='store', type='string', dest='asize')
parser.add_option('-p','--physmem', default='16k', help='physical memory size (e.g.,16,64k,32m,1g)', action='store', type='string', dest='psize')
parser.add_option('-n','--addresses', default=5, help='number of virtual addresses to generate', action='store', type='int', dest='num')
parser.add_option('-b','--b', default='-1', help='value of base register', action='store', type='string', dest='base')
parser.add_option('-l','--l', default='-1', help='value of limit register', action='store', type='string', dest='limit')
parser.add_option('-c','--compute', default=False, help='compute answers for me', action='store_true', dest='solve')
(options, args)= parser.parse_args()
random.seed(options.seed)
asize = convert(options.asize)
psize = convert(options.psize)
if psize <=1:
print('Error: must specify a non-zero physical memory size.')
exit(1)
if asize ==0:
print('Error: must specify a non-zero address-space size.')
exit(1)
if psize <= asize:
print('Error: physical memory size must be GREATER than address space size (for this simulation)')
exit(1)
limit = convert(options.limit)
base = convert(options.base)
if limit ==-1:
limit = int(asize /4.0+(asize /4.0* random.random()))
if base ==-1:
done =0
while done ==0:
base = int(psize * random.random())
if (base + limit)< psize:
done =1
valid_count =0
for i in range(0, options.num):
vaddr = int(asize * random.random())
if vaddr < limit:
valid_count +=1
fraction_valid = valid_count / options.num
print(f'Seed: {options.seed}, Limit: {limit}, Fraction of valid addresses: {fraction_valid:.2f}')
Traceback (most recent call last):
File "/Users/jonnieeason/Desktop/relocation.py", line 14, in
fraction = capture_fraction(bound)
^^^^^^^^^^^^^^^^
NameError: name 'capture_fraction' is not defined
How do i fix this specific error?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

Students also viewed these Databases questions