Can someone tell me the very basics of how compute

2019-01-31 01:55发布

What makes all the words of a programming language actually do anything? I mean, what's actually happening to make the computer know what all of those words mean? If I verbally tell my my computer to do something, it doesn't do it, because it doesn't understand. So how exactly can these human words written into a language actually cause the computer to do some desirable activity?

13条回答
Rolldiameter
2楼-- · 2019-01-31 02:19

Several people have already provided summaries of the translation process from a typical programming language down to actual machine code that a processor can execute.

To understand this process, it's helpful to have a concrete feel for what it's actually like to program at the level of machine code. Once you have an understanding of what the processor itself can do, it's easier to understand higher-level programming constructs as the abbreviations they are.

But unfortunately, writing machine code for a desktop computer is not much fun.

As an alternative, there is a great old game called Corewar in which you write little programs using a simplified machine language. These programs then battle each other for survival. You can write basic programs in the raw machine language, and then there's a system of macros so you don't have to repeat yourself so much, and that's the first step towards a full-featured language.

Another easy, rewarding, but low-level thing to do is to program a simple embedded controller like an Arduino. There are lots of easy introductions like this one available. You'll still be using a compiler, but the resulting machine code is easier to understand (if you want to) because the capabilities of the processor are so much simpler.

Both of these are great ways to get a feel for how digital computers actually work.

查看更多
ら.Afraid
3楼-- · 2019-01-31 02:19

The CPU has a register (a thingy that can store a number) called an instruction pointer. The instruction pointer says what address in memory to pull an instruction from. The CPU pulls an instruction, executes it, and goes on to the next instruction, unless the instruction that it executed said to go somewhere else. These instructions are fairly weak. Add this number to that number. Store this number over there. Take the next instruction from over there. A program called a compiler analyzes your program and turns it into machine code (I'm skipping a few steps here).

Two books that will give you a decent overview of this process are SICP and TECS.

查看更多
\"骚年 ilove
4楼-- · 2019-01-31 02:22

A good book that talks about computers for non-engineers is 'Code' by Charles Petzold. I don't recall exactly if it covers exactly your question, but I think so. If you are interested enough to go farther it's a good choice.

Code http://ecx.images-amazon.com/images/I/11MYtZPhJEL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA198_SH20_OU01_.jpg

查看更多
一纸荒年 Trace。
5楼-- · 2019-01-31 02:24

You could compare how programming works to translating between languages. Say you were on a desert island with 2 other people. You only speak French. Person number 1 (we'll call him Fred) only speaks French and Japanese. Person 2 (Bob) only speaks Japanese. Say you need to ask Bob to go help you gather some firewood. Imagine in this case you are the program and Bob is the computer. You say to Fred in French "Can you tell Bob to come help me." Fred translates into Japanese and asks Bob to help you. In this case Fred would be the compiler. He translates the request into something Bob can understand. That is sort of how a computer program works.

There is a good How Stuff Works article that explains things.

I personally didn't really understand how computers could work the way they do until I took a digital electronics class. Prior to that the whole idea of how computers could work at all for me. After I built a binary counter it all made sense.

查看更多
一夜七次
6楼-- · 2019-01-31 02:24

Very simply, computer programming is the act of giving the computer a set of instructions in a language that it can understand. Programmers normally write instructions in a high-level programming language, and those instruction then get translated into the binary language that the computer understands. Programs that do this translation are called compilers.

查看更多
走好不送
7楼-- · 2019-01-31 02:25

In the simplest case, a program called a compiler takes the programming language words you write and converts them to machine language which the computer can understand. Compilers understand a specific programming language (C#, Java, etc) which has very specific rules about how you explain to the compiler what you want it to do.

Interpretation and understanding of those rules is most of what Stack Overflow is about. :)

查看更多
登录 后发表回答