惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Last Week in AI
Last Week in AI
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
B
Blog RSS Feed
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Latest news
Latest news
S
SegmentFault 最新的问题
J
Java Code Geeks
C
CXSECURITY Database RSS Feed - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Full Disclosure
Engineering at Meta
Engineering at Meta
AWS News Blog
AWS News Blog
月光博客
月光博客
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
雷峰网
雷峰网
博客园_首页
Project Zero
Project Zero
美团技术团队
Google DeepMind News
Google DeepMind News
IT之家
IT之家
P
Palo Alto Networks Blog
有赞技术团队
有赞技术团队
S
Security @ Cisco Blogs
U
Unit 42
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
S
Schneier on Security
TaoSecurity Blog
TaoSecurity Blog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
Help Net Security
Help Net Security

博客园 - 华腾智算

子系统框架存档20260717 响应式后台管理系统 smart-water 融合多端协同总体架构设计方案 现代前端架构的核心思想 极简设计框架 跨平台弹性栅格理念设计 多端统一设计理念 一套规则,多端伸缩的UI设计理念 现代栅格设计之一 设计中的栅格系统 智慧水利顶层设计之何为“水利矩阵”与“数字孪生” 从古典Web到AI原生超级应用:团队学习路线与未来架构蓝图 最新架构设计 前端代码规范 v1.0 树型菜单全功能代码 最终最佳实践操作文档:统信UOS VSCode 全栈开发环境配置(基于 Chromium 浏览器) vscode-setting.json配置 VSCode 全栈开发环境初始化设置与跨平台配置指南(Windows/macOS 通用) VScode完整的跨平台适配方案 完整的跨平台 settings.json(飞雪飘鸿优化版) 数字孪生破局之道 完整的GLFW应用程序示例 雏形 程序方向 web三维 第一步,第一行,开始 绘制三角形 明确目标 使用Python的pydub库播放音乐并打印二进制数据 python的音频处理 python加密与解密 mainwindows.cpp 十进制数213转换为二进制数的完整过程,使用除2取余法(也称为“重复除法法”) 二进制数 \((-1101.101)_2\) 转换为十进制数 - 华腾智算
从文本文件加载指令到模拟内存中,并显示前11个内存单元的内容
华腾智算 · 2025-08-21 · via 博客园 - 华腾智算
# -*- coding: utf-8 -*-
'''
程序功能:从文本文件加载指令到模拟内存中,并显示前11个内存单元的内容
文件格式:每行包含内存地址和指令,例如 "0 LOAD 100"
'''

# 初始化一个长度为1000的内存空间,每个元素初始为空字符串
men = [''] * 1000

def loadProgram(file):
    """
    从文件加载程序到内存中
    
    参数:
        file: 包含程序指令的文本文件路径
        
    返回:
        list: 包含已加载指令的内存列表
    """
    # 以只读模式打开文件
    fil = open(file, "r")
    
    # 循环读取文件的每一行
    while True:
        line = fil.readline()
        
        # 如果读到文件末尾,退出循环
        if line == '':
            break
            
        # 使用空格分割行内容,得到字段列表
        flds = line.split()
        
        # 提取第一个字段作为内存地址并转换为整数
        address = int(flds[0])
        
        # 提取第二个字段作为指令
        instruc = flds[1]
        
        # 将剩余字段(操作数等)添加到指令字符串中
        for fld in flds[2:len(flds)]:
            instruc = instruc + " " + fld
            
        # 将指令存储到对应的内存地址
        men[address] = instruc
        
    # 关闭文件
    fil.close()
    
    # 返回填充后的内存
    return men

# 加载程序文件到内存
loadProgram('sum100.txt')

# 打印前11个内存单元的内容
for i in range(11):
    print('主存单元', i, ':', men[i])