UIUC ECE 220 计算机系统与编程 · 开篇与课程概览

目录 · l1 →

ECE 220 – Computer Systems & Programming University of Illinois Urbana-Champaign · The Grainger College of Engineering Department of Electrical and Computer Engineering

一门自底向上讲授 C 语言与系统编程的核心课程: 从 LC-3 汇编、内存映射 I/O、子程序与栈出发,一路走到 C 的指针、动态内存、 数据结构、面向对象设计与调试工具,建立”从高级语言到机器代码的完整认知链条“。

先修课:ECE 120(Introduction to Computing)· 4 学分 · 教材:Patt & Patel, Introduction to Computing Systems: from bits and gates to C and beyond


本笔记的结构

本笔记共 21 讲 + 1 个速查表附录,按”从汇编 → 到 C → 到数据结构 → 到工程实践”的顺序组织。 每一讲都严格采用六段式结构,其中代码示例部分包含五个子项 (代码 / 代码做什么 / 底层机制透视 / 内存布局图解 / 与汇编的对应)。

部分讲次主题
一 · 机器层L1 – L4课程概述与 LC-3 复习;内存映射 I/O 与 TRAP;子程序与调用约定;栈抽象与栈帧
二 · C 与机器码的映射L5 – L8类型/运算符/作用域/存储期;控制结构与 I/O;函数;运行时栈与栈帧
三 · 指针与数组L9 – L12指针;数组;字符串与多维数组;问题求解与函数指针
四 · 程序组织与内存L13 – L16递归;文件 I/O;结构体与信息隐藏;动态内存分配
五 · 数据结构与算法L17 – L19链表;树与 C-to-LC-3;排序算法
六 · 工程实践L20 – L21面向对象概念与 C/C++ 实现;调试工具与技术
附录C 语言与系统编程核心概念速查表

资料来源

本笔记基于 ECE 220 的公开可访问资料编写:课程目录页的官方描述、主题列表、 Course Goals 与 9 条 Instructional Objectives;Fall 2025 课程网站的 syllabus、 逐周课程表与讲座索引;Resources 栏目下的官方 GDB quick reference、 C coding conventions、C Programming Reference 三个完整公开页面; 以及归档的 Prof. Steven Lumetta ECE 220 公开站点(58 份讲座幻灯片、15 份 Lab 讲义、 12 份 MP 讲义、历年试卷与完整示例代码)。MP 与 Lab 的完整讲义位于当前网站的 /secure/ 路径下、不对公众开放,仅有标题与截止日期公开。详细的资料来源与访问限制 记录见”课程概览”一节的最后一小节。

所有 C 代码示例均以 gcc -g -std=c99 -Wall -Werror 实际编译并运行验证过。


目录


课程概览 (Course Overview)

ECE 220 是什么

ECE 220 – Computer Systems & Programming(计算机系统与编程) 是伊利诺伊大学厄巴纳-香槟分校 (UIUC)Grainger 工程学院电子与计算机工程系(ECE)的大二核心课程,4 学分,由计算机工程与 电气工程两个专业共同必修。它同时承担着一个更宏大的任务:把 ECE 120 建立的”从比特到门电路” 的底层视角,一路缝合到现代软件工程实践之上。

官方课程描述

Advanced use of LC-3 assembly language for I/O and function calling convention. C programming, covering basic programming concepts, functions, arrays, pointers, I/O, recursion, simple data structures, linked lists, dynamic memory management, and basic algorithms. Information hiding and object-oriented design as commonly implemented in modern software and systems programming.

先修要求:ECE 120(Introduction to Computing)。不接受同期修读。 限制:仅限计算机工程 / 电气工程专业学生,或经 ECE 系批准的转学生。

课程主任(Course Director)为 Yih-Chun Hu 教授。教材为 Patt & Patel 的 Introduction to Computing Systems: from bits and gates to C and beyond(第 2 版 2003 / 第 3 版 2019, McGraw-Hill)——这正是 ECE 120 使用的同一本教材,第 8 章之后的内容构成本课程的主体。


为什么要”自底向上”(bottom-up)

这是理解 ECE 220 全部教学设计的一把钥匙。课程官网的原文是:

This course will focus on C programming, where each new C concept will be related to the fundamental concepts described in ECE 120. We will start by finishing our coverage of low-level concepts such as I/O, subroutines, and stacks in LC-3 assembly language, then move on to C. … Such a bottom-up understanding of computing systems has proven more successful in helping students understand advanced computing concepts that follow in the ECE curriculum.

也就是说,ECE 220 不是一门普通的”C 语言入门课”。它的教学逻辑是反向的:

                         ┌──────────────────────────────────────────┐
   自底向上 (bottom-up)   │  这门课真正要回答的问题:                  │
                         │  "这行 C 代码,机器到底做了什么?"          │
                         └──────────────────────────────────────────┘
                                            ▲
                                            │
   第 21 讲  调试与工具 (GDB / Valgrind)     │  ← 用工具"看见"底层
   第 20 讲  面向对象概念与其 C/C++ 实现     │
   第 19 讲  排序算法与算法权衡              │
   第 17-18 讲 链表、树(堆上的指针结构)     │
   第 15-16 讲 结构体、信息隐藏、动态内存     │
   第 13 讲  递归(栈帧的自我调用)           │
   第 9-12 讲 指针、数组、字符串             │  ← C 的核心难点
   第 5-8 讲  C 基础、函数、运行时栈          │  ← 每个概念都回指汇编
   第 1-4 讲  LC-3 汇编、I/O、子程序、栈      │  ← ECE 120 的直接延续
                         ─────────────────────
   ECE 120: 比特 → 门电路 → 有限状态机 → LC-3 指令集 → 汇编

这条链条的每一环都不可跳过,因为后面每一讲都在使用前面一讲建立的机器模型

C 概念它底下的机器事实(ECE 120/220 前四讲建立)
变量与类型一段内存 + 一段比特编码;类型是给编译器的”解读说明书”
函数调用JSR 压栈返回地址 + 在栈上建立栈帧 + RET
局部变量栈帧内 R5 相对偏移寻址的存储单元
数组一段连续内存 + 基址加偏移寻址
指针一个存着地址的字(64 位 = 8 字节)
结构体一段连续内存 + 编译期确定的成员偏移
动态内存 (malloc)sbrk 系统调用移动 heap 的 break,再由分配器切块
递归每次调用一份新的栈帧,栈就是递归的”记忆”
信息隐藏头文件只暴露函数签名,结构体定义藏在 .c

学习建议:每学一个 C 概念,都问自己三个问题—— ① 它在内存里长什么样?② 它编译成什么指令?③ 它的生命周期由谁管理(作用域 / 存储期)?


官方主题列表(Topics Covered)

来自课程目录页,一字不改:

  1. Assembly language programming with subroutines and stacks(汇编语言中的子程序与栈)
  2. Basic programming concepts in C(C 基础编程概念)
  3. Functions(函数)
  4. Arrays(数组)
  5. Pointers(指针)
  6. I/O(输入输出)
  7. Recursion(递归)
  8. Simple data structures such as linked lists and trees(链表、树等简单数据结构)
  9. Basic sorting algorithms(基本排序算法)
  10. Concepts in object-oriented programming(面向对象编程概念)

课程目标(Course Goals)

This course focuses on C programming, where each new C concept is introduced based on the fundamental concepts described in ECE 120. We cover basic programming concepts, functions, arrays, pointers, I/O, recursion, simple data structures, and concepts in object-oriented programming. A bottom-up understanding of computing systems has proven more successful in helping students to understand advanced concepts in computing that follow in the ECE curriculum.


教学目标(Instructional Objectives)—— 本笔记的知识框架

课程目录页列出 9 条教学目标,括号中的数字是 UIUC 工程学院的通识能力编号。 这 9 条就是本笔记每一讲”学习目标”栏目的直接来源

#教学目标(原文)对应本笔记
1Understand how statements written in high-level language such as C are transformed into machine code. Be able to perform such a transformation manually.L1–L8, L18
2Understand the idea of scope and storage for variables, and the role of types in high-level languages in providing information to the compiler.L5
3Understand the stack abstraction and the notion of a calling convention and its role in supporting the transfer of information between a caller and a subroutine.L3, L4, L8
4Understand the concepts of arrays and pointers and their representations in memory. Be able to use arrays and pointers for problem solving.L9–L12
5Be able to develop and use data structures for representing and aggregating information.L11, L15, L17, L18
6Be able to use dynamic memory allocation for storing values and objects in memory.L16, L17
7Understand the value of recursion as a problem-solving tool and be able to apply it for solving math and logical problems.L13
8Be able to test and debug programs written in C using standard debugging tools and techniques.L21
9Be familiar with the concepts of object-oriented programming.L20

Fall 2025 版课程网站另外补充了 6 条更细的目标:

  • be familiar with basic data organizations such as arrays, structures, lists, trees, jump tables, and how they are laid out in memory(熟悉基本数据组织及其内存布局)
  • be able to write assembly language programs that make use of these data structures
  • understand the transformation between programming constructs in languages such as C and their implementation on a modern microprocessor
  • be able to write C programs to accomplish simple tasks, such as functional simulation of a processor
  • understand the importance of structuring code in a way that it can be tested, be able to write effective tests, and be familiar with tools for aiding in this process
  • be familiar with implementations of basic data structures and operations on them

以及四条工程素养目标:理解工程学科对投入、质量、客观性的要求;认识到自我驱动与终身学习 是工程成功的必要条件;能够阐述权衡(tradeoff)的重要性;能够识别基本的设计权衡。

注意第 1 条里的那句话:”Be able to perform such a transformation manually.” 这不是修辞。ECE 220 的考试要求学生手写 C 到 LC-3 的翻译。这也是本笔记每一讲都保留 【与汇编的对应】栏目的原因——它直接对应考试能力。


与 ECE 120 的衔接

ECE 120 结束在 LC-3 指令集与基础汇编;ECE 220 从同一本教材的下一章接着讲:

 ECE 120ECE 220
起点比特、逻辑门、组合电路、有限状态机LC-3 汇编的 I/O、子程序、栈
机器模型LC-3 数据通路、指令集、汇编基础调用约定、栈帧、内存布局、堆
语言LC-3 汇编LC-3 汇编 → C → C++ 概念
数据组织单个变量、简单数组数组、结构体、链表、树、跳转表
终点“计算机如何执行一条指令”“高级语言程序如何变成一组指令与内存布局”

教材进度对照(来自 Fall 2025 公开课表):

  • 第 8 章(2 版)/ 第 9 章(3 版):Memory-mapped I/O、TRAP、子程序
  • 第 10 章:栈数据结构与栈操作
  • 第 11–13 章:C 的数据类型、变量、运算符、控制结构
  • 第 14 章:C 函数、运行时栈
  • 第 16 章:指针与数组
  • 第 17 章:递归
  • 第 18 章:C 文件 I/O
  • 第 19 章:数据结构、动态内存、链表
  • 第 20 章:数据结构续、树、C++ 与面向对象
  • 第 5.4 / 9.4 节:中断与异常、中断驱动 I/O、TRAP

考核结构(Fall 2025)

MPs (Machine Problems)   ██████               15%
Midterms (2 次)          ████████████████     40%
Final Exam               ██████████           25%
Quizzes (6 次 CBTF)      ████████             20%
                         ─────────────────────
                         100%     (Lab 仅提供加分,不计入 100%)
  • MPs:约每周一个编程作业,每个 100 分。前两个用 LC-3 汇编,其余用 C(最后一个涉及 C++)。 通过 GitHub 提交,允许 3 人小组,但每人必须提交自己的副本。 迟交每小时扣 2 分,最多迟 48 小时;MP1–MP11 中最低分会被丢弃。
  • Quizzes:6 次 CBTF(Computer-Based Testing Facility)机考,最低分丢弃。
  • Exams:两次期中 + 一次期末,线下纸笔考试,可以用手写方式考察 C 到 LC-3 的翻译
  • Labs:每周五的编程练习课,完成 worksheet 可得 10 分加分,用于弥补 MP1–MP11 的失分。

工具链(Toolchain)——课程明确要求掌握三类工具:

  1. LC-3 工具lc3tools 汇编器 / 模拟器,含 lc3sim-tk 图形界面)
  2. Git(作业分发与提交,SSH key 配置,远程工作)
  3. GCC / GDB 编译器-调试器组合,以及 Valgrind

课程的官方编译命令(务必照抄,不要省略警告选项):

gcc -g -std=c99 -Wall -Werror -o output_executable -l library1 source_file1.c [source_file2.c] ...

本笔记如何使用

每一讲严格按六段式组织,服务于上面 9 条教学目标:

段落作用对应教学目标
概述本讲要解决什么问题
核心概念与底层机制图解定义 / 直观解释 / 内存表示 / 作用域与存储期2, 5
代码示例与底层机制分析可运行 C 代码 + 做什么 + 底层透视 + 内存布局 + 与汇编的对应1, 3, 4, 6
常见错误与调试技巧真实 bug 与可执行的调试命令8
关键要点结论与编程准则全部
思考题(带答案)自测全部

两条使用建议:

  1. 不要跳过汇编部分。 第 1–4 讲的 LC-3 内容不是”复习”,它是后面所有 C 概念的解释框架。 如果你不理解 R5(帧指针)和 R6(栈指针)的区别,第 8 讲”运行时栈”就只能是死记硬背。
  2. 每个代码示例都亲手跑一遍。 本笔记中所有 C 代码都已在 gcc -g -std=c99 -Wall -Werror 下实际编译运行验证过。请打开 GDB 单步执行它们, 用 x/8xb 看内存,用 p &var 看地址——把笔记里的 ASCII 图变成你屏幕上真实的地址, 这是把”知道”变成”理解”的唯一途径。

关于资料来源的说明(透明记录)

本笔记的资料获取过程如下,已公开的内容与未公开的内容都如实记录

✅ 公开可访问并已获取:

  • 课程目录页的完整官方描述、主题列表、Course Goals、9 条 Instructional Objectives
  • Fall 2025 课程网站:syllabus(含 6 条补充目标)、逐周课程表(含教材章节对照)、 27 讲的讲座索引页、MP 与 Lab 的标题与截止日期
  • Resources 栏目下的三个完整公开页面:GDB quick reference(完整命令参考)、 C coding conventions(代码风格规范)、C Programming Reference (完整的基本类型/派生类型/字面量/运算符/printf-scanf 格式说明符表格)
  • 归档的 Prof. Steven Lumetta ECE 220 Fall 2020 (ZJUI) / Spring 2018 (Honors) 公开站点: 58 份完整讲座幻灯片、15 份 Lab 讲义、12 份 MP 讲义、历年期中/期末试卷(含答案与勘误), 以及完整的 C 与 LC-3 示例代码(含一个真实可用的动态内存分配器 mem220

⚠️ 未公开 / 需登录,仅记录名称:

  • MP01MP12 的完整讲义:当前网站的路径为 /ece220/fa2025/secure/mps/mpNN/secure/ 路径不对公众开放。公开的只有标题(如 “MP 04 – Debugging with GDB”) 与截止日期。本笔记用其标题来佐证对应讲次的教学重点。
  • Lab01Lab13 的完整 worksheet:路径 /ece220/fa2025/secure/labs/labNN,同样不公开。 公开的只有标题(如 “Lab 10 – Linked List”、”Lab 12 – Lowest Common Ancestor”)。
  • Spring 2026 讲座幻灯片 PDF:讲座索引页公开列出了 27 讲的 PDF 链接, 但截至获取时 PDF 资产本身尚未上传(访问返回 Grainger 模板占位页)。 本笔记因此改用上面归档的 Lumetta 幻灯片作为公开补充来源。
  • 考试试卷(/evaluation/exams)、CBTF 测验内容、Piazza 论坛、Gradescope 提交: 需要登录,未访问。

Fall 2025 公开的 MP 标题(用于佐证教学重点):

MP标题语言
MP 01Printing histogramLC-3 汇编
MP 02Stack calculatorLC-3 汇编
MP 03Pascal’s triangleC
MP 04Debugging with GDBC
MP 05CodebreakerC
MP 06Game of LifeC
MP 07Sudoku SolverC
MP 082048C
MP 09MazeC
MP 10Sparse MatrixC
MP 11Introduction to C++C++
MP 12AnagramsC

Fall 2025 公开的 Lab 标题:Printing hexadecimals;Problem solving with stack; Computing a math function;Printing Prime Numbers;Random Numbers;Matrix Multiplication in C; Mini Sudoku;2048 Preparation;Vectors;Linked List;C++ Classes;Lowest Common Ancestor;Recap。

这些标题本身就是极好的教学信号:MP04 直接就是”用 GDB 调试”MP11 是 C++ 入门Lab 12 是”最低公共祖先”(树)—— 说明调试、面向对象和树结构在本课程中都是一等公民,而不是附录。


讲座序列与主文档结构

本笔记按”从汇编到 C 到数据结构”的逻辑顺序组织为 21 讲,覆盖官方全部主题与 9 条教学目标:

第一部分 · 机器层(承接 ECE 120)

  • Lecture 1:课程概述与自底向上方法论;LC-3 机器模型复习
  • Lecture 2:内存映射 I/O 与 TRAP
  • Lecture 3:子程序与调用约定(Call Interface Specification)
  • Lecture 4:栈抽象、栈帧与用栈做算术

第二部分 · C 语言与机器码的映射

  • Lecture 5:C 语言入门——数据类型、运算符、作用域与存储期
  • Lecture 6:C 控制结构与基本 I/O
  • Lecture 7:C 函数——定义、调用、参数传递与返回值
  • Lecture 8:C 函数的实现——运行时栈与栈帧

第三部分 · 指针与数组(课程核心难点)

  • Lecture 9:指针
  • Lecture 10:数组
  • Lecture 11:字符串与多维数组
  • Lecture 12:用指针与数组解决问题;函数指针与回调

第四部分 · 程序组织与内存

  • Lecture 13:递归
  • Lecture 14:文件 I/O
  • Lecture 15:数据结构——结构体、typedef 与信息隐藏
  • Lecture 16:动态内存分配

第五部分 · 数据结构与算法

  • Lecture 17:链表
  • Lecture 18:树、遍历与搜索;从 C 到 LC-3 汇编
  • Lecture 19:基本排序算法

第六部分 · 工程实践

  • Lecture 20:面向对象编程概念及其在 C/C++ 中的实现
  • Lecture 21:调试工具与技术(GDB、Valgrind、assert)

附录:C 语言与系统编程核心概念速查表