Why This Course?
Download
Report
Transcript Why This Course?
CS2422
Assembly Language and
System Programming
Department of Computer Science
National Tsing Hua University
Announcement
Two sessions for this course:
CS2422-01 (潘雙洪教授)
CS2422-02 (金仲達教授)
1
Course Administration:
CS2422-02
授課老師: 金仲達
助教: 張建偉、劉力瑋
辦公室: 資電館734
電話: 53553
上課時間:
辦公室: 資電館443
電話: 42804
email: [email protected]
星期二15:20-17:10
星期四15:20-16:10
上課地點: 資電館236
課程網頁:
http://www.cs.nthu.edu.tw/~king/courses/cs2422.html
2
Textbooks
Kip Irvine, “Assembly Language for Intel-Based
Computers”, 5th ed.
Leland Beck, “System Software”
Using the first 4 chapters
Other good books:
Patterson and Hennesey, “Computer Organization
and Design” (not Intel-based, textbook of CS4100)
The Art of Assembly (freely available online)
3
Honor Code
University code will be followed strictly to handle
the cheating in assignments and exams.
You are allowed (and in fact encouraged) to
discuss the assignments, but the work must be
your own.
4
Grading (Subject to Change)
1. Program assignments: 60%
2. Mid-term exam.: 20%
3. Final exam: 20%
Early bonus: +2% each day early, up to two days
Late penalty: -20% each day (or partial day) late
The instructor reserves the right to normalize
(including shift and scale) the scores for the
purpose of achieving fair grade distribution within
the class or across classes
5
What’s Next?
Basic concepts
What is “assembly language”, “assembly program”,
and “assembler”?
How are they related to computers?
Why this course?
6
稻田是怎麼灌溉的?
灌溉渠道
水庫
7
灌溉渠道
8
如何實施分區輪流灌溉?
閘門
5
1
6
4
2
3
7
8
水利會
控制中心
9
水利會控制中心的「閘門排程表」
閘門
1
9/17
9/18
9/19, 9/21, 9/23
9/20, 9/22, 9/24
9/25
2
3
4
6
7
5
8
…
10
水利會總幹事的「灌溉區排程表」
灌溉區
北埔
9/17
9/18
9/19, 9/21, 9/23
新埔
大埔
南埔
9/20, 9/22, 9/24
9/25
…
11
水利會理事長的灌溉指示
今年三期稻作由9/17開始灌溉
9/17灌溉新埔、大埔
9/18灌溉北埔、新埔、南埔
9/19至9/24輪流,一天灌溉北埔、大埔,另一天灌
溉新埔、南埔
9/25灌溉新埔
(以上故事純屬虛構)
灌溉和電腦有什麼對應的關係?
12
Computer Analogy
Datapath
Machine
code
Register
10110110
11101010
01010111
11011011
Memory
00100111
…
Control
Controller
5
clock
ALU
N
Z
IR
PC
1
6
2
3
multiplexer
4
7
8
水利會
控制中心
閘門排程表
13
Computer Analogy
灌溉區排程表
Assembly program
閘門排程表
灌溉區排程表
?
14
Computer Analogy
理事長的指示
High-level
Language
Program
灌溉區排程表
理事長的指示
?
15
Assembly Language
Machine language:
Machine instructions: direct instructions to the
processor, e.g. to be encoded to control the
datapath
A numeric language understood by the processor
Assembly language:
Statements (instructions) in short mnemonics and
symbolic reference, e.g. ADD, MOV, CALL, var1, i,
j, that have a 1-to-1 relationship with machine
instructions
Understood by human
16
From C to Assembly
C
x = (a+b) * b
Assembly
C compiler
MOV AX, a
ADD AX, b
MUL c
MOV x, AX
17
From Assembly to Binary
Assembly
Assembler
MOV AX, a
ADD AX, b
MUL c
MOV x, AX
00000000101000010000000000011000
00000000100011100001100000100001
10001100011000100000000000000000
10001100111100100000000000000100
10101100111100100000000000000000
10101100011000100000000000000100
00000011111000000000000000001000
Machine code
18
Different Levels of Abstractions
High Level Language
Program
Compiler
Assembly Language
Program
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
MOV
ADD
MOV
AX,
AX,
x,
a
b
AX
Assembler
Machine Language
Program
Machine
Interpretation
Control Signal
°
°
more elaborated later
0000 1001
11001-2:
0110Virtual
1010 1111
in Sec.
1010 1111 0101 1000 0000 1001
Machine Concept
1100 0110 1010 1111 0101 1000
0101
1100
0000
0101 1000 0000 1001 1100 0110 1010
1000
0110
1001
1111
ALUOP[0:3] <= InstReg[9:11] & MASK
19
Comparing Assembly
to High-Level Languages
20
System Programming
Programming of system software:
Programs that support operation of a computer
itself, rather than any particular application
Examples: text editor, compiler, loader or linker,
debugger, macro processor, operating system,
database management systems, ….
21
System Programming
Assembler:
Linker:
A computer program to translate an assembly
program into the processor’s object code
Translates assembly instruction mnemonics into
opcodes, and resolves symbolic names for
memory locations and other entities
A program that takes one or more objects
generated by compilers/assemblers and
assembles them into a single executable file
Loader:
A program to load executables into memory,
preparing them for execution and executing them
Usually a part of operating system
22
What’s Next?
Basic concepts
What is “assembly language”, “assembly program”,
and “assembler”?
How are they related to computers?
Why this course?
23
Why This Course?
A great way to learn how a computer works:
To talk in the languages of the processors
To see how a computer talks to other devices
To write very efficient code (size & speed)
To build solid background for other courses:
Computer Architecture, Compilers, Operating
Systems…etc.
24
Even More Important Now
A few examples:
The SOC (System-On-Chip) and embedded
system trend
The era of ubiquitous computing
For graphics folks: the DirectX and OpenGL
shading languages
The hardware/software boundary is blurring
25