Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# ! / usr / bin / env pythonimport matplotlib.pyplot as pltimport sysfrom optparse import OptionParserimport randomimport mathbounds _ values = range ( 0 ,

#!/usr/bin/env pythonimport matplotlib.pyplot as pltimport sysfrom optparse import OptionParserimport randomimport mathbounds_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 programparser = 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 =1valid_count =0for i in range(0, options.num): vaddr = int(asize * random.random()) if vaddr < limit: valid_count +=1fraction_valid = valid_count / options.numprint(f'Seed: {options.seed}, Limit: {limit}, Fraction of valid addresses: {fraction_valid:.2f}')
Getting errors in the code please help

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

Step: 3

blur-text-image

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

What projects have I completed at home, work, or school?

Answered: 1 week ago

Question

3. Raster images for screen projects need to be 72 dpi to scale.

Answered: 1 week ago