C 語言入門 | 01 - 02 | 程式語言簡介

Feis Studio
8 Apr 201806:25

Summary

TLDRThis script introduces the concept of programming languages, emphasizing their necessity for communication with computers. It explains that while natural languages are complex for computers, programming languages provide a structured way to command computers to perform tasks. The script outlines the evolution from machine language, which computers directly understand, to assembly and high-level languages, which are more human-readable and writable. It highlights the importance of components like CPU and RAM in a computer's ability to execute programs, and mentions common high-level languages like C, C++, and Java.

Takeaways

  • 💬 Learning a programming language allows us to communicate with computers, similar to how we communicate with other people using human languages.
  • 🤔 The necessity of learning programming languages arises from the inability of computers to understand natural human languages without specific instructions.
  • 🧠 Computers primarily understand binary signals, composed of 0s and 1s, which are the building blocks of machine language.
  • 🔧 Assembler languages assign mnemonic names to binary instructions, making it easier for humans to write and understand code before it's translated back into machine language.
  • 📚 High-level languages like C, C++, and Java are designed to be more intuitive and closer to human language, simplifying the programming process.
  • 💻 The evolution of programming languages, from machine language to high-level languages, has been driven by the need to make communication with computers more accessible.
  • 🧩 The core components of a computer, such as the CPU and RAM, are essential for executing programs and are the focus of many programming tasks.
  • 🛠️ Compilers play a crucial role in converting high-level language code into machine language that the computer's hardware can execute.
  • 📱 The definition of a computer has evolved; it's not just traditional PCs but also includes smartphones and other devices with computational capabilities.
  • 🔑 Understanding the basics of programming languages and how they interface with computer hardware is fundamental to controlling and utilizing modern technology effectively.

Q & A

  • What is the primary purpose of learning a programming language?

    -The primary purpose of learning a programming language is to communicate with computers, allowing us to instruct them to perform tasks we desire.

  • Why do we need to learn a programming language if we already know human languages?

    -Human languages are too complex for computers to understand accurately. Programming languages provide a structured and precise way to communicate with computers.

  • What is the fundamental function of language, according to the script?

    -The fundamental function of language is communication, which in the context of programming languages, means communicating with computers.

  • Why is it difficult for computers to understand human languages like Chinese or English?

    -Human languages are complex and can have multiple meanings. Computers require precise and unambiguous instructions, which is why we use programming languages.

  • What is the role of a CPU in a computer?

    -The CPU, or Central Processing Unit, is the control and computation unit of a computer responsible for executing instructions and processing data.

  • What is the function of RAM in a computer system?

    -RAM, or Random Access Memory, serves as the memory unit in a computer, where data is temporarily stored for quick access and manipulation by the CPU.

  • What is the significance of the terms '0' and '1' in computer hardware?

    -The terms '0' and '1' represent binary digits that are the basic units of data in computer hardware, used to represent instructions and data.

  • What is an instruction set in the context of computer architecture?

    -An instruction set is a collection of instructions that a computer's hardware can understand and execute, often associated with a specific architecture like x86 or ARM.

  • What is machine language and why is it important?

    -Machine language is a low-level programming language consisting of binary code that computers can directly execute. It's important because it's the direct language of computer hardware.

  • How does an assembler help in the process of programming?

    -An assembler translates assembly language, which is a human-readable representation of machine code, into machine language that the computer can execute.

  • What is a high-level programming language and why is it easier to use than machine language?

    -A high-level programming language is a language that is closer to human language and intuition, making it easier to read and write. It abstracts away the complexity of machine language, allowing programmers to write more intuitive code.

  • What is the role of a compiler in the execution of high-level programming languages?

    -A compiler translates high-level programming language code into machine language or an intermediate form that can be executed by the computer.

Outlines

00:00

💻 Introduction to Programming Languages

The paragraph introduces the concept of programming languages by drawing an analogy with natural languages. It explains that just as we learn human languages to communicate with other people, we learn programming languages to communicate with computers. The speaker points out that while we might already know multiple human languages, programming languages are necessary because computers do not understand natural language as well as humans do. The main purpose of learning a programming language is to control computers and make them perform tasks. The paragraph also touches on the evolution of computers from traditional PCs to smartphones and other devices, emphasizing that programming allows us to interact with a wide range of computer-based systems. Additionally, it introduces the hardware components essential for programming, such as the CPU and RAM, which are responsible for computation and memory, respectively.

05:01

🔧 Understanding Machine Language and Assembly Language

This paragraph delves into the lower levels of programming, starting with machine language, which is a series of 0s and 1s that computers directly understand. It explains that while machine language is the most basic form of communication with computers, it is not human-friendly. To bridge this gap, assembly language was developed, which assigns mnemonic names to machine instructions, making them more comprehensible to humans. The paragraph describes the process of writing programs in assembly language and then using an assembler to translate these programs into machine code that computers can execute. This section also introduces the concept of high-level languages, which are closer to human language and intuition, making them easier to read and write. High-level languages like C, C++, and Java are mentioned as examples, and the paragraph concludes by explaining that these languages are eventually compiled into machine language for execution by the computer.

Mindmap

Keywords

💡Programming Language

A programming language is a formal language comprised of instructions that a computer can understand and execute. In the video, it is emphasized that learning a programming language allows us to communicate with computers, similar to how natural languages allow us to communicate with other humans. The video contrasts this with human languages, highlighting that programming languages are simpler because computers require precise and unambiguous instructions.

💡Communication

Communication is the process of conveying information between entities. The video highlights that while natural languages allow humans to communicate with each other, programming languages enable communication with computers. The essence of learning a programming language is to give computers instructions in a way they can comprehend and act upon.

💡Computer

A computer is an electronic device that processes data and performs tasks according to instructions. In the video, the term 'computer' is discussed in various forms, such as personal computers, smartphones, and other digital devices. The video emphasizes that regardless of form, computers are fundamentally about processing and executing instructions given via programming languages.

💡CPU (Central Processing Unit)

The CPU is the part of a computer that performs most of the processing inside a computer. The video identifies the CPU as a crucial component responsible for executing instructions from a program, making it central to the function of a computer. It is described as one of the primary units that programming languages interact with.

💡Memory

Memory refers to the component of a computer where data is stored temporarily or permanently. In the video, memory, such as RAM, is highlighted as essential for storing data that a program uses while running. Memory is one of the core components that programming languages manage, particularly when dealing with data storage and retrieval.

💡Machine Language

Machine language is a low-level programming language consisting of binary code that a computer's CPU can directly execute. The video explains that it consists of a series of 0s and 1s and is the most basic level of programming that directly communicates with the computer hardware. It is highlighted as a primitive but crucial form of communication between humans and machines.

💡Assembly Language

Assembly language is a low-level programming language that uses symbolic names instead of binary code, making it easier for humans to understand. The video mentions assembly language as an intermediary between machine language and high-level languages, simplifying programming by allowing the use of recognizable instructions instead of raw binary.

💡High-level Language

A high-level language is a programming language that is closer to human language, making it easier to write, read, and maintain code. The video mentions languages like C, C++, and Java as examples. High-level languages abstract the complexities of machine code, allowing programmers to focus on solving problems rather than managing hardware intricacies.

💡Compiler

A compiler is a tool that translates code written in a high-level programming language into machine language so that it can be executed by a computer's CPU. The video describes the compiler's role in converting human-readable code into a format that the machine can understand and execute, bridging the gap between human and computer communication.

💡Instruction Set Architecture (ISA)

ISA refers to the set of instructions that a specific computer architecture can execute. In the video, it is mentioned in the context of how hardware manufacturers define which instructions their processors can handle, such as x86 or ARM architectures. Understanding the ISA is essential for writing programs that interact directly with computer hardware.

Highlights

Introduction to the concept of programming languages and their necessity.

The analogy of language learning to explain the importance of programming languages.

The primary function of language: communication, and its application to programming languages for communicating with computers.

Why learning programming languages is essential despite knowing human languages.

The practical applications of programming languages in enabling us to command computers.

The limitations of natural human languages in controlling computers due to their complexity.

The simplicity of programming languages compared to human languages.

The evolution of devices that contain computers in everyday life beyond traditional PCs.

The core components of a computer: CPU and memory, and their roles in executing programs.

The process of how programs work with data: input, storage, computation, and output.

The importance of CPU speed and memory size in determining computer performance.

The digital signals (0s and 1s) that computers understand and the role of hardware in interpreting these signals.

Instruction sets and their role in defining how instructions correspond to binary code.

The concept of machine language: the most basic form of communication with computers using binary code.

The invention of assembly language as a step up from machine language, making it easier for humans to write programs.

The role of compilers in translating high-level languages into machine language for execution.

The introduction and benefits of high-level programming languages like C, C++, and Java.

How high-level languages allow for more intuitive and efficient programming compared to lower-level languages.

Transcripts

play00:00

大家好 在開始學程式語言之前

play00:02

我們先稍微介紹一下甚麼是程式語言

play00:04

首先我們要問一下

play00:05

你以前是否有學過任何一種語言

play00:07

當然這有個小小的陷阱

play00:09

如果你沒有學過任何一種語言

play00:11

那你就不應該聽懂我現在在說甚麼

play00:13

反過來說

play00:13

如果你已經聽懂我現在在說甚麼

play00:15

至少代表說你已經學過了中文這樣的一個語言

play00:18

當然你還有很可能是學了

play00:20

像是英文或是日文或西班牙文

play00:23

但是問題又回來了

play00:24

既然我們已經會了這麼多種語言

play00:26

那為什麼還要學程式語言呢

play00:27

更務實地來說

play00:28

到底學會程式語言

play00:29

可以做到甚麼以前我們做不到的事情

play00:32

所以我們必須要回到語言最原始而最重要的功能

play00:35

也就是溝通

play00:36

例如我們今天如果學會中文

play00:37

我們當然就可以跟會中文的人溝通

play00:39

我們學會英文就可以跟會英文的人溝通

play00:42

那如果我們今天學會了程式語言可以跟誰溝通呢

play00:45

沒錯 我們就是可以跟電腦溝通

play00:47

當然說溝通好像很了不起

play00:49

有一種互相交流的概念

play00:51

但實際上大部分的情形

play00:52

都是我們單方面的要求電腦

play00:54

去做一些我們想要他做的事情

play00:57

所以更準確地說呢

play00:58

使用程式語言其實是要讓電腦可以了解我們的想法

play01:01

進而做我們想要他做的事情

play01:03

當然你可能會想

play01:05

為什麼不使用我們已經會的中文去控制電腦呢

play01:08

為什麼非要另外去花時間去學另外一種程式語言

play01:11

實際上當然不是不行

play01:12

現在確實有很多方法

play01:13

例如說聲控之類的來控制電腦

play01:16

但是 一般我們生活中所使用的這種語言

play01:18

對於現在電腦來講而是太過複雜

play01:20

甚至很多時候我們同一句話還有可能有不同的涵義

play01:24

那電腦可能沒辦法確定你到底想要幹嘛

play01:26

因此對我們來說這些都是不夠好的

play01:28

所以呢我們需要特地去學習一種程式語言

play01:30

最大的原因其實就在於電腦實在太笨了

play01:33

他無法準確地理解我們平常所說的話

play01:36

當然也許再過幾個世紀

play01:38

以後的小朋友可能不需要另外學就可以讓電腦做事情

play01:41

只可惜我們可能太早生了

play01:42

從另外一個角度來看

play01:44

程式語言其實比我們學過的中文或英文

play01:46

都應該要簡單很多

play01:48

畢竟連這麼笨的電腦都懂了 對不對

play01:50

總而言之

play01:51

我們學會程式語言其實最重要的功用

play01:53

就是為了可以控制電腦

play01:54

但是問題來了

play01:55

甚麼是電腦呢

play01:56

其實在現代我們越來越難界定

play01:58

電腦他應該要長甚麼樣子

play02:00

例如我們現在平常在家裡或是我們工作

play02:02

用的可能像是 PC 我們叫個人電腦

play02:04

他就是一個方方的螢幕還有一個方方的盒子

play02:07

裡面裝著電腦主機

play02:09

同時又可以發現你現在手上

play02:10

可能拿著是所謂的智慧型手機

play02:12

其實他也是某一種電腦

play02:13

所以我們生活中常見的各種 3C 產品

play02:16

都可能含有某種類型的電腦

play02:18

只是我們可能不知道

play02:19

或者說我們可能不在意

play02:20

那換句話說

play02:21

學會程式設計

play02:23

他不僅僅是能夠控制傳統我們認知的所謂 PC 個人電腦

play02:26

在現代他已經慢慢深入生活或工作中

play02:29

但是不管是哪一種類型或是長得怎麼樣

play02:31

基本上還是由一些主要的單元所構成

play02:34

其中最主要的當然是控制跟運算單元

play02:36

例如說我們常講的 CPU 中央處理器

play02:38

就是屬於這樣的一個單元

play02:39

那還有所謂的記憶單元

play02:41

例如說我們常講的 RAM 記憶體

play02:43

那這兩個單元其實也是我們程式設計時

play02:46

用到最重要的兩個核心

play02:48

他們分別負責計算跟記憶

play02:49

因為在大部分的時間裡面呢

play02:51

程式做的事情就是把輸入的資料存起來

play02:53

存起來的資料拿起來 算一算

play02:55

再把算出來的結果存起來

play02:56

再把這個結果拿起來算一算

play02:58

不停地重複這樣的過程

play02:59

所以我們程式執行的效率

play03:01

他很多時候也就會跟這兩個單元有關

play03:03

這也是為什麼我們買電腦的時候

play03:05

都很在意 CPU 有多快或是記憶體有多大

play03:08

總而言之

play03:08

當你聽說某個物體他含有中央處理器

play03:11

或者他裡面含有所謂的記憶體的時候

play03:13

很有可 能他裡面就是有一台電腦

play03:15

那很有可能你就可以寫程式去控制他

play03:17

聽起來是不是有點酷

play03:18

對甚麼是電腦有點概念之後

play03:20

電腦他能夠看得懂甚麼

play03:21

絕大部分的電腦硬體只 能儲存所謂的數位訊號

play03:24

一串由 0 跟 1 構成的數字

play03:27

換句話說

play03:27

如果你想要讓電腦硬體去執行某個指令

play03:30

要 先將那個指令變成一串 0 跟 1 的數字

play03:32

電腦硬體才看得到

play03:33

電腦硬體看到之後

play03:34

他才可以依照那串數字去決定說你下的是甚麼指令

play03:38

問題是那段 0 跟 1 到底要對應到哪個指令是誰決定的

play03:41

事實上就是由硬體廠商所決定

play03:43

硬體廠商在設計硬體的時候

play03:45

依照某種所謂的指令集

play03:47

約定好說他們到底支援那些指令

play03:49

還有每個指令要怎麼樣對應到一串 0 跟 1

play03:51

例如說你有聽過甚麼 x86 或是 ARM 這些名詞

play03:55

他們都是某一種指令集的架構

play03:57

硬體廠商他們會依照架構去實作

play03:59

所以到底甚麼指令對應到甚麼樣的 0 跟 1

play04:02

然後怎麼對應

play04:03

都會由這個指令集所包含

play04:05

也就是說我們事先透過跟電腦硬體廠商他約好的暗號

play04:09

就是說每個指令對應到哪串 0 跟 1

play04:11

我們就可以去跟電腦溝通

play04:13

因為我們只要輸入約好的 0 跟 1

play04:15

就會對應到某一個電腦知道的指令

play04:17

這個就是最傳統最原始的方式

play04:20

我們寫了一串 0 跟 1

play04:21

電腦硬體依照事先約好的暗號

play04:23

將這串 0 跟 1 對應到某個指令去執行

play04:26

這樣所使用的語言呢

play04:27

就這串 0 跟 1 呢

play04:28

就是所謂的機器語言

play04:29

就是連機器都可以懂的語言

play04:31

但是對一般人來講呢

play04:32

每次我要控制電腦去執行指令的時候

play04:34

就要去背說

play04:35

那這件事情對應到哪串 0 跟 1

play04:36

你才可以去控制電腦

play04:38

這樣是不是太痛苦太不人道了

play04:39

所幸人們很聰明

play04:40

既然每個指令他會對應到一串我們事先已經訂好的 0 跟 1

play04:44

那我們只要把每個指令取一個好聽的名字

play04:47

以後寫程式的時候我們只要寫名字就好

play04:49

當有一天我們真的要去執行他的時候

play04:51

我們就把這個名字變成機器碼

play04:54

因為每個名字就會對應到一串 0 跟 1

play04:56

例如說我們這邊的 LOAD A 代表載入 A

play04:59

ADD B 代表加上 B

play05:01

STORE SUM 代表把結果存在 SUM

play05:03

這些看起 來比我們寫 0 跟 1 容易理解嘛

play05:06

當我們寫好之後

play05:06

再透過一個軟體

play05:08

這個軟體通常我們稱為組譯器

play05:10

他會將我們這邊的每個指令

play05:12

都對應到一串事先約定好的 0 跟 1

play05:15

之後電腦的硬體就可以執行他了

play05:17

是不是就簡單很多

play05:18

這個我們叫組合語言

play05:19

我們把每一個電腦能夠執行的指令取個名字

play05:22

每個名字會對應到一串 0 跟 1

play05:24

我們寫的時候就用這個名字去寫

play05:26

但是我們要執行的時候

play05:28

會先把用名字寫的程式碼

play05:29

組譯成機器語言

play05:30

再用機器語言的方式去執行

play05:33

電腦就看得懂了

play05:34

那我們人真的很聰明

play05:35

既然我們可以這麼做

play05:36

就是把一個人比較不容易看懂的表示方法

play05:39

變成一個人比較容易看懂的表示方法

play05:41

那我們是不是可以把他變成更容易看懂

play05:43

怎麼說呢

play05:44

我們就發明了所謂的高階語言

play05:46

例如說我們就寫一個 SUM = A + B

play05:48

看起來是不是更直觀

play05:49

A + B 結果存在SUM 裡面

play05:51

那東西就稱為高階語言是因為他更接近我們人類的直覺

play05:55

更容易閱讀也更容易寫

play05:58

因為他更短嘛

play05:58

我們就寫這樣的程式碼

play06:00

然後我們透過一個編譯器

play06:02

這個編譯器呢

play06:02

他再把我們這高階語言的程式碼

play06:04

變成組語或是機器語言

play06:06

電腦就可以去執行

play06:07

那常見的高階語言就包含了 C、C++、Java

play06:10

這些我們常聽到的語言的名稱都是高階語言

play06:13

其實我們大部分的情況下

play06:14

我們學的都是所謂的高階語言

play06:16

我們使用一個比較接近人類直覺的方式來寫程式碼

play06:20

透過編譯器變成電腦也看得懂的機器語言

play06:23

用這樣的方式來跟電腦溝通

Rate This

5.0 / 5 (0 votes)

Related Tags
ProgrammingComputer CommunicationLanguage BasicsTech EducationSoftware ControlHardware InteractionCoding EssentialsComputer ScienceInstruction SetHigh-Level Languages