题目G完成
This commit is contained in:
parent
f95f1446bf
commit
f63c1d9e6f
28
操作系统/题目7.py
Normal file
28
操作系统/题目7.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
def 计算物理地址(段表, 逻辑地址):
|
||||||
|
段号, 偏移 = 逻辑地址
|
||||||
|
|
||||||
|
if 段号 < 0 or 段号 >= len(段表):
|
||||||
|
return "interrupt"
|
||||||
|
|
||||||
|
起始地址, 段长度 = 段表[段号]
|
||||||
|
|
||||||
|
if 偏移 < 0 or 偏移 >= 段长度:
|
||||||
|
return "interrupt"
|
||||||
|
else:
|
||||||
|
return 起始地址 + 偏移
|
||||||
|
|
||||||
|
段表输入 = input().split()
|
||||||
|
逻辑地址输入 = input().split()
|
||||||
|
|
||||||
|
段表 = []
|
||||||
|
for i in range(0, len(段表输入), 2):
|
||||||
|
起始地址 = int(段表输入[i])
|
||||||
|
段长度 = int(段表输入[i + 1])
|
||||||
|
段表.append((起始地址, 段长度))
|
||||||
|
|
||||||
|
段号 = int(逻辑地址输入[0])
|
||||||
|
偏移 = int(逻辑地址输入[1])
|
||||||
|
|
||||||
|
物理地址 = 计算物理地址(段表, (段号, 偏移))
|
||||||
|
|
||||||
|
print(物理地址)
|
Loading…
x
Reference in New Issue
Block a user