Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2019-01-20 10:29:03 +08:00
commit d7384a6b91
10 changed files with 268 additions and 252 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (qhwdw)
[#]: reviewer: (wxy)
[#]: publisher: ()
[#]: url: ()
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-10458-1.html)
[#]: subject: (Computer Laboratory Raspberry Pi: Lesson 1 OK01)
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html)
[#]: author: (Robert Mullins http://www.cl.cam.ac.uk/~rdm34)
@ -199,12 +199,12 @@ b loop$
[^1]: 是的,我说错了,它告诉的是链接器,它是另一个程序,用于将汇编器转换过的几个代码文件链接到一起。直接说是汇编器也没有大问题。
[^2]: 其实它们对你很重要。由于 GNU 工具链主要用于开发操作系统,它要求入口点必须是名为 `_start` 的地方。由于我们是开发一个操作系统,无论什么时候,它总是从 `_start` 开时的,而我们可以使用 `.section .init` 命令去设置它。因此,如果我们没有告诉它入口点在哪里,就会使工具链困惑而产生警告消息。所以,我们先定义一个名为 `_start` 的符号,它是所有人可见的(全局的),紧接着在下一行生成符号 `_start` 的地址。我们很快就讲到这个地址了。
[^3]: 本教程的设计减少了你阅读树莓派开发手册的难度,但是,如果你必须要阅读它,你可以在这里 [SoC-Peripherals.pdf](https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads/SoC-Peripherals.pdf) 找到它。由于添加了混淆,手册中 GPIO 使用了不同的地址系统。我们的操作系统中的地址 0x20200000 对应到手册中是 0x7E200000。
[^4]: mov 能够加载的值只有前 8 位是 1s 的二进制表示的值。换句话说就是一个 0s 后面紧跟着 8 个 1s 或 0s
[^4]: `mov` 能够加载的值只有前 8 位是 `1` 的二进制表示的值。换句话说就是一个 0 后面紧跟着 8 个 `1``0`
[^5]: 一个很友好的硬件工程师是这样向我解释这个问题的:
原因是现在的芯片都是用一种称为 CMOS 的技术来制成的,它是互补金属氧化物半导体的简称。互补的意思是每个信号都连接到两个晶体管上,一个是使用 N 型半导体的材料制成,它用于将电压拉低,而另一个使用 P 型半导体材料制成它用于将电压升高。在任何时刻仅有一个半导体是打开的否则将会短路。P 型材料的导电性能不如 N 型材料。这意味着三倍大的 P 型半导体材料才能提供与 N 型半导体材料相同的电流。这就是为什么 LED 总是通过降低为低电压来打开它,因为 N 型半导体拉低电压比 P 型半导体拉高电压的性能更强。
还有一个原因。早在上世纪七十年代,芯片完全是由 N 型材料制成的NMOSP 型材料部分使用了一个电阻来代替。这意味着当信号为低电压时,即便它什么事都没有做,芯片仍然在消耗能量(并发热)。你的电话装在口袋里什么事都不做,它仍然会发热并消耗你的电池电量,这不是好的设计。因此,信号设计成 'active low',而不活动时为高电压,这样就不会消耗能源了。虽然我们现在已经不使用 NMOS 了,但由于 N 型材料的低电压信号比 P 型材料的高电压信号要快,所以仍然使用了这种设计。通常在一个 'active low' 信号名字上方会有一个条型标记,或者写作 SIGNAL_n 或 /SIGNAL。但是即便这样仍然很让人困惑那怕是硬件工程师也不可避免这种困惑
还有一个原因。早在上世纪七十年代,芯片完全是由 N 型材料制成的NMOSP 型材料部分使用了一个电阻来代替。这意味着当信号为低电压时,即便它什么事都没有做,芯片仍然在消耗能量(并发热)。你的电话装在口袋里什么事都不做,它仍然会发热并消耗你的电池电量,这不是好的设计。因此,信号设计成 “活动时低”,而不活动时为高电压,这样就不会消耗能源了。虽然我们现在已经不使用 NMOS 了,但由于 N 型材料的低电压信号比 P 型材料的高电压信号要快,所以仍然使用了这种设计。通常在一个 “活动时低” 信号名字上方会有一个条型标记,或者写作 `SIGNAL_n``/SIGNAL`。但是即便这样,仍然很让人困惑,那怕是硬件工程师,也不可避免这种困惑!
--------------------------------------------------------------------------------

View File

@ -1,128 +0,0 @@
zhs852 is translating.
Dawn of the Microcomputer: The Altair 8800
======
Subscribers to Popular Electronics were a sophisticated group. The magazines editor, Arthur Salsberg, felt compelled to point out as much in the editorial section of the [December 1974 issue][1]. The magazine had received letters complaining that a recent article, titled “How to Set Up a Home TV Service Shop,” would inspire a horde of amateur TV technicians to go out and undercut professional repairmen, doing great damage to everyones TVs in the process. Salsberg thought this concern was based on a misunderstanding about who read Popular Electronics. He explained that, according to the magazines own surveys, 52% of Popular Electronics subscribers were electronics professionals of some kind and 150,000 of them had repaired a TV in the last 60 days. Moreover, the average Popular Electronics subscriber had spent $470 on electronics equipment ($3578 in 2018) and possessed such necessities as VOMs, VTVMs, tube testers, transistor testers, r-f signal generators, and scopes. “Popular Electronics readers are not largely neophytes,” Salsberg concluded.
I am surprised that anyone familiar with Popular Electronics could ever have doubted its subscribers. I certainly havent repaired a TV in the last 60 days. My computer is a block of aluminum that I have never seen the inside of. Yet the December 1974 issue of Popular Electronics features articles such as “Standing Wave Ratio: What It Is and How to Deal with It” and “Test Scene: Uses for Your Multimeter.” Even the ads are intimidating. One of them, which seems to be for some kind of stereo system, boldly proclaims that “no piece of audio equipment is as eagerly awaited as the one four-channel unit that does everything—i.e. the receiver with built-in circuitry for SQ, RM and CD-4 record decoding.’” The mere hobbyists subscribed to Popular Electronics, let alone the professionals, must have been very knowledgeable indeed.
But Popular Electronics readers were introduced to something in the [January 1975 issue][2] that they had never encountered before. Below a heading that read “PROJECT BREAKTHROUGH,” the magazines cover showed a large gray and black box whose front panel bore a complicated array of lights and toggles. This was the Altair 8800, the “worlds first minicomputer kit to rival commercial models,” available for under $400. Though advertised as a “minicomputer,” the Altair would actually be the first commercially successful member of a new class of computers, first known as “microcomputers” and then eventually as PCs. The Altair was small enough and cheap enough that the average family could have one at home. Its appearance in Popular Electronics magazine meant that, as Salsberg wrote in that issue, “the home computer age is here—finally.”
![January 1975 cover of Popular Electronics][3]
I have written briefly about [the Altair before][4], but I think the Altair is worth revisiting. It was not an especially powerful computer compared to others available at the time (though it cost significantly less money). Nor was it the first general-purpose computer to incorporate a microprocessor chip—at least three microprocessor-based computers preceded it. But the Altair was and is a kind of Ur-Computer for all of us. It was the first popular computer in a lineage that includes our own devices, whereas the mainframes and bulky minicomputers that predated the Altair were an entirely different kind of machine, programmed by punched card or else rarely interacted with directly. The Altair was also a radically simple computer, without any kind of operating system or even a bootloader. Unless you bought peripherals for it, the Altair was practically a bank of RAM with switches and lights on the front. The Altairs simplicity makes learning about it a great way to reacquaint yourself with the basic concepts of computing, exactly as they were encountered by the denizens of the old analog world as they first ventured into our digital one.
### Roberts and Co.
The Altair was designed and manufactured by a company called Micro Instrumentation and Telemetry Systems (MITS), based in Albuquerque, New Mexico. MITS was run by a man named H. Edward Roberts. The company had started off making telemetry systems for model rocket kits before moving into the calculator market, which in the early 1970s was booming. Integrated circuits were bringing the cost of a calculator down dramatically and suddenly every working American professional had to have one. But the calculator market was ruthlessly competitive and, by the beginning of 1974, MITS was deeply in debt.
The year 1974 would prove to be an “annus mirabilis” in computing. In January, Hewlett-Packard introduced the HP-65, the worlds first programmable handheld calculator. In April, Intel released the Intel 8080, its second 8-bit microprocessor and the first microprocessor to become widely popular. Then, in July, Radio Electronics magazine advertised a build-it-yourself minicomputer called the Mark-8, which employed the Intel 8008 microprocessor that Intel had released in 1972. The Mark-8 was only the third computer ever built using a microprocessor and it was the first to be appear on the cover of a magazine. The Mark-8s appearance in Radio Electronics pushed Popular Electronics to look for a minicomputer project of their own to feature.
Popular Electronics subscribers actually received their copies of the January 1975 issue in the mail in December of 1974. So the announcement of the Altair closed out the “annus mirabilis” that was that year. The Altairs introduction was so momentous because never before had such a fully capable computer been offered to the public at an affordable price. The PDP-8, one the most popular minicomputers at the time, could only be bought for several thousand dollars. Yet the Intel 8080 chip at the heart of the Altair made it almost as capable as the PDP-8, if not more so; the 8080 supported a wider instruction set and the Altair could be expanded to have up to 64kb of memory, while the stock PDP-8 typically only had 4kb. The Altair was also more powerful than the Mark-8, which, because it was based on the Intel 8008, could only address 16kb of memory. And whereas the Mark-8 had to be built from scratch by customers with only a booklet and printed circuit boards to guide them, the Altair could be purchased fully assembled, though MITS soon became so inundated with orders that the only real way to get an Altair was to order the construction kit.
For many Popular Electronics readers, the Altair was their first window into the world of digital computing. The article introducing the Altair in the January 1975 issue was written by Roberts and the Altairs co-designer, William Yates. Roberts and Yates took pains to explain, in terms familiar to the electricians and radio enthusiasts in their audience, the basic concepts underlying digital hardware and computer programming. “A computer,” they wrote, “is basically a piece of variable hardware. By changing the bit pattern stored in the memory, the hardware can be altered from one type of device to another.” Of programming, meanwhile, Roberts and Yates wrote that the basic concepts are “simple enough to master in a relatively short time,” but that becoming “an efficient programmer requires a lot of experience and a large amount of creativity,” which sounds about right to me. The article included a detailed diagram explaining all the constituent circuits of the Intel 8080 CPU, even though readers would receive at least that part fully assembled. It explained the difference between a CPU and a computers memory unit, the uses of a stack pointer, and the enormous advantages offered by assembly languages and higher-level languages like FORTRAN and BASIC over manual entry of machine code.
Popular Electronics had in fact been running a series written by Roberts for several issues before January 1975. The series was billed as a short course in “digital logic.” In the December 1974 issue, Roberts walked readers through building a “very low cost computer terminal,” which was basically an octal keypad that could input values into an 8-bit computer. In the course of describing the keypad, Roberts explained how transistor-to-transistor logic works and also how to construct a flip-flop, a kind of circuit capable of “remembering” digital values. The keypad, Roberts promised, could be used with the Altair computer, to be announced the following month.
Its unclear how many Popular Electronics readers actually built the keypad, but it would have been a very useful thing to have. Without a keypad or some other input mechanism, the only way to input values into the Altair was through the switches on the front panel. The front panel had a row of 16 switches that could be used to set an address and a lower row of eight switches that could be used to control the operation of the computer. The eight right-most switches in the row of 16 could also be used to specify a value to be stored in memory. This made sense because the Intel 8080 used 16-bit values to address 8-bit words. The 16 switches on the front panel each represented a bit—the up position represented a one, while the down position represented a zero. Interacting with a computer this way is a revelation (more on that in a minute), because the Altairs front panel is a true binary interface. Its as close as you can get to the bare metal.
As alien as the Altairs interface is to us today, it was not unusual for its time. The PDP-8, for example, had a similar binary input mechanism on its front panel, though the PDP-8s switches were nicer and colored in that attractive orange and yellow color scheme that really ought to make a comeback. The PDP-8, however, was often paired with a paper-tape reader or a teletype machine, which made program entry much easier. These I/O devices were expensive, meaning that most Altair users in the early days were stuck with the front panel. As you might imagine, entering long programs via the switches was a chore. Eventually the Altair could be hooked up to a cassette recorder and programs could be loaded that way. Bill Gates and Paul Allen, in what would become Microsofts first ever commercial venture, also wrote a version of BASIC for the Altair that MITS licensed and released in the middle of 1975. Users that could afford a teletype could then [load BASIC into the Altair via paper tape][5] and interact with their Altair through text. BASIC, which had become everyones favorite introductory programming language in schools, would go on to become the standard interface to the machines produced in the early microcomputer era.
### z80pack
Thanks to the efforts of several internet people, in particular a person named Udo Munk, you can run a simulation of the Altair on your computer. The simulation is built on top of some software that emulates the Zilog Z80 CPU, a CPU designed to be software-compatible with the Intel 8080. The Altair simulation allows you to input programs entirely via the front panel switches like early users of the Altair had to do. Though clicking on switches does not offer the same tactile satisfaction as flipping real switches, playing with the Altair simulation is a great way to appreciate how a binary human/computer interface was both horribly inefficient and, at least in my opinion, charmingly straightforward.
z80pack, Udo Munks Z80 emulation package, can be downloaded from the z80pack website. There are instructions in [my last Altair post][4] explaining how to get it set up on Mac OS. If you are able to compile both the FrontPanel library and the `altairsim` executable, you should be able to run `altairsim` and see the following window:
![Simulated Altair Front Panel][6]
By default, at least with the version of z80pack that I am using (1.36), the Altair is configured with something called Tarbell boot ROM, which I think is used to load disk images. In practice, what this means is that you cant write values into the first several words in RAM. If you edit the file `/altairsim/conf/system.conf`, you can instead set up a simple Altair that has 16 pages of RAM and no ROM or bootloader software at all. You can also use this configuration file to increase the size of the window the simulation runs in, which is handy.
The front panel of the Altair is intimidating, but in reality there isnt that much going on. The [Altair manual][7] does a good job of explaining the many switches and status lights, as does this [YouTube video][8]. To enter and run a simple program, you only really need to know a few things. The lights labeled D0 through D7 near the top right of the Altair indicate the contents of the currently addressed word. The lights labeled A0 through A15 indicate the current address. The 16 switches below the address lights can be used to set a new address; when the “EXAMINE” switch is pressed upward, the data lights update to show the contents of the newly addressed word. In this way, you can “peek” at all the words in memory. You can also press the “EXAMINE” switch down to the “EXAMINE NEXT” position, which automatically examines the next memory address, which makes peeking at sequential words significantly easier.
To save a bit pattern to a word, you have to set the bit pattern using the right-most eight switches labeled 0 through 7. You then press the “DEPOSIT” switch upward.
In the [February 1975 issue][9] of Popular Electronics, Roberts and Yates walked Altair owners through inputting a small sample program to ensure that their Altair was functioning. The program loads two integers from memory, adds them, and saves the sum back into memory. The program consists of only six instructions, but those six instructions involve 14 words of memory altogether, which takes some time to input correctly. The sample program also appears in the Altair manual in table form, which Ive reproduced here:
Address Mnemonic Bit Pattern Octal Equivalent 0 LDA 00 111 010 0 7 2 1 (address) 10 000 000 2 0 0 2 (address) 00 000 000 0 0 0 3 MOV B, A 01 000 111 1 0 7 4 LDA 00 111 010 0 7 2 5 (address) 10 000 001 2 0 1 6 (address) 00 000 000 0 0 0 7 ADD B 10 000 000 2 0 0 8 STA 00 110 010 0 6 2 9 (address) 10 000 010 2 0 2 10 (address) 00 000 000 0 0 0 11 JMP 11 000 011 3 0 3 12 (address) 00 000 000 0 0 0 13 (address) 00 000 000 0 0 0
If you input each word in the above table into the Altair via the switches, you end up with a program that loads the value in word 128, adds it to the value in the word 129, and finally saves it into word 130. The addresses that accompany each instruction taking an address are given with the least-significant bits first, which is why the second byte is always zeroed out (no addresses are higher than 255). Once youve input the program and entered some values into words 128 and 129, you can press the “RUN” switch into the down position briefly before pushing it into the “STOP” position. Since the program loops, it repeatedly adds those values and saves the sum thousands of times a second. The sum is always the same though, so if you peek at word 130 after stopping the program, you should find the correct answer.
I dont know whether any regular users of the Altair ever had access to an assembler, but z80pack includes one. The z80pack assembler, `z80asm`, is meant for Z80 assembly, so it uses a different set of mnemonics altogether. But since the Z80 was designed to be compatible with software written for the Intel 8080, the opcodes are all the same, even if the mnemonics are different. So just to illustrate what it might have been like to write the same program in assembly, here is a version that can be assembled by `z80asm` and loaded into the Altair:
```
ORG 0000H
START: LD A,(80H) ;Load from address 128.
LD B,A ;Move loaded value from accumulator (A) to reg B.
LD A,(81H) ;Load from address 129.
ADD A,B ;Add A and B.
LD (82H),A ;Store A at address 130.
JP START ;Jump to start.
```
You can turn this into something called an Intel HEX file by invoking the assembler like so (after you have compiled it):
```
$ ./z80asm -fh -oadd.hex add.asm
```
The `-f` flag, here taking `h` as an argument, specifies that a HEX file should be output. You can then load the program into the Altair by passing the HEX file in using the `-x` flag:
```
$ ./altairsim -x add.hex
```
This sets up the first 14 words in memory as if you had input the values manually via the switches. Instead of doing all that again, you can just run the program by using the “RUN” switch as before. Much easier!
As I said, I dont think many Altair users wrote software this way. Once Altair BASIC became available, writing BASIC programs was probably the easiest way to program the Altair. z80pack also includes several HEX files containing different versions of Altair BASIC; the one Ive been able to get working is version 4.0 of 4K BASIC, which you can load into the simulator like so:
```
$ ./altairsim -x basic4k40.hex
```
If you turn the simulated machine on and hit the “RUN” switch, you should see that BASIC has started talking to you in your terminal window. It first prompts you to enter the amount of memory you have available, which should be 4000 bytes. It then asks you a few more questions before presenting you with the “OK” prompt, which Gates and Allen used instead of the standard “READY” to save memory. From there, you can just use BASIC:
```
OK
PRINT 3 + 4
7
```
Though running BASIC with only 4kb of memory didnt give you a lot of room, you can see how it would have been a significant step up from using the front panel.
The Altair, of course, was nowhere near as capable as the home desktops and laptops we have available to us today. Even something like the Macintosh, released less than a decade later, seems like a quantum leap forward over the spartan Altair. But to those first Popular Electronics readers that bought the kit and assembled it, the Altair was a real, fully capable computer that they could own for themselves, all for the low cost of $400 and half the surface space of the credenza. This would have been an amazing thing for people that had thus far only been able to interact with computers by handing [a stack of cards][10] or a roll of tape to another human being entrusted with the actual operation of the computer. Subsequent microcomputers would improve upon what the Altair offered and quickly become much easier to use, but they were all, in some sense, just more complicated Altairs. The Altair—almost Brutalist in its minimalism—was the bare-essentials blueprint for all that would follow.
If you enjoyed this post, more like it come out every two weeks! Follow [@TwoBitHistory][11] on Twitter or subscribe to the [RSS feed][12] to make sure you know when a new post is out.
Previously on TwoBitHistory…
> "I invite you to come along with me on an exciting journey and spend the next ten minutes of your life learning about a piece of software nobody has used in the last decade." <https://t.co/R9zA5ibFMs>
>
> — TwoBitHistory (@TwoBitHistory) [July 7, 2018][13]
--------------------------------------------------------------------------------
via: https://twobithistory.org/2018/07/22/dawn-of-the-microcomputer.html
作者:[Two-Bit History][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://twobithistory.org
[b]: https://github.com/lujun9972
[1]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1974/Poptronics-1974-12.pdf
[2]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-01.pdf
[3]: https://twobithistory.org/images/jan1975-altair.jpg
[4]: https://twobithistory.org/2017/12/02/simulating-the-altair.html
[5]: https://www.youtube.com/watch?v=qv5b1Xowxdk
[6]: https://www.autometer.de/unix4fun/z80pack/altair.png
[7]: http://www.classiccmp.org/dunfield/altair/d/88opman.pdf
[8]: https://www.youtube.com/watch?v=suyiMfzmZKs
[9]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-02.pdf
[10]: https://twobithistory.org/2018/06/23/ibm-029-card-punch.html
[11]: https://twitter.com/TwoBitHistory
[12]: https://twobithistory.org/feed.xml
[13]: https://twitter.com/TwoBitHistory/status/1015647820353867776?ref_src=twsrc%5Etfw

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (beamrolling)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,68 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (qhwdw)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Computer Laboratory Raspberry Pi: Lesson 2 OK02)
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html)
[#]: author: (Robert Mullins http://www.cl.cam.ac.uk/~rdm34)
Computer Laboratory Raspberry Pi: Lesson 2 OK02
======
The OK02 lesson builds on OK01, by causing the 'OK' or 'ACT' LED to turn on and off repeatedly. It is assumed you have the code for the [Lesson 1: OK01][1] operating system as a basis.
### 1 Waiting
Waiting is a surprisingly useful part of Operating System development. Often Operating Systems find themselves with nothing to do, and must delay. In this example, we wish to do so in order to allow the LED flashing off and on to be visible. If you just turned it off and on, it would not be visible, as the computer would be able to turn it off and on many thousands of times per second. In later lessons we will look at accurate waiting, but for now it is sufficient to simply waste time.
```
mov r2,#0x3F0000
wait1$:
sub r2,#1
cmp r2,#0
bne wait1$
```
```
sub reg,#val subtracts the number val from the value in reg.
cmp reg,#val compares the value in reg with the number val.
Suffix ne causes the command to be executed only if the last comparison determined that the numbers were not equal.
```
The code above is a generic piece of code that creates a delay, which thanks to every Raspberry Pi being basically the same, is roughly the same time. How it does this is using a mov command to put the value 3F000016 into r2, and then subtracting 1 from this value until it is 0. The new commands here are sub, cmp, and bne.
sub is the subtract command, and simply subtracts the second argument from the first.
cmp is a more interesting command. It compares the first argument with the second, and remembers the result of the comparison in a special register called the current processor status register. You don't really need to worry about this, suffice to say it remembers, among other things, which of the two numbers was bigger or smaller, or if they were equal.[1]
bne is actually just a branch command in disguise. In the ARM assembly language family, any instruction can be executed conditionally. This means that the instruction is only run if the last comparison had a certain result. We will use this extensively later for interesting tricks, but in this case we use the ne suffix on the b command to mean 'only branch if the last comparison's result was that the values were not equal'. The ne suffix can be used on any command, as can several other (16 in all) conditions such as eq for equal and lt for less than.
### 2 The All Together
I mentioned briefly last time that the status LED can be turned off again by writing to an offset of 28 from the GPIO controller instead of 40 (i.e. str r1,[r0,#28]). Thus, you need to modify the code from OK01 to turn the LED on, run the wait code, turn it off, run the wait code again, and then include a branch back to the beginning. Note, it is not necessary to re-enable the output to GPIO 16, we need only do that once. If you're being efficient, which I strongly encourage, you should be able to reuse the value of r1. As with all lessons, a full solution to this can be found on the [download page][2]. Be careful to make sure all of your labels are unique. When you write wait1$: you cannot label another line wait1$.
On my Raspberry Pi it flashes about twice a second. this could easily be altered by changing the value we set r2 to. However, unfortunately we can't precisely predict the speed this runs at. If you didn't manage to get this working see our trouble shooting page, otherwise, congratulations.
In this lesson we've learnt two more assembly commands, sub and cmp, as well as learning about conditional execution in ARM.
In the next lesson, [Lesson 3: OK03][3] we will evaluate how we're coding, and establish some standards so that we can reuse code, and if necessary, work with C or C++ code.
--------------------------------------------------------------------------------
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html
作者:[Robert Mullins][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://www.cl.cam.ac.uk/~rdm34
[b]: https://github.com/lujun9972
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads.html
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok03.html

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (MjSeven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (qhwdw)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,19 +1,19 @@
The Ruby Story
红宝石Ruby史话
======
尽管我很难说清楚为什么,但 Ruby 一直是我最喜爱的一门编程语言。如果用音乐来类比的话Python 给我的感觉像是<ruby>朋克摇滚<rt>punk rock</rt></ruby>,简单、直接,但略显单调,而 Ruby 则像是爵士乐,赋予了程序员<ruby>灵活的表达<rt>freedom to express</rt></ruby>,虽然这可能会让代码变复杂、程序不直观。
Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视为其核心价值。可我不认同这对于 Ruby 的开发和普及是最重要的。一个人创建一门编程语言也许是为了更高的性能,也许是为了在抽象上节省更多的时间,可 Ruby 就有趣在它并不关心这些,从它诞生之初,它的目标就是让程序员更快乐
尽管我很难说清楚为什么,但 Ruby 一直是我最喜爱的一门编程语言。如果用音乐来类比的话Python 给我的感觉像是<ruby>朋克摇滚<rt>punk rock</rt></ruby>,简单、直接,但略显单调,而 Ruby 则像是爵士乐,从根本上赋予了程序员表达自我的自由,虽然这可能会让代码变复杂,编写出来的程序对其他人来说不直观
### 松本 行弘
Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视为其核心价值。可我不认同这对于 Ruby 的开发和普及是最重要的。创建一门编程语言也许是为了更高的性能,也许是为了在抽象上节省更多的时间,可 Ruby 就有趣在它并不关心这些,从它诞生之初,它的目标就是让程序员更快乐。
<ruby>松本行弘<rt>Yukihiro Matsumoto</rt></ruby>,也叫 “Matz”于 1990 年毕业于筑波大学。筑波是东京东北方向上的一个小城市,是科学研究与技术开发的中心之一。那里的筑波大学以其 STEM 计划广为流传。松本行弘就在筑波大学的信息科学专业学习过,且专攻编程语言。他也在 Ikuo Nakata 的编程语言实验室工作过。
LCTT译注STEM是科学Science技术Technology工程Engineering数学Mathematics四门学科英文首字母的缩写。
### 松本·行弘
<ruby>松本·行弘<rt>Yukihiro Matsumoto</rt></ruby>,亦称为 “Matz”于 1990 年毕业于筑波大学。筑波是东京东北方向上的一个小城市,是科学研究与技术开发的中心之一。筑波大学以其 STEM 计划广为流传。松本·行弘在筑波大学的信息科学专业学习过,且专攻编程语言。他也在 Ikuo Nakata 的编程语言实验室工作过。LCTT 译注STEM 是<ruby>科学<rt>Science</rt></ruby><ruby>技术<rt>Technology</rt></ruby><ruby>工程<rt>Engineering</rt></ruby><ruby>数学<rt>Mathematics</rt></ruby>四门学科英文首字母的缩写。)
松本从 1993 年开始制作 Ruby那时他才刚毕业几年。他制作 Ruby 的起因是觉得那时的脚本语言缺乏一些特性。他在使用 Perl 的时候觉得这门语言过于“玩具”,此外 Python 也有点弱,用他自己的话说:
> 我那时就知道 Python 了,但我不喜欢它,因为我认为不是一门真正的面向对象的语言。面向对象就像是 Python 的一个附件。作为一个编程语言狂热者,我在 15 年里一直是面向对象的忠实粉丝。我真的想要一门生来就面向对象而且易用的脚本语言。我为此特地寻找过,可事实并不如愿。
> 我那时就知道 Python 了,但我不喜欢它,因为我认为不是一门真正的面向对象的语言。面向对象就像是 Python 的一个附件。作为一个编程语言狂热者,我在 15 年里一直是面向对象的忠实粉丝。我真的想要一门生来就面向对象而且易用的脚本语言。我为此特地寻找过,可事实并不如愿。[^1]
所以一种解释松本创造 Ruby 的动机就是他想要创造一门更好且面向对象的 Perl 版本
所以一种解释松本创造 Ruby 的动机就是他想要创造一门更好,且面向对象的 Perl。
但在其他场合,松本说他创造 Ruby 主要是为了让他自己和别人更快乐。2008 年,松本在谷歌技术讲座结束时放映了这张幻灯片:
@ -21,50 +21,53 @@ Ruby 社区一直将<ruby>灵活表达<rt>freedom of expression</rt></ruby>视
他对听众说到,
> 我希望 Ruby 能帮助世界上的每一个程序员更有效率地工作,享受编程并感到快乐。这也是制作 Ruby 语言的主要意图。
> 我希望 Ruby 能帮助世界上的每一个程序员更有效率地工作,享受编程并感到快乐。这也是制作 Ruby 语言的主要意图。[^2]
松本开玩笑的说他制作 Ruby 的原因很自私,因为他觉得其的语言乏味,所以需要创造一点让自己开心的东西。
松本开玩笑的说他制作 Ruby 的原因很自私,因为他觉得其的语言乏味,所以需要创造一点让自己开心的东西。
这张幻灯片展现了松本谦虚的一面。其实,松本是一位摩门教,因此我很好奇他传奇般的友善有多少归功于他的宗教信仰。无论如何,他的友善在 Ruby 社区广为流传,甚至有一条称为 MINASWAN 的原则,即“<ruby>松本人很好,我们也一样<rt>Matz Is Nice And So We Are Nice</rt></ruby>”。我想那张幻灯片一定震惊了来自 Google 的观众。我想谷歌技术讲座上的每张幻灯片都充满着代码和运行效率的指标,来说明一个方案比另一个更快更有效,可仅仅放映崇高的目标的幻灯片却寥寥无几。
这张幻灯片展现了松本谦虚的一面。其实,松本是一位摩门教践行者,因此我很好奇他传奇般的友善有多少归功于他的宗教信仰。无论如何,他的友善在 Ruby 社区广为流传,甚至有一条称为 MINASWAN 的原则,即“<ruby>松本人很好,我们也一样<rt>Matz Is Nice And So We Are Nice</rt></ruby>”。我想那张幻灯片一定震惊了来自 Google 的观众。我想谷歌技术讲座上的每张幻灯片都充满着代码和运行效率的指标,来说明一个方案比另一个更快更有效,可仅仅放映崇高的目标的幻灯片却寥寥无几。
Ruby 主要受到 Perl 的印象。Perl 则是由 Larry Wall 与 20 世纪 80 年代晚期创造的语言主要用于处理和转换基于文本的数据。Perl 因其文本处理和正则表达式而闻名于世。对于 Ruby 程序员Perl 程序中的很多语法元素都不陌生,例如符号`$`、符号`@`、`elsif`等等。虽然我觉得,这些不是 Ruby 应该具有的特征。除了这些符号外Ruby 还借鉴了 Perl 中的正则表达式和标准库。
Ruby 主要受到 Perl 的影响。Perl 则是由 Larry Wall 于 20 世纪 80 年代晚期创造的语言主要用于处理和转换基于文本的数据。Perl 因其文本处理和正则表达式而闻名于世。对于 Ruby 程序员Perl 程序中的很多语法元素都不陌生,例如符号 `$`、符号 `@`、`elsif` 等等。虽然我觉得,这些不是 Ruby 应该具有的特征。除了这些符号外Ruby 还借鉴了 Perl 中的正则表达式的处理和标准库。
但影响了 Ruby 的不仅仅只有 Perl 。在 Ruby 之前松本使用过运行在 Emacs Lisp 上的邮件客户端。这一经历让他对 Emacs 和 Lisp 语言运行的内部原理有了更多的认识。松本说 Ruby 的对象模型也受其启发。在那之上,松本添加了一个 Smalltalk 风格的信息传递系统,这一系统随后成为了 Ruby 中任何依赖 `#method_missing` 的操作的基石。松本 Ada 和 Eiffel 也影响了 Ruby 的设计。
但影响了 Ruby 的不仅仅只有 Perl 。在 Ruby 之前,松本制作过一个仅用 Emacs Lisp 编写的邮件客户端。这一经历让他对 Emacs 和 Lisp 语言运行的内部原理有了更多的认识。松本说 Ruby 底层的对象模型也受其启发。在那之上,松本添加了一个 Smalltalk 风格的信息传递系统,这一系统随后成为了 Ruby 中任何依赖 `#method_missing` 的操作的基石。松本也表示过 Ada 和 Eiffel 也影响了 Ruby 的设计。
当时间来到了给这门新语言命名的时候,松本和它的同事 Keiju Ishitsuka 挑选了很多个名字。他们希望名字能够体现新语言和 Perl、shell 脚本间的联系。在[这一段聊天记录][2]中Ishitsuka 和 松本也许花了太多的时间来思考 <ruby>shell<rt>贝壳</rt></ruby><ruby>clam<rt>蛤蛎</rt></ruby><ruby>oyster<rt>牡蛎</rt></ruby><ruby>pearl<rt>珍珠</rt></ruby>之间的关系了,以至于差点把 Ruby 命名为“<ruby>Coral<rt>珊瑚虫</rt></ruby>”或“<ruby>Bisque<rt>贝类浓汤</rt></ruby>”。幸好,他们决定使用 Ruby ,因为他就像 pearl 一样,是一种珍贵的宝石。此外,<ruby>Ruby<rt>红宝石</rt></ruby> 还是 7 月的诞生石,而 <ruby>Peral<rt>珍珠</rt></ruby> 则是 6 月的诞生石,采用了类似 C++ 和 C# 的隐喻,暗示着她们是改进自前辈的编程语言。
LCTT译注Perl 和 Pearl 发音相同shell 是操作系统提供的用户界面,这里指的是命令行界面;更多有关诞生石的[信息](https://zh.wikipedia.org/zh-hans/%E8%AA%95%E7%94%9F%E7%9F%B3)。)
当时间来到了给这门新语言命名的时候,松本和他的同事 Keiju Ishitsuka 挑选了很多个名字。他们希望名字能够体现新语言和 Perl、shell 脚本间的联系。在[这一段非常值得一读的即时消息记录][2]中Ishitsuka 和 松本也许花了太多的时间来思考 <ruby>shell<rt>贝壳</rt></ruby><ruby>clam<rt>蛤蛎</rt></ruby><ruby>oyster<rt>牡蛎</rt></ruby><ruby>pearl<rt>珍珠</rt></ruby>之间的关系了,以至于差点把 Ruby 命名为“<ruby>Coral<rt>珊瑚虫</rt></ruby>”或“<ruby>Bisque<rt>贝类浓汤</rt></ruby>”。幸好,他们决定使用 Ruby因为它就像 pearl 一样,是一种珍贵的宝石。此外,<ruby>Ruby<rt>红宝石</rt></ruby> 还是 7 月的生辰石,而 <ruby>Pearl<rt>珍珠</rt></ruby> 则是 6 月的生辰石,采用了类似 C++ 和 C# 的隐喻暗示着她们是改进自前辈的编程语言。LCTT 译注Perl 和 Pearl 发音相同,所以也常以“珍珠”来借喻 Perlshell 是操作系统提供的用户界面,这里指的是命令行界面;更多有关生辰石的[信息](https://zh.wikipedia.org/zh-hans/%E8%AA%95%E7%94%9F%E7%9F%B3)。)
### Ruby 走向西方
### Ruby 西渐
Ruby 在日本的普及很快。1995 年 Ruby 刚刚发布后不久后,松本就被一家名为 Netlab 的日本软件咨询团(全名 Network Applied Communication Laboratory雇用并全职为 Ruby 工作。到 2000 年时,仅仅在 Ruby 发布 5 年后Ruby 在日本的流行度就超过了 Python。可这是的 Ruby 从刚刚进入英语国家。虽然从 Ruby 的诞生之初就存在日语邮件的列表,但是英语邮件的列表直到 1998 年才建立起来。而且起初在英语邮件的列表里交流的大多是日本的 Ruby 狂热者,但这一问题随着 Ruby 在西方国家的普及而逐渐得以改善
Ruby 在日本的普及很快。1995 年 Ruby 刚刚发布后不久后,松本就被一家名为 Netlab 的日本软件咨询团(全名 Network Applied Communication Laboratory雇用并全职为 Ruby 工作。到 2000 年时,在 Ruby 发布仅仅 5 年后Ruby 在日本的流行度就超过了 Python。可这时的 Ruby 才刚刚进入英语国家。虽然从 Ruby 的诞生之初就存在讨论它的日语邮件列表,但是英语的邮件列表直到 1998 年才建立起来。起初,在英语的邮件列表中交流的大多是日本的 Ruby 狂热者,可随着 Ruby 在西方的逐渐普及而得以改变
在 2000 年Dave Thomas 出版了第一本涵盖 Ruby 的英文书籍《Programming Ruby》。因为它的封面上画着一把锄头所以这本书也被称为锄头书。是第一次向身处西方的程序员们介绍了 Ruby。就像在日本那样Ruby 的普及很快,到 2002 年时,英语邮件列表的流量超过了日语邮件列表。
在 2000 年Dave Thomas 出版了第一本涵盖 Ruby 的英文书籍《Programming Ruby》。因为它的封面上画着一把锄头所以这本书也被称为锄头书。是第一次向身处西方的程序员们介绍了 Ruby。就像在日本那样Ruby 的普及很快,到 2002 年时,英语的 Ruby 邮件列表的通信量就超过了日语邮件列表。
时间来到了 2005 年Ruby 更流行了,但它然不是主流的编程语言。然而Ruby on Rails 的发布让一切都不一样了。Ruby on Rails 是 Ruby 的“杀手应用”,没有别的什么项目比它更推动 Ruby 的普及了。在 Ruby on Rails 发布后,人们对 Ruby 的兴趣爆发式的增长,看看 TIOBE 监测的语言排行:
时间来到了 2005 年Ruby 更流行了,但它然不是主流的编程语言。然而Ruby on Rails 的发布让一切都不一样了。Ruby on Rails 是 Ruby 的“杀手应用”,没有别的什么项目比它更推动 Ruby 的普及了。在 Ruby on Rails 发布后,人们对 Ruby 的兴趣爆发式的增长,看看 TIOBE 监测的语言排行:
![][3]
有时人们开玩笑的说Ruby 程序全是基于 Ruby-on-Rails 的网站。虽然这听起来就像是 Ruby on Rails 占领了整个 Ruby 社区,但在一定程度上,这是事实。因为 Rails 开发需要 RubyRuby 在西方是随着 Rails 的发布才普及开的。Rails 欠 Ruby 的和 Ruby 欠 Rails 的一样多。
有时人们开玩笑的说Ruby 程序全是基于 Ruby-on-Rails 的网站。虽然这听起来就像是 Ruby on Rails 占领了整个 Ruby 社区,但在一定程度上,这是事实。因为编写 Rails 应用时使用的语言正是 Ruby。Rails 欠 Ruby 的和 Ruby 欠 Rails 的一样多。
Ruby 的设计哲学也深深地影响了 Rails 的设计与开发。Rails 之父 David Heinemeier Hansson 常常提起他第一次与 Ruby 的接触的情形,那简直就是一次传教。他说,那经历简直太有感召力了,让他感到要为松本的杰作(指 Ruby“传教”的使命。对于 Hansson 来说Ruby 的灵活性简直就是对 Python 或 Java 语言中自上而下的设计哲学的反抗。他很欣赏 Ruby 这门能够信任自己的语言Ruby 赋予了他自由选择<ruby>程序表达方式<rt>express his programs</rt></ruby>的权力。
Ruby 的设计哲学也深深地影响了 Rails 的设计与开发。Rails 之父 David Heinemeier Hansson 常常提起他第一次与 Ruby 的接触的情形,那简直就是一次传教。他说,那经历简直太有感召力了,让他感到要为松本的杰作(指 Ruby“传教”的使命。[^3] 对于 Hansson 来说Ruby 的灵活性简直就是对 Python 或 Java 语言中自上而下的设计哲学的反抗。他很欣赏 Ruby 这门能够信任自己的语言Ruby 赋予了他自由选择<ruby>程序表达方式<rt>express his programs</rt></ruby>的权力。
就像松本那样Hansson 声称他创造 Rails 时因为对现状的不满并想让自己能更开心。他也认同让程序员更快乐高于一切的观点,所以检验 Rails 是否需要添加一项新特性的标准是“<ruby>更灿烂的笑容标准<rt>The Principle of The Bigger Smile</rt></ruby>”。什么功能能让 Hansson 更开心就给 Rails 添加什么。因此Rails 中包括了很多非传统的功能例如“Inflector”类和 `Time` 扩展("Inflector"类试图将单个类的名字映射到多个数据库表的名字;`Time` 扩展允许程序员使用 `2.days.ago` 这样的表达式)。可能会有人觉得这些功能太奇怪了,但 Rails 的成功表明它的确能让很多人的生活得更快乐。
就像松本那样Hansson 声称他创造 Rails 时因为对现状的不满并想让自己能更开心。他也认同让程序员更快乐高于一切的观点,所以检验 Rails 是否需要添加一项新特性的标准是“<ruby>更灿烂的笑容标准<rt>The Principle of The Bigger Smile</rt></ruby>”。什么功能能让 Hansson 更开心就给 Rails 添加什么。因此Rails 中包括了很多非正统的功能,例如 “Inflector” 类和 `Time` 扩展“Inflector”类试图将单个类的名字映射到多个数据库表的名字;`Time` 扩展允许程序员使用 `2.days.ago` 这样的表达式)。可能会有人觉得这些功能太奇怪了,但 Rails 的成功表明它的确能让很多人的生活得更快乐。
因此,Rails 不但是 Ruby 的一个普及度很高的应用,而且体现了 Ruby 的很多核心准则。此外,很难看到使用其他语言开发的 Rails 的替代品,因为 Rails 的实现依赖于 Ruby 中<ruby>类似于宏的类方法<rt>macro-like class method</rt></ruby>来实现模型关联的功能这样的功能。一些人认为这么多的 Ruby 开发需要基于 Ruby on Rails 是 Ruby 生态不健康的表现,但 Ruby 和 Ruby on Rails 结合的如此紧密并不是没有道理的。
因此,虽然 Rails 的火热带动了 Ruby 的普及看起来是一个偶然,但事实上 Rails 体现了 Ruby 的很多核心准则。此外,很难看到使用其他语言开发的 Rails正是因为 Rails 的实现依赖于 Ruby 中<ruby>类似于宏的类方法调用<rt>macro-like class method calls</rt></ruby>来实现模型关联这样的功能。一些人认为这么多的 Ruby 开发需要基于 Ruby on Rails 是 Ruby 生态不健康的表现,但 Ruby 和 Ruby on Rails 结合的如此紧密并不是没有道理的。
### Ruby 的未来
### Ruby 之未来
人们似乎对 Ruby 是否正在灭亡有着异常的兴趣。早在 2011 年Stack Overflow 和 Quora 上就有程序员在咨询“如果几年后不在使用 Ruby 那么现在是否有必要学它”。这些担忧对 Ruby 并不合理,虽然在 TIOBE 指数和 Stack Overflow 趋势上Ruby 和 Ruby on Rails 的人气在萎缩,可它也曾是新兴的、热门的技术,但在更新更热的框架面前,排名自然会有所下降
人们似乎对 Ruby(及 Ruby on Rails是否正在消亡有着异常的兴趣。早在 2011 年Stack Overflow 和 Quora 上就充斥着程序员在咨询“如果几年后不再使用 Ruby 那么现在是否有必要学它”的话题。这些担忧对 Ruby 并非没有道理,根据 TIOBE 指数和 Stack Overflow 趋势Ruby 和 Ruby on Rails 的人气一直在萎缩,虽然它也曾是热门新事物,但在更新更热的框架面前它已经黯然失色
一种解释这种趋势的理论是程序员们正在舍弃动态类型的语言转而选择静态类的。TIOBE 指数的趋势中可以看出对软件质量的需求在上升,这使出现在运行时的异常变得难以接受。他们引用 TypeScript 来说明这一趋势TypeScript 是 JavaScript 的全新版本,而创造的目的正是为了保证客户端运行的代码能益于编译所提供的安全保障。
一种解释这种趋势的理论是程序员们正在舍弃动态类型的语言转而选择静态类的。TIOBE 指数的趋势中可以看出对软件质量的需求在上升,这意味着出现在运行时的异常变得难以接受。他们引用 TypeScript 来说明这一趋势TypeScript 是 JavaScript 的全新版本,而创造的目的正是为了保证客户端运行的代码能益于编译所提供的安全保障。
我认为另一个原因可能是比起 Ruby on Rails 推出的时候现在存在着更多有竞争力的框架。2005 年它刚刚发布的时候,还没有那么多用于创建 Web 程序的框架,其主要的替代者还是 Java。可在今天你可以用 Go、Javascript 或者 Python 上的各种优秀的框架,而这还仅仅是主流的选择。 Web 的世界似乎正走向更加分布式的结构,与其使用一个代码仓库来完成从数据库读取到页面渲染所有事务,不如将事务拆分到多个组建其中每个组件专注于一项事务并将其做到最好。在这种趋势下Rails 相较于那些专攻 JavaScript 前端通信的 JSON API 就显得过于宽泛和臃肿。
我认为另一个更可能的原因是比起 Ruby on Rails 推出的时候现在存在着更多有竞争力的框架。2005 年它刚刚发布的时候,还没有那么多用于创建 Web 程序的框架,其主要的替代者还是 Java。可在今天你可以使用为 Go、Javascript 或者 Python 开发的各种优秀的框架而这还仅仅是主流的选择。Web 的世界似乎正走向更加分布式的结构,与其使用一块代码来完成从数据库读取到页面渲染所有事务,不如将事务拆分到多个组件其中每个组件专注于一项事务并将其做到最好。在这种趋势下Rails 相较于那些专攻 JavaScript 前端通信的 JSON API 就显得过于宽泛和臃肿。
总而言之,我们有理由对 Ruby 的未来持乐观态度。因为不管是 Ruby 还是 Rails 的开发都还很活跃。松本和其他的贡献者们都在努力开发 Ruby 的第三个主要版本。新的版本将比现在的版本快上 3 倍,以减轻制约着 Ruby 发展的性能问题。虽然从 2005 年起,越来越多的 Web 框架被开发出来,但这并不意味着 Ruby on Rails 就失去了其生存空间。Rails 是一个富有大量功能的成熟的工具,对于一些特定类型的应用开发一直是非常好的选择。
但就算 Ruby 和 Rails 走上了亡的道路Ruby 让程序员更快乐的信条一定会存活下来。Ruby 已经深远的影响了许多新的编程语言的设计,这些语言的设计中能够看到来自 Ruby 的很多理念。而其他的新生语言则试着变成 Ruby 更现代的实现,例如 Elixir 是一个强调函数式编程的语言,仍在开发中的 Crystal 目标是成为使用静态类型的 Ruby 。世界上许多程序员都喜欢上了 Ruby因此它的影响必将会在未来持续很长一段时间。
但就算 Ruby 和 Rails 走上了亡的道路Ruby 让程序员更快乐的信条一定会存活下来。Ruby 已经深远的影响了许多新的编程语言的设计,这些语言的设计中能够看到来自 Ruby 的很多理念。而其他的新生语言则试着变成 Ruby 更现代的实现,例如 Elixir 是一个强调函数式编程范例的语言,仍在开发中的 Crystal 目标是成为使用静态类型的 Ruby 。世界上许多程序员都喜欢上了 Ruby 及其语法,因此它的影响必将会在未来持续很长一段时间。
喜欢吗?这里每两周都会发表一篇这样的文章。请在推特上关注我们 [@TwoBitHistory][4] 或者订阅我们的 [RSS][5],这样新文章发布的第一时间你就能得到通知。
喜欢这篇文章吗?这里每两周都会发表一篇这样的文章。请在推特上关注我们 [@TwoBitHistory][4] 或者订阅我们的 [RSS][5],这样新文章发布的第一时间你就能得到通知。
[^1]: http://ruby-doc.org/docs/ruby-doc-bundle/FAQ/FAQ.html
[^2]: https://www.youtube.com/watch?v=oEkJvvGEtB4?t=30m55s
[^3]: http://rubyonrails.org/doctrine/
--------------------------------------------------------------------------------
@ -73,7 +76,7 @@ via: https://twobithistory.org/2017/11/19/the-ruby-story.html
作者:[Two-Bit History][a]
选题:[lujun9972][b]
译者:[wwhio](https://github.com/wwhio)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,141 @@
微型计算机的始祖Altair 8800
======
《大众电子》的订阅者是个复杂的群体,杂志编辑 Arthur Salsberg 不得不在 [1974 年 12 月刊][1] 中的前言部分指出这点。此前杂志编辑组曾收到了对《如何搭建家庭媒体中心》文章的抱怨称这篇文章激励了许多业余电视爱好者走出去削弱了专业修理人员存在的必要性这对许多人的电视造成了极大伤害。Salsberg 认为这个担忧的产生可能是因为大家不清楚《大众电子》读者们的真实水平。他解释道杂志内部调查的数据显示52 % 的订阅者都是某方面的电子专家,并且其中的 150,000 人在最近 60 天之内都修过电视。此外,订阅者们平均在电子产品上花费了 470 美金2018 年则是 3578 美金并且他们有对万用表、真空管伏特计、电子管测试仪、晶体管测试仪、射频讯号产生器和示波器的需求。“《大众电子》的读者们并不全都是新手。”Salsberg 总结道。
熟悉《大众电子》的人居然会质疑它的订阅者,这令我十分吃惊。不过最近 60 天我的确没修过电视。我的电脑对我来说就是一块铝我甚至没把它拆开看过。1974 年 12 月的《大众电子》刊登的像《驻波比是什么以及如何处理它》和《对万用表的测试》之类的特色文章,甚至连广告都令人生畏。它们中有个看起来像某种立体声系统的东西大胆地写道“除了‘四通道单元(即内建的 SQ、RM 和 CD-4 解码接收器)’,没有任何音频设备是被期待的”。这也表明了《大众电子》的订阅者一定对电子有很多深入的了解。
不过在 [1975 年 1 月刊][2] 中,杂志为读者们带来了一些他们从没见过的东西。在标题“发现项目”下面,杂志的封面是一个黑灰色的盒子,它的前面板上有一组开关和灯。这便是 Altair 8800“世界上首个有商业竞争力的迷你计算机”它的售价低于 400 美元。尽管 Altair 作为“迷你计算机”被宣传但其实大家都将它称为“微机”和PC它是首个商业上成功的新型电脑。Altair 十分小巧而且很便宜,以至于它成为了当时家家户户都能用起的电脑。正如 Salsberg 所写道,它在《大众电子》上的出现意味着:“家用电脑的时代终于到来了。”
![《大众电子》1975 年 1 月刊的封面][3]
此前,我曾写过 [关于 Altair 的文章][4],但我觉得 Altair 有让我再次介绍的价值。它在当时性能并不强(虽然它便宜很多),也不是首个装载微处理器(由至少三个微处理器组成)的通用计算机。但是 Altair 是一种可供我们所有人使用的计算机。它是历史上包括我们所拥有的设备中首台流行的计算机,早于 Altair 计算机都是完全不同的机器,它们由穿孔卡编程并且很少与用户交互。不过 Altair 也是台极其简单的计算机,它不附带任何操作系统甚至引导加载器。除非你购买其它外设,否则 Altair 就是一台装配 RAM 并且只有一组开关和灯泡的机器。由于 Altair 操作简单,学习计算的基本理论都成了十分简单的事情,就好像他们在数字世界冒险时遇上了旧世界的居民一样。
### Roberts 和他的公司
Altair 被一家名为 MITS 的公司设计和制造这家公司位于美国新墨西哥州的阿尔布开克。MITS 由一个叫 H. Edward Roberts 运营。他们起初借 19 世纪 70 年代的热潮制造模型火箭的遥测系统。集成电路将计算器的成本降低到十分可观的数字,突然之间它就成了美国教授们的必需品。不幸的是,由于计算器市场竞争过于激烈,到了 1974 年MITS 便负债累累。
1974 年在计算机界是<ruby>奇迹迭出的一年<rt>annus mirabilis</rt></ruby>。一月的时候,惠普公司推出了世界首个可编程的手持计算器 HP-65。四月的时候Intel 发布了 Intel 8080他们的第二款 8 位微处理器它也是首款受欢迎的微处理器。接着六月的时候《Radio Electronics》杂志介绍了 Mark-8 这个自制迷你计算机,它使用了 Intel 在 1972 年推出的 Intel 8008 微处理器。Mark-8 是使用微处理器搭建的第三台电脑它的首次登场是在杂志的封面上。Mark-8 在《Radio Electronics》上的出现促使了《大众电子》寻找微机项目的出现。
《大众电子》的订阅者们其实早在 1974 年 12 月就通过电邮获得了 1975 年 1 月刊的副本。他们公布的 Altair 为这个<ruby>奇迹迭出的一年<rt>annus mirabilis</rt></ruby>画上了圆满的句号。Altair 的出现是十分重要的,因为此前从未有过向公众提供的价格公道而又功能齐全的电脑。当时,作为最受欢迎的迷你计算机之一的 PDP-8 要几千美金才能买到。不过 Altair 搭载的 Intel 8080 芯片几乎能与 PDP-8 匹敌8080 支持更广泛的指令集,而且 Altair 可以扩展到 64 kb 内存,显然强于仅有 4 kb 内存的 PDP-8。并且Mark-8 也不是他的对手,因为它搭载的是只能处理 16 kb 内存的 Intel 8008。在 Mark-8 必须由用户按照说明书手动拼装的情况下Altair 在购买时就已经被组装好了(不过由于后来 MITS 被大量订单淹没,最后真正能获得 Altair 的方式也只有买零件拼装了)。
对许多《大众电子》的读者来说Altair 是他们了解数字计算的起点。1975 年 1 月刊上那篇介绍 Altair 的文章由 Roberts 和 Altair 的联合设计师 William Yates 所写。Roberts 和 Yates 煞费苦心地用电工和无线电狂热者们所熟悉的词汇来介绍了数字硬件和计算机编程的基本概念。他们写道“一台计算机其实由一堆可变的硬件构成。仅需修改储存于内存之中的为组合形式便可改变硬件设备的种类。”同时Roberts 和 Yates 认为编程的基本概念是“足够简单并能在较短时间内掌握,但是想要成为一个高效的程序员必须经验丰富且富有创造力。”对此我十分认同。尽管已经组装好了,文章仍包含了用来讲解 Intel 8080 的组成的详细图表。文章解释了 CPU 和计算机内存单元的区别,堆栈指针的概念和汇编语言以及更高级的语言(例如 FORTRAN 和 BASIC比起手动输入机器码所带来的巨大优势。
其实,《大众电子》在 1975 年 1 月刊之前就出版过 Roberts 撰写的系列文章。这一系列作为短期课程被收录在“数字逻辑”专栏中。在 1974 年 12 月刊中Roberts 为读者们带来了关于构建“超低成本计算机终端”的文章,文章中介绍了可以用于 8 位电脑中输入值的八进制键盘。在介绍这个键盘时Roberts 解释了晶体管到晶体管的逻辑工作原理以及关于构建一种可以“记住”数字值的触发器的方法。Roberts 承诺说,这个键盘可以在下个月即将公布的 Altair 电脑中使用。
有多少《大众电子》的读者制作了这个键盘我们无从得知,但是那个键盘的确是个很有用的东西。如果没有键盘和其它输入设备,我们只能通过拨动 Altair 面板上的开关来输入值。Altair 的面板上有 16 行开关被用来设置地址,而下方的 8 个则是用来操作计算机的。16 行中最右边的开关是用来指定要储存在内存中的值的。这么做不无道理,因为 Intel 8080 使用 16 位的值来处理 8 位的信息。而这 16 个开关每一个都代表了一个位,当开关向上时代表 1向下则代表 0。用这样的方式交互是个启示一会儿我们就会讲到因为 Altair 的面板是真正的二进制界面。这使得你可以触摸到裸露的金属。
尽管在当下 Altair 的界面对我们来说完全不像是人用的,不过在那个时候这可是不平凡的。比如 PDP-8 的面板上有个类似的但更漂亮的二进制输入装置,而且它被涂上了吸引人的黄色和橙色,不过讲真,它应该重新来过。然而 PDP-8 经常与纸带阅读器或电传打字机配合使用,这使得程序输入更加容易。这些 I/O 设备价格高昂,这意味着 Altair 的用户们大都会被面板卡住。正如你所想通过这一堆开关进入一个大型程序是个繁重的工作。不过幸运的是Altair 可以与盒式记录器连接这样一来载入程序就不是什么难事了。Bill Gates 和 Paul Allen 进行了微软的首次商业合作,为 Altair 编写了 BASIC 语言,并在 1975 年以 MITS 许可证发行。此后,那些买得起电传打字机的用户就能 [通过纸带来将 BASIC 载入 Altair][5] 了,并能使得用户能够通过字符界面与 Altair 交互。之后BASIC 便成为了学生们最爱的入门编程语言,并成了早期微机时代的标准接口。
### z80pack
多亏了网络上一些人,特别是 Udo Munk 的努力,你可以在你的电脑上运行 Altair 的模拟器。这个模拟器是在 Zilog Z80 CPU 的虚拟套件上构建的,这个 CPU 可以运行 Intel 8080 的软件。Altair 模拟器允许你像 Altair 的用户们一样调整面板上的开关。尽管点击这些开关的感觉不如拨动真实开关,但是使用 Altair 模拟器仍是一个能让你知道二进制人机交互效率有多低的途径,不过我觉得这同时也很简明直观。
z80pack 是 Udo Munk 开发的 Z80 模拟器套件,你可以在 z80pack 的官网上找到它的下载链接。我在 [上一篇介绍 Altair 的文章中][4] 写到过在 macOS 上使用它的详细过程。如果你能编译 FrontPanel 库和 `altairsim` 可执行程序,你应该能直接运行 `altairsim` 并看到这个窗口:
![模拟器中的 Altair 面板][6]
在新版的 z80pack 中(比如我正在使用的 1.36 版本),你可以使用一个叫 Tarbell boot ROM 的功能,我觉得这是用来加载磁盘镜像的。经我测试,它的意思是你不能写入 RAM 中的前几个信息。在编辑 `/altairsim/conf/system.conf` 之后,你可以构建带有一个 16 页 RAM 且没有 ROM 或引导加载器的 Altair。除此之外你还可以用这个配置文件来扩大运行模拟器的窗口不得不说这还是挺方便的。
Altair 的面板看起来就很吓人,不过事实上并没有我们想象中的这么可怕。[Altair 说明书][7] 对解释开关和指示灯起到了很大的作用,这个 [YouTube 视频][8] 也是。若想运行一个简易的程序你只需要了解一点点东西。Altair 右上方标签为 D0 到 D7 的指示灯代表当前处理地址的信息。标签为 A0 到 A15 的指示灯标识当前的地址。地址指示灯下的 16 个开关可以用来设置新地址;当 “EXAMINE” 开关被向上推动时,数据指示灯将会更新,并显示新地址上的内容。用这个功能,你便能观察到内存中所有的信息了。你也可以将 “EXAMINE” 推下来自动检查下一个位置上的信息,这使得检索信息更容易了。
要将模式保存到信息中,请使用最左边的 8 个标签为 0 到 7 的开关。然后,请向上推动 “DEPOSIT” 按钮。
在《大众电子》 的 [1975 年 2 月刊][9] 中Roberts 和 Yates 制作了一小段程序来确保用户们的 Altair 正常工作。这个程序从内存中读取两个整型数据并添加之后将它们存回内存中。这个小程序仅由 6 条指令组成,但是这 6 条指令包含了 14 条在一起的内存信息,所以要正确地输入它们需要一点时间。这个程序也被写入了 Altair 的说明书,原文如下:
| Address | Mnemonic | Bit Pattern | Octal Equivalent |
| :------: | :------: | :------: | :------: |
| 0 | LDA | 00 111 010 | 0 7 2 |
| 1 | (address) | 10 000 000 | 2 0 0 |
| 2 | (address) | 00 000 000 | 0 0 0 |
| 3 | MOV B, A | 01 000 111 | 1 0 7 |
| 4 | LDA | 00 111 010 | 0 7 2 |
| 5 | (address) | 10 000 001 | 2 0 1 |
| 6 | (address) | 00 000 000 | 0 0 0 |
| 7 | ADD B | 10 000 000 | 2 0 0 |
| 8 | STA | 00 110 010 | 0 6 2 |
| 9 | (address) | 10 000 010 | 2 0 2 |
| 10 | (address) | 00 000 000 | 0 0 0 |
| 11 | JMP | 11 000 011 | 3 0 3 |
| 12 | (address) | 00 000 000 | 0 0 0 |
| 13 | (address) | 00 000 000 | 0 0 0 |
如果你通过开关来输入上面这些值,最终会得到一个程序,它会读取内存 128 中的值,并将其添加至 129 中,最终将其保存至 130 中。每条指令都会占用一个地址,它们最开始会被给予最低有效位,这便是第二个字节总会被清零(没有高于 255 的地址)的原因了。在输入这个程序并在 128 和 129 中输入了一些值之后,你可以向下推动 “RUN” ,之后再将它推到 “STOP” 位置。因为程序循环执行,以一秒内执行上千次的速度反复地添加并保存那些值。并且最后得到的值总是相同的,如果你暂停程序并检查 130你应该能找到正确答案。
我不知道普通的 Altair 用户是否使用过,不过 z80pack 包括了一个汇编程序 —— `z80asm`,意思是<ruby>适用于 Z80 的汇编程序<rt>Z80 assembly</rt></ruby>,所以它使用了不同的助记符。不过因为 Z80 是被设计来适配为 Intel 8080 写的软件的,所以即使助记符不一样,它们的操作码也是相同的。你可以直接将 `z80asm` 装载进 Altair
```
ORG 0000H
START: LD A,(80H) ;Load from address 128.
LD B,A ;Move loaded value from accumulator (A) to reg B.
LD A,(81H) ;Load from address 129.
ADD A,B ;Add A and B.
LD (82H),A ;Store A at address 130.
JP START ;Jump to start.
```
编译之后,你可以调用汇编程序来将其转换为 Intel HEX 文件:
```shell
$ ./z80asm -fh -oadd.hex add.asm
```
我们用带有 `h` 参数的 `-f` 标识来定义输出的 HEX 文件。你可以用 `-x` 标识来传递 HEX 文件,从而使得 Altair 能够加载程序:
```shell
$ ./altairsim -x add.hex
```
这会在内存中自动设置前 14 个信息,就和你通过开关手动输入这些值一样。你可以直接使用 “RUN” 按钮来替代以前那些繁琐的步骤,这是如此的简单!
我不觉得有很多 Altair 用户以这种方式来编写软件。Altair BASIC 发布后,使得 BASIC 成为了 Altair 编程最简单的方法。z80pack 同时也包括了一些包含不同版本 Altair BASIC 的 HEX 文件;在模拟器中,你可以用这个方式加载 4.0 版本的 4K BASIC
```shell
$ ./altairsim -x basic4k40.hex
```
当你开启模拟器并按下 “RUN” 按钮之后,你就会看到 BASIC 开始执行了,同时它会在终端中与你交互。它首先会提示你输入你内存的可用量,我们输入 4000 字节。随后,在显示 “OK” 提示符之前它会问你几个问题Gates 和 Allen 用这个来代替标准的 “READY” 并以此节省内存。在这之后,你便可以使用 BASIC 了:
```
OK
PRINT 3 + 4
7
```
尽管只有极小的 4 kb 空间来运行 BASIC不过你仍迈出了使用面板操控电脑的重要一步。
很显然Altair 远不及如今的家用电脑,并且比它晚十多年发布的 Mac 电脑看上去也是对 Altair 电脑的巨大飞跃。但是对亲手组装了 Altair 的《大众电子》的读者们来说,只用了低于 400 美金和一半的书柜空间的 Altair 才是第一个它们真正能拥有的全功能电脑。对那时只能用 [一叠卡片][10] 或一卷磁带来与计算机交互的人们来说Altair 是个令人眼前一亮的玩意。这之后的微机基本都是在对 Altair 改进,使得它更易用。从某种意义上来说,我们甚至可以把它们看成更复杂的 Altair。Altair一个野兽派的极简作品却为之后的许多微机打下了铺垫。
如果你觉得这篇文章写的不错,你可以在推特上关注 [@TwoBitHistory][11] 或订阅 [RSS feed][12] 来获得我们文章的更新提醒。文章每两周就会更新一次!
TwoBitHistory 的上一篇文章是…………
> “跟我一起来进行这振奋人心的冒险吧!只需要十分钟,你就能了解到 10 年都没人用过的软件。” <https://t.co/R9zA5ibFMs>
>
> — TwoBitHistory (@TwoBitHistory) [写于 2018 年 7 月 7 日][13]
--------------------------------------------------------------------------------
via: https://twobithistory.org/2018/07/22/dawn-of-the-microcomputer.html
作者:[Two-Bit History][a]
选题:[lujun9972][b]
译者:[zhs852](https://github.com/zhs852)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://twobithistory.org
[b]: https://github.com/lujun9972
[1]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1974/Poptronics-1974-12.pdf
[2]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-01.pdf
[3]: https://twobithistory.org/images/jan1975-altair.jpg
[4]: https://twobithistory.org/2017/12/02/simulating-the-altair.html
[5]: https://www.youtube.com/watch?v=qv5b1Xowxdk
[6]: https://www.autometer.de/unix4fun/z80pack/altair.png
[7]: http://www.classiccmp.org/dunfield/altair/d/88opman.pdf
[8]: https://www.youtube.com/watch?v=suyiMfzmZKs
[9]: https://www.americanradiohistory.com/Archive-Poptronics/70s/1975/Poptronics-1975-02.pdf
[10]: https://twobithistory.org/2018/06/23/ibm-029-card-punch.html
[11]: https://twitter.com/TwoBitHistory
[12]: https://twobithistory.org/feed.xml
[13]: https://twitter.com/TwoBitHistory/status/1015647820353867776?ref_src=twsrc%5Etfw

View File

@ -0,0 +1,70 @@
[#]: collector: (lujun9972)
[#]: translator: (qhwdw)
[#]: reviewer: ()
[#]: publisher: ()
[#]: url: ()
[#]: subject: (Computer Laboratory Raspberry Pi: Lesson 2 OK02)
[#]: via: (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html)
[#]: author: (Robert Mullins http://www.cl.cam.ac.uk/~rdm34)
计算机实验室 树莓派:课程 2 OK02
======
OK02 课程是在 OK01 课程的基础上构建,通过不停地打开和关闭 `OK``ACT` LED 指示灯来实现闪烁。假设你已经有了 [课程 1OK01][1] 操作系统的代码,它将是这一节课的基础。
### 1、等待
等待是操作系统开发中非常有用的部分。操作系统经常发现自己无事可做,以及必须要延迟。在这个例子中,我们想去做等待,为了能够让这种等待可以看得见,让 LED 灯打开关闭闪烁起来。如果你只是打开和关闭它,你什么都看不到,因为计算机每秒种可以打开和关闭它好几千次。在后面的课程中,我们将看到精确的等待,但是现在,我们只要简单地去消耗时间就足够了。
```
mov r2,#0x3F0000
wait1$:
sub r2,#1
cmp r2,#0
bne wait1$
```
```
sub reg,#val 从寄存器 reg 中的值上减去数字 val
cmp reg,#val 将寄存器中的值与数字 val 进行比较。
如果最后的比较结果是不相等,那么执行后面的 ne 命令。
```
上面是一个很常见的产生延迟的代码片段,由于每个树莓派基本上是相同的,所以产生的延迟大致也是相同的。它的工作原理是,使用一个 `mov` 命令将值 3F0000<sub>16</sub> 推入到寄存器 r2 中,然后将这个值减 1直到这个值减到 0 为止。在这里使用了三个新命令 `sub``cmp``bne`
`sub` 是减法命令,它只是简单地从第一个参数中的值减去第二个参数中的值。
`cmp` 是个很有趣的命令。它将第一个参数与第二个参数进行比较,然后将比较结果记录到一个称为当前处理器状态寄存器的专用寄存器中。你其实不用担心它,它记住的只是两个数谁大或谁小,或是相等而已。[^1]
`bne` 其实是一个伪装的分支命令。在 ARM 汇编语言家族中,任何指令都可以有条件运行。这意味着如果上一个比较结果是某个确定的结果,那个指令才会运行。这是个非常有意思的技巧,我们在后面将大量使用到它,但在本案例中,我们在 `b` 命令后面的 ne 后缀意思是 “只有在上一个比较的结果是值不相等,才去运行分支”。`ne` 后缀可以使用在任何命令上,其它几个(总共 16 个)条件也是如此,比如 `eq` 表示等于,而 `lt` 表示小于。
### 2、组合到一起
上一节讲我提到过,通过将 GPIO 地址偏移量设置为 28str r1,[r0,#28])而不是 40 即可实现 LED 的关闭。因此,你需要去修改课程 OK01 的代码,在打开 LED 后,运行等待代码,然后再关闭 LED再次运行等待代码并包含一个回到开始位置的分支。注意不需要重新启用 GPIO 的 16 号针脚的输出功能,这个操作只需要做一次就可以了。如果你想更高效,我建议你复用 r1 寄存器的值。所有课程都一样,你可以在 [下载页面][2] 找到所有的解决方案。需要注意的是,必须保证你的所有标签都是唯一的。当你写了 wait1\$: 你其它行上的标签就不能再使用 wait1\$ 了。
在我的树莓派上,它大约是每秒闪两次。通过改变我们所设置的 r2 寄存器中的值,可以很轻松地修改它。但是,不幸的是,我不能够精确地预测它的运行速度。如果你的树莓派未按预期正常工作,请查看我们的故障排除页面,如果它正常工作,恭喜你。
在这个课程中,我们学习了另外两个汇编命令:`sub` 和 `cmp`,同时学习了 ARM 中如何实现有条件运行。
在下一个课程,[课程 3OK03][3] 中我们将学习如何编写代码,以及建立一些代码复用的标准,并且如果需要的话,可能会使用 C 或 C++ 来写代码。
[^1]:如果你点了这个链接说明你一定想知道它的具体内容。CPSR 是一个由许多独立的比特位组成的 32 比特寄存器。它有一个位用于表示正数、零和负数。当一个 cmp 指令运行后它从第一个参数上减去第二个参数然后用这个位记下它的结果是正数、零还是负数。如果是零意味着它们相等a-b=0 暗示着 a=b如果为正数意味着 a 大于 ba-b>0 暗示着 a>b如果为负数意味着小于。还有其它比较指令但 cmp 指令最直观。
--------------------------------------------------------------------------------
via: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok02.html
作者:[Robert Mullins][a]
选题:[lujun9972][b]
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: http://www.cl.cam.ac.uk/~rdm34
[b]: https://github.com/lujun9972
[1]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html
[2]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/downloads.html
[3]: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok03.html

View File

@ -7,46 +7,44 @@
[#]: via: (https://kerneltalks.com/linux/understanding-etc-services-file-in-linux/)
[#]: author: (kerneltalks https://kerneltalks.com)
Understanding /etc/services file in Linux
理解 Linux 中的 /etc/services 文件
======
Article which helps you to understand /etc/services file in Linux. Learn about content, format & importance of this file.
这篇文章将帮助你了解 Linux 中 /etc/services 文件,包括它的内容,格式以及重要性。
![/etc/services file in Linux][1]
/etc/services file in Linux
Linux 中的 /etc/services 文件
Internet daemon is important service in Linux world. It takes care of all network services with the help of `/etc/services` file. In this article we will walk you through content, format of this file and what it means to a Linux system.
网络守护程序是 Linux 世界中的重要服务。它借助 `/etc/services` 文件来处理所有网络服务。在本文中,我们将向你介绍这个文件的内容,格式以及它对于 Linux 系统的意义。
`/etc/services` file contains list of network services and ports mapped to them. `inetd` or `xinetd` looks at these details so that it can call particular program when packet hits respective port and demand for service.
`/etc/services` 文件包含网络服务和它们映射端口的列表。`inetd` 或 `xinetd` 会查看这些细节,以便在数据包到达各自的端口或服务有需求时,它会调用特定的程序。
As a normal user you can view this file since file is world readable. To edit this file you need to have root privileges.
作为普通用户,你可以查看此文件,因为文件一般都是可读的。要编辑此文件,你需要有 root 权限。
```
$ ll /etc/services
-rw-r--r--. 1 root root 670293 Jun 7 2013 /etc/services
```
### `/etc/services` file format
### `/etc/services` 文件格式
```
service-name port/protocol [aliases..] [#comment]
```
Last two fields are optional hence denoted in `[` `]`
最后两个字段是可选的,因此用 `[` `]` 表示。
where
其中:
* service-name is name of the network service. e.g. [telnet][2], [ftp][3] etc.
* port/protocol is port being used by that network service (numerical value) and protocol (TCP/UDP) used for communication by service.
* alias is alternate name for service.
* comment is note or description you can add to service. Starts with `#` mark
* service-name 是网络服务的名称。例如 [telnet][2], [ftp][3] 等。
* port/protocol 是网络服务使用的端口一个数值和服务通信使用的协议TCP/UDP
* alias 是服务的别名。
* comment 是你可以添加到服务的注释或说明。以 `#` 标记开头。
### Sample` /etc/services` file
### `/etc/services` 文件示例
```
# Each line describes one service, and is of the form:
# 每行描述一个服务,形式如下:
#
# service-name port/protocol [aliases ...] [# comment]
@ -56,7 +54,7 @@ echo 7/udp
discard 9/udp sink null
```
Here, you can see use of optional last two fields as well. `discard` service has alternate name as `sink` or `null`.
在这里,你可以看到可选的最后两个字段的用处。`discard` 服务的别名为 `sink``null`
--------------------------------------------------------------------------------
@ -64,7 +62,7 @@ via: https://kerneltalks.com/linux/understanding-etc-services-file-in-linux/
作者:[kerneltalks][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出