注意:这篇文章上次更新于1122天前,文章内容可能已经过时。
This article was last updated1122 days ago, the content may be outdated.
今天开始开启了人生新阶段,从学生身份转变为社会人儿了。
也从 3 年的 CVer 即将变成 Coder 了。
3 年的 CV 生涯可以说是毫无建树,希望在未来的两年能够有所收获,成为一名工程师。
码农界流传着一种说法,想要获得长足的发展,基础一定要牢固。所以我决定花半年左右的时间学习《操作系统》这门课程,至于为什么是操作系统,因为 jyywiki.cn 的教程制作精良,不学有些可惜了。
本系列的博客主要为 jyywiki.cn 的示例代码作笔记,以便于加深印象。
Today marks the beginning of a new chapter in my life, transitioning from a student to a member of the working world.
I’m also about to go from a CVer of 3 years to a Coder.
My 3 years of CV research can hardly be said to have accomplished anything. I hope to gain something in the next two years and become an engineer.
There’s a saying among coders: to achieve long-term growth, you must have a solid foundation. So I’ve decided to spend about half a year studying the Operating Systems course. Why operating systems? Because the tutorials on jyywiki.cn are so well-made that it would be a shame not to study them.
This blog series mainly serves as notes on the example code from jyywiki.cn, to help deepen my understanding.
绪论
Demo: 数学概念的探索与发现
1 | # Life is short; you need Python. |
这是一段 Python 的代码,用于画一个函数的图像,其中 z3 库可以用于解方程(就先这么认为吧), numpy 很熟悉了,现代人工智能的基石,sympy 与 numpy 不同,它是用于符号计算(而不是数值计算)的。
1 | def interpolate(n, xs, ys): |
第二个代码比第一个更加晦涩一些,主要涉及库的使用方法。这个函数的目的是给定一些点,找到一条多项式曲线能够穿过这些点。# 1 的部分构建了一系列关于系数的线性方程组,这可以说是大学线性代数的知识,也可以说是初中的解方程组知识,# 2 的部分是求解方程组获得系数,最后 f 返回符号方程。
其实我看的也很晕。
于是调试了一下看看输出的都是什么东西。
1 | xs = [-1, 0, 1, 2, 3] |
Demo: 模拟数字系统
1 |
|
这是一个模拟数码管的程序,嗯… 记得单片机课程上学过数码管啥的,但是忘没了啊。这段代码实际上就是 VHDL 的写法。
但是这里有一个我已经遗忘了的 C 语言语法,结构体初始化的时候使用.符号来指定初始化成员。
1 | reg b1 = {.in = &X1, .out = &X}; |
为了验证这段程序是正确的,写一个 Python 脚本来解析一下上个程序的输出。
这里涉及到了 Unix 哲学,“管道”。
1 | ./a.out | python3 seven-seg.py # The UNIX Philosophy |
seven-seg.py 的写法如下:
1 | import fileinput |
这里有一个很有趣的想法,是我没有想到的。当看到DISPLAY 的时候我大概知道是要进行替换,我的想法自然是从 a.out 输出的字符串中进行解析,获得 A - G 的值。
而这段代码却直接把 a.out 的输出直接作为 Python 代码执行了。exec(line),然后再通过 globals() 字典获得 A - G 的值。

Demo: 模拟 RISC-V 指令执行
这个Demo就更难了,作了一个模拟指令执行的程序来求解鸡兔同笼问题。
1 | //@file_name: uncore.c |
1 | //@file_name: rvemu.c |
1 | @file_name: ji_tu.txt |
1 | a.out: rvemu.c uncore.c |
这个 Demo 实在看不懂,不过也有所收获,就是这段代码也有一个我遗忘的 C 语法,用 : 来指定结构体的默认值。
1 | typedef struct { u32 op:7, rd:5, f3:3, rs1:5, rs2:5, f7:7; } inst_t; |
看来我的 C 基础不行啊。
Introduction
Demo: Exploring and Discovering Mathematical Concepts
1 | # Life is short; you need Python. |
This is a piece of Python code used to plot the graph of a function. The z3 library can be used to solve equations (let’s just think of it that way for now). numpy is very familiar — it’s the cornerstone of modern AI. sympy is different from numpy: it is used for symbolic computation (rather than numerical computation).
1 | def interpolate(n, xs, ys): |
The second piece of code is more obscure than the first, mainly involving the usage of the libraries. The purpose of this function is: given some points, find a polynomial curve that passes through them. The # 1 part builds a series of linear equations about the coefficients — this is college linear algebra knowledge, or you could say it’s middle-school equation solving. The # 2 part solves the equations to obtain the coefficients, and finally f returns the symbolic equation.
To be honest, I was quite confused looking at it too.
So I did some debugging to see what the outputs actually are.
1 | xs = [-1, 0, 1, 2, 3] |
Demo: Simulating a Digital System
1 |
|
This is a program that simulates a seven-segment display. Hmm… I remember learning about seven-segment displays in the microcontroller course, but I’ve forgotten it all. This code is actually written in the style of VHDL.
But there’s a C syntax here that I had forgotten: when initializing a struct, the . symbol is used to specify the members being initialized.
1 | reg b1 = {.in = &X1, .out = &X}; |
To verify that this program is correct, I wrote a Python script to parse the output of the previous program.
This involves the Unix philosophy — the “pipe”.
1 | ./a.out | python3 seven-seg.py # The UNIX Philosophy |
seven-seg.py is written as follows:
1 | import fileinput |
There’s a very interesting idea here that I hadn’t thought of. When I saw DISPLAY, I roughly knew that replacement was needed; my natural idea was to parse the string output from a.out to obtain the values of A - G.
But this code instead directly executes a.out’s output as Python code. It calls exec(line), and then obtains the values of A - G through the globals() dictionary.

Demo: Simulating RISC-V Instruction Execution
This Demo is even harder — it’s a program that simulates instruction execution to solve the classic “chickens and rabbits in the same cage” problem.
1 | //@file_name: uncore.c |
1 | //@file_name: rvemu.c |
1 | @file_name: ji_tu.txt |
1 | a.out: rvemu.c uncore.c |
I really can’t understand this Demo, but I still gained something: this code also contains a C syntax I had forgotten — using : to specify the struct’s default values.
1 | typedef struct { u32 op:7, rd:5, f3:3, rs1:5, rs2:5, f7:7; } inst_t; |
It seems my C fundamentals are really weak.


