第4章アルゴリズムの言語による実現:低水準プログラミング言語
4.4 Applications of Programming Models4.4 プログラミングモデルの応用
Learning Objectives学習目標
By the end of this section, you will be able to:
この節を終えると、次のことができるようになる。
• Discuss the future of low-level programming
• 低水準プログラミングの将来を論じる。
• Understand how the C language is used to develop firmware for embedded systems
• 組込みシステムのファームウェア開発に、C言語をどう使うかを理解する。
• Develop kernel code using the C programming language
• Cプログラミング言語を使って、カーネルのコードを開発する。
High-level languages are popular, and have their place, but there are certain applications where only middle-level languages such as C will do. This section showcases two such applications: firmware and kernel development.
英語のヒント
高水準言語は人気があり、適した用途もあるが、Cのような中水準言語でなければ対応できない用途もある。この節では、そのような用途を2つ、ファームウェアとカーネルの開発について紹介する。
The Future of Low-Level Programming低水準プログラミングの将来
The economic trends that diminish interest in low-level programming are expected to continue and even accelerate. We are using wider varieties of computer hardware—not just personal computers, mobile devices, and servers, but also narrower segments such as tablets, set-top boxes, video streamers, and system-on-chip (SoC) computers such as the Raspberry Pi (Figure 4.33).
英語のヒント
低水準プログラミングへの関心を弱める経済的な傾向は、今後も続き、さらに加速すると予想される。私たちが使うコンピューターハードウェアの種類は増えている。パソコン、モバイル機器、サーバーだけでなく、タブレット、セットトップボックス、動画配信機器、Raspberry Piのようなシステムオンチップ(SoC)コンピューターなど、より限定された分野にも広がっている(図4.33)。

credit: “Raspberry-Pi-2-Bare-BR” by “Evan- Amos”/Wikipedia, Public Domain · Public Domain · Source出典
Figure 4.33 A Raspberry PI demonstrates the concept of a system-on-chip (SOC). (credit: “Raspberry-Pi-2-Bare-BR” by “Evan-Amos”/Wikipedia, Public Domain)
図4.33 Raspberry Piは、システムオンチップ(SoC)の概念を示す。(クレジット:「Evan-Amos」/Wikipediaによる「Raspberry-Pi-2-Bare-BR」、パブリックドメイン)
The IoT is the growing network of products that are not used as a computer, but nevertheless contain an Internet-connected computer. IoT devices include but are not limited to smart voice assistant speakers, thermostats, home appliances, speakers, and tap payment systems. The computer embedded inside an IoT device is limited in terms of size, energy use, and cost, so it typically has a slow CPU and small memory. This makes middle-level languages well suited to writing IoT software; writing Internet-connected applications in low-level languages is impractical, and high-level languages may not be efficient enough.
英語のヒント
IoTは、コンピューターとしては使われないものの、インターネットに接続されたコンピューターを内部に含む製品の、拡大しつつあるネットワークである。IoT機器には、スマート音声アシスタントスピーカー、サーモスタット、家電、スピーカー、タッチ決済システムなどがあり、これらに限らない。IoT機器に組み込まれたコンピューターには、大きさ、消費エネルギー、費用の制約がある。そのため通常、CPUは遅く、メモリは小さい。こうした事情によって、中水準言語はIoTソフトウェアの作成に適している。インターネット接続のあるアプリケーションを低水準言語で書くのは現実的でなく、高水準言語では効率が十分でないかもしれない。
RustRust
Rust is a relatively new middle-level language created by the Mozilla Foundation in the 2010s. Many of C’s positive features are also found in Rust: efficient execution, portability, modularity, procedural and structured programming, and recursion. Rust has the capability to manipulate pointers but adds native safety features so that the compiler can help the programmer prevent bugs related to pointers. The language also includes some features that are more common to high-level languages and are unavailable in C, including higher-level data types (lists, maps, and sets), macros, templates, and parallel programming. These features do make Rust more complicated than C, though. Since Rust has the same positive attributes as C, with some additional desirable features, we expect to see increasing use of Rust as a middle-level language.
英語のヒント
Rustは、Mozilla Foundationが2010年代に作った、比較的新しい中水準言語である。効率的な実行、移植性、モジュール性、手続き型・構造化プログラミング、再帰など、Cの長所の多くはRustにもある。Rustはポインターを操作できるが、言語自体に安全のための機能を加え、コンパイラーが、ポインター関連のバグを防ぐのを助けられるようにしている。この言語には、Cにはなく、高水準言語でより一般的な機能もある。高水準のデータ型(リスト、マップ、集合)、マクロ、テンプレート、並列プログラミングなどである。ただ、これらの機能によってRustはCより複雑にもなる。RustはCと同じ長所に加え、望ましい機能も備えるため、中水準言語としての利用が増えると予想される。
GLOBAL ISSUES IN TECHNOLOGY技術をめぐる世界の課題
Naming of C ProceduresCの手続きの命名
It is a best practice to give procedures descriptive names that help a reader understand what the procedure does. English has been globally accepted as the language of programming, but this can cause some problems in non–English-speaking countries. For example, “open_file” is more descriptive than “fopen”; it is also difficult to tell what “fopen” might mean out of context and especially if you are not a native English speaker. Unfortunately, procedure names in C are almost always written in English. How can this practice of using English names affect aspiring programmers whose first language is not English? How will it make it more difficult for programmers around the world to collaborate on source code?
英語のヒント
手続きには、読者がその働きを理解しやすくなる、内容を説明する名前を付けるのが最善の慣行である。英語は世界的にプログラミングの言語として受け入れられているが、非英語圏では問題を引き起こす場合がある。たとえば「open_file」は「fopen」より内容がわかりやすい。「fopen」が何を意味するのかは、文脈がなければ、特に英語を母語としない人には判断しにくい。残念ながら、Cの手続き名は、ほとんど常に英語で書かれる。英語の名前を使うこの慣行は、英語を第一言語としないプログラマー志望者に、どのような影響を与えうるだろうか。世界各地のプログラマーがソースコードで共同作業することを、どのように難しくするだろうか。
Firmwareファームウェア
Hardware is purely physical machinery, and software is purely digital code. To bridge this gap, we have firmware, which is very low-level code that communicates directly with hardware, and provides a convenient interface for other software. (“Firm” is the halfway point between “hard” and “soft.”)
英語のヒント
ハードウェアは純粋に物理的な機械であり、ソフトウェアは純粋にデジタルなコードである。この隔たりを埋めるのがファームウェアである。これは、ハードウェアと直接通信し、ほかのソフトウェアに便利なインターフェースを提供する、非常に低水準のコードである(firmは、hardとsoftの中間の硬さを表す)。
If you want to learn to be an embedded systems engineer, it would be best to start from a simple hardware kit, rather than starting with the latest Intel or ARM chipset. Arduino is a hardware platform intended for creating simple, low-cost hardware for educational or hobbyist purposes. There are many series of Arduinos, but their "Arduino PLC Starter Kit" has a simple processor and comes with a guide book. Atmega328P has an 8-bit core, which is a good place to start digital circuit design and firmware development. You do not need to know how to draw schematics and layouts and assemble the chips. But you do need to know how to read schematics and understand how the chips are connected. Firmware developers should be able to read the schematics and figure out how to send data to the target device.
英語のヒント
組込みシステムの技術者になるために学ぶなら、最新のIntelやARMのチップセットではなく、単純なハードウェアキットから始めるのがよい。Arduinoは、教育や趣味のための、単純で安価なハードウェアを作ることを意図したハードウェアプラットフォームである。Arduinoには多くのシリーズがあるが、「Arduino PLC Starter Kit」は、単純なプロセッサーとガイドブックを備える。Atmega328Pには8ビットのコアがあり、デジタル回路設計とファームウェア開発を始めるのによい。回路図や配置図の描き方や、チップを組み立てる方法を知る必要はない。しかし、回路図の読み方と、チップ同士がどう接続されているかは、理解する必要がある。ファームウェア開発者は、回路図を読み、対象の装置へデータを送る方法を把握できるべきである。