From f63c1d9e6fb9444892c5f1d1405fb346cea23fc4 Mon Sep 17 00:00:00 2001 From: GuanM <30427262+sxhoio@users.noreply.github.com.> Date: Thu, 7 Nov 2024 17:46:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AEG=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 操作系统/题目7.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 操作系统/题目7.py diff --git a/操作系统/题目7.py b/操作系统/题目7.py new file mode 100644 index 0000000..e360cee --- /dev/null +++ b/操作系统/题目7.py @@ -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(物理地址) \ No newline at end of file