Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2422 Basic Concepts Department of Computer Science National Tsing Hua University.

Similar presentations


Presentation on theme: "CS2422 Basic Concepts Department of Computer Science National Tsing Hua University."— Presentation transcript:

1 CS2422 Basic Concepts Department of Computer Science National Tsing Hua University

2 Assembly Language for Intel- Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed. Slides prepared by the author, with modification Revision date: June 3, 2006 Kip Irvine

3 當你在寫 C 程式時, 心中想像的電腦是長什麼樣子? CPU, memory, I/O, Operations on variables, …

4 3 A Model of Computer for C +  if for && CPU Memory i, j, k; xfloat, yfloat; A[0], A[1], … i = i + j; xfloat = 1.0; if (A[0]==0) … Program Counter Typed storage

5 這個 model 和你實際跑程式的 電腦有很大的差別! 為什麼你用這個 C 的 model 所寫的程式能在你的電腦上執行? 顯然有人為你做了轉換!

6 5 MOV AX, a ADD AX, b MUL c MOV x, AX x = (a+b) * b 我們已經知道... C compiler Assembly program C program

7 可見得組合語言程式更靠近 實際的電腦 組合語言程看到的電腦 是長什麼樣子 ?

8 7 A Model of Computer for ASM CPU Memory MOV AX, a ADD AX, b MOV x, AX … 010100110010101 a 110010110001010 b 000000000010010 x AX BX... + - PC Register ALU Take the data stored in memory address a, and move it to register AX Take the data stored in memory address b, and add it to register AX Take the data stored in register AX, and move it to memory address x

9 組合語言程式 / 機器碼 看到的電腦, 離實際電腦還是有一段差距 e.g. 多核心、 hyperthreading 當然仍需要再一或多層的轉換!

10 Computer Model of a Lower Layer (from Computer Architecture textbook)

11 10 A Layered View of Computer +  if for && CPU Memory i, j, k; xfloat, yfloat; A[0], A[1], … i = i + j; if (A[0]==0) … Program Counter CPU Memory ADD AX, b MOV x, AX … 010100110010101 a 110010110001010 b 000000000010010 x AX BX JX... + - PC i = i + j; xfloat = 1.0; if (A[0]==0) … MOV AX, a ADD AX, b MOV x, AX … xxxxxx xxxxx

12 11 What’s Next?  Virtual machine concept (Sec. 1-2)  Data representation (Sec. 1-3)

13 12 Virtual Machine Concept  Purpose of this section: Understand the role of assembly language in a computer system  Side product: The principle of layered abstraction for combating complexities, e.g. OSI 7-layer protocol

14 13 Virtual Machine Concept  A layered abstraction of computers proposed by A. Tanenbaum  Each layer provides an abstract computer, or virtual machine, to its upper layer  Virtual machine: A hypothetical computer that can be constructed of either HW or SW What is a computer?

15 14 Simplest Model of Computers Compute engine Memory Input data Output data Program Instructions c.f., y = f(x) Layered abstraction: A computer consists of layers of such virtual machine abstractions

16 15 Why Layered Abstraction?  Big idea: layered abstraction to combat complexities A strategy of divide-and-conquer Decompose a complex system into layers with well-defined interfaces Each layer is easier to manage and handle Only need to focus on a particular layer, e.g. to make it the best  Also, it makes interaction clear Particularly if one layer is realized in hardware and the other in software

17 16 Layered Abstraction of Computer  Each layer as a hypothetical computer, or virtual machine, that runs a programming language Can be programmed with the programming language to process inputs and outputs  Program written in L i can be mapped to that L i-1 by: Interpretation: L i-1 program interprets and executes L i instructions one by one Translation: L i program is completely translated into L i-1 program, and runs on L i-1 machine Compute engine Memory Input data Output data Program Instructions

18 17 Layered Abstraction of Computer +  if for && CPU Memory i, j, k; xfloat, yfloat; A[0], A[1], … i = i + j; if (A[0]==0) … Program Counter CPU Memory ADD AX, b MOV x, AX … 010100110010101 a 110010110001010 b 000000000010010 x AX BX JX... + - PC i = i + j; xfloat = 1.0; if (A[0]==0) … MOV AX, a ADD AX, b MOV x, AX … xxxxxx xxxxx LiLi L i-1 Virtual Machine

19 18 Languages of Different Layers English: Display the sum of A times B plus C. C++: cout << (A * B + C); Assembly Language: mov eax,A mul B add eax,C call WriteInt Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000

20 19 High-Level Language Level 5  Application-oriented languages, e.g., C, C++, Java, Perl  Written with certain programming model in mind Variables in storage Operators for operations  Programs compiled into assembly language (Level 4) or interpreted by interpreters What kind of computer does C see?

21 20 Assembly Language Level 4  Instruction mnemonics that have a one-to-one correspondence to machine language  Based on a view of machine: register organization, addressing, operand types and locations, functional units, …  Calls functions written at the OS level (Level 3)  Programs are translated into machine language (Level 2) What kind of computer does it see?

22 21 Operating System Level 3  Provides services to Level 4 programs as if it were a computer  How about VMware?  How about JVM?

23 22 Instruction Set Architecture Level 2  Known as conventional machine language  Attributes of a computer as seen by assembly programmer, i.e. conceptual structure and functional behavior Organization of programmable storage Data types and data structures Instruction set and formats Addressing modes and data accessing  Executed by Level 1 program (microarchitecture)

24 23 Microarchitecture Level 1  Can be described by register transfer language (RTL)  Interprets conventional machine instructions (Level 2)  Executed by digital hardware (Level 0) Z N Register Memory PC IR Controller ALU clock Control Signals

25 24 Digital Logic Level 0  CPU, constructed from digital logic gates  System bus  Memory

26 25 What’s Next?  Virtual machine concept (Sec. 1-2)  Data representation (Sec. 1-3)

27 26 Data Representation  Purpose of this section Assembly program often needs to process data, and manage data storage and memory locations  need to know data representation and storage  Binary numbers: translating between binary and decimal  Binary addition  Integer storage sizes  Hexadecimal integers: translating between decimal and hex.; hex. subtraction  Signed integers: binary subtraction  Character storage

28 27 Integer Storage Sizes What is the largest unsigned integer that may be stored in 20 bits? Standard sizes: Why unsigned numbers?

29 28 Signed Integers  The highest bit indicates the sign 1 = negative, 0 = positive If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples: 8A, C5, A2, 9D

30 29 Forming Two's Complement  Negative numbers are stored in two's complement notation Complement (reverse) each bit Add 1 Note that 00000001 + 11111111 = 00000000 Why?

31 30 Binary Subtraction  When subtracting A – B, convert B to its two's complement  Add A to (–B)1 1 0 0 –0 0 1 1 + 1 1 0 1 1 0 0 1 Practice: Subtract 0101 from 1001

32 31 Ranges of Signed Integers  The highest bit is reserved for the sign  This limits the range: What is the largest positive value that may be stored in 20 bits?

33 32 Character Storage  Character sets Standard ASCII (0 – 127) ‒ American Standard Code for Information Interchange Extended ASCII (0 – 255) ANSI (0 – 255) ‒ American National Standard Institute Unicode (0 – 65,535): UTF-8. UTF-16, UTF-32  Null-terminated string Array of characters followed by a null byte  Using the ASCII table back inside cover of book

34 33 Chapter Summary  Assembly language helps you learn how software is constructed at the lowest levels  Assembly language has a one-to-one relationship with machine language  Each layer in a computer's architecture is an abstraction of a machine layers can be hardware or software  Assembly programs and assemblers often need to manage data storage in memory, and it is important to understand data representation and size of different data


Download ppt "CS2422 Basic Concepts Department of Computer Science National Tsing Hua University."

Similar presentations


Ads by Google