Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# ! / usr / bin / env python import matplotlib.pyplot as plt import sys from optparse import OptionParser import random import math bounds _
#usrbinenv python
import matplotlib.pyplot as plt
import sys
from optparse import OptionParser
import random
import math
boundsvalues range
validfractions
for bound in boundsvalues:
# Run relocation.py with bound value and capture valid fraction
# Here we assume capturefraction is a function that runs relocation.py and returns the valid fraction
fraction capturefractionbound
validfractions.appendfraction
pltplotboundsvalues, validfractions
pltxlabelBounds Register Value'
pltylabelFraction of Valid Addresses'
plttitleFraction of Valid Virtual Addresses vs Bounds Register Value'
pltshow
def convertsize:
length lensize
lastchar sizelength
if lastchar k or lastchar K:
m
nsize intsize:length m
elif lastchar m or lastchar M:
m
nsize intsize:length m
elif lastchar g or lastchar G:
m
nsize intsize:length m
else:
nsize intsize
return nsize
# main program
parser OptionParser
parser.addoptionsseed', default help'the random seed', action'store', type'int', dest'seed'
parser.addoptionaasize', defaultk help'address space size egkmg action'store', type'string', dest'asize'
parser.addoptionpphysmem', defaultk help'physical memory size egkmg action'store', type'string', dest'psize'
parser.addoptionnaddresses', default help'number of virtual addresses to generate', action'store', type'int', dest'num'
parser.addoptionbb default help'value of base register', action'store', type'string', dest'base'
parser.addoptionll default help'value of limit register', action'store', type'string', dest'limit'
parser.addoptionccompute', defaultFalse, help'compute answers for me action'storetrue', dest'solve'
options args parser.parseargs
random.seedoptionsseed
asize convertoptionsasize
psize convertoptionspsize
if psize :
printError: must specify a nonzero physical memory size.
exit
if asize :
printError: must specify a nonzero addressspace size.
exit
if psize asize:
printError: physical memory size must be GREATER than address space size for this simulation
exit
limit convertoptionslimit
base convertoptionsbase
if limit :
limit intasize asize random.random
if base :
done
while done :
base intpsize random.random
if base limit psize:
done
validcount
for i in range options.num:
vaddr intasize random.random
if vaddr limit:
validcount
fractionvalid validcount options.num
printfSeed: optionsseed Limit: limit Fraction of valid addresses: fractionvalid:f
Traceback most recent call last:
File UsersjonnieeasonDesktoprelocationpy line in
fraction capturefractionbound
NameError: name 'capturefraction' is not defined
How do i fix this specific error?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started