260 likes | 275 Vues
CS2422 Assembly Language and System Programming. Department of Computer Science National Tsing Hua University. Announcement. Two sessions for this course: CS2422-01 ( 潘雙洪教授) CS2422-02 ( 金仲達教授). Course Administration: CS2422-02. 授課老師: 金仲達
E N D
CS2422 Assembly Language andSystem Programming Department of Computer Science National Tsing Hua University
Announcement • Two sessions for this course: • CS2422-01 (潘雙洪教授) • CS2422-02 (金仲達教授)
Course Administration: CS2422-02 • 授課老師: 金仲達 • 辦公室: 資電館443 電話: 42804email: king@cs.nthu.edu.tw • 助教: 張建偉、劉力瑋 • 辦公室: 資電館734 電話: 53553 • 上課時間: • 星期二15:20-17:10 星期四15:20-16:10 • 上課地點: 資電館236 • 課程網頁: http://www.cs.nthu.edu.tw/~king/courses/cs2422.html
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)
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.
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
What’s Next? • Basic concepts • What is “assembly language”, “assembly program”, and “assembler”? • How are they related to computers? • Why this course?
稻田是怎麼灌溉的? 灌溉渠道 水庫
閘門 5 1 6 4 3 2 水利會 控制中心 7 8 如何實施分區輪流灌溉?
水利會理事長的灌溉指示 • 今年三期稻作由9/17開始灌溉 • 9/17灌溉新埔、大埔 • 9/18灌溉北埔、新埔、南埔 • 9/19至9/24輪流,一天灌溉北埔、大埔,另一天灌溉新埔、南埔 • 9/25灌溉新埔 (以上故事純屬虛構) 灌溉和電腦有什麼對應的關係?
Datapath Register 5 Memory Control 1 Controller 6 ALU N 4 Z 3 2 IR PC clock 7 水利會 控制中心 8 multiplexer 閘門排程表 Computer Analogy Machine code 10110110 11101010 01010111 11011011 00100111 …
灌溉區排程表 閘門排程表 灌溉區排程表 Computer Analogy Assembly program ?
理事長的指示 理事長的指示 灌溉區排程表 Computer Analogy High-level Language Program ?
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
From C to Assembly C x = (a+b) * b Assembly MOV AX, a ADD AX, b MUL c MOV x, AX C compiler
From Assembly to Binary Assembly MOV AX, a ADD AX, b MUL c MOV x, AX Assembler 00000000101000010000000000011000 00000000100011100001100000100001 10001100011000100000000000000000 10001100111100100000000000000100 10101100111100100000000000000000 10101100011000100000000000000100 00000011111000000000000000001000 Machine code
Different Levels of Abstractions MOV AX, a ADD AX, b MOV x, AX temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; High Level Language Program Compiler Assembly Language Program more elaborated later in Sec. 1-2: Virtual Machine Concept Assembler 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Machine Language Program Machine Interpretation Control Signal ALUOP[0:3] <= InstReg[9:11] & MASK ° °
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, ….
System Programming • Assembler: • 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 • Linker: • 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
What’s Next? • Basic concepts • What is “assembly language”, “assembly program”, and “assembler”? • How are they related to computers? • Why this course?
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.
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