2024-11-07 17:46:15 +08:00

28 lines
734 B
Python

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(物理地址)