Presentation is loading. Please wait.

Presentation is loading. Please wait.

國立政治大學資訊科學系 Introduction

Similar presentations


Presentation on theme: "國立政治大學資訊科學系 Introduction"— Presentation transcript:

1 國立政治大學資訊科學系 Introduction
2017/2/24 系統程式 Introduction

2 Computer Architecture and Organization
Related Courses Operating System Computer Programming Compiler Introduction to Computer Science System Programming SW HW Introduction to Digital System Data structure Algorithm Computer Architecture and Organization 國立政治大學資訊科學系

3 An Overview System software?
國立政治大學資訊科學系 2017/2/24 An Overview System software? System software vs. application software: System software are usually related to the architecture of the machine on which they are to run. Some aspects of system software do not directly depend on its host machine. Simplified Instructional Computer (SIC) 國立政治大學資訊科學系

4 Systems Programming Applications System H/W Software 國立政治大學資訊科學系
2017/2/24 Systems Programming Applications System Software H/W 國立政治大學資訊科學系

5 Example: Programming sample.c Compiler sample.exe Loader, Linker &
國立政治大學資訊科學系 2017/2/24 Example: Programming sample.c Compiler sample.exe Loader, Linker & Runtime System output 國立政治大學資訊科學系

6 國立政治大學資訊科學系 2017/2/24 Computers 國立政治大學資訊科學系

7 Mother Board 國立政治大學資訊科學系 國立政治大學資訊科學系 2017/2/24
Source: Charles S. Parker, Understanding Computers Today & Tomorrow, Dryden, 1998 國立政治大學資訊科學系

8 CPU 國立政治大學資訊科學系 國立政治大學資訊科學系 2017/2/24
國立政治大學資訊科學系 Source: Charles S. Parker, Understanding Computers Today & Tomorrow, Dryden, 1998

9 Turing Machine Tape Head Table State Register 國立政治大學資訊科學系 國立政治大學資訊科學系
2017/2/24 Turing Machine Tape Head Table State Register Turing Machine were described in 1936 by Alan Turing. 國立政治大學資訊科學系

10 The von Neumann architecture
國立政治大學資訊科學系

11 SIC Machine Architecture
國立政治大學資訊科學系 2017/2/24 SIC Machine Architecture Memory 8-bit bytes A word consists of three bytes and is addressed by the lowest numbered byte. A total of 32,768 (2^15) bytes in memory Registers Five 24-bit special-purpose registers A (accumulator), X (index), L (linkage), PC (program counter), SW (status word) IP: instruction pointer 國立政治大學資訊科學系

12 SIC (2) Data Formats Instruction Formats
國立政治大學資訊科學系 2017/2/24 SIC (2) Data Formats 24-bit integers (no floating-point numbers) negative values are represented by 2’s complement 8-bit ASCII for characters Instruction Formats 8 1 15 opcode x address 國立政治大學資訊科學系

13 SIC (3) Addressing Modes Instruction Set Direct Mode: x=0; TA=address
國立政治大學資訊科學系 2017/2/24 SIC (3) Addressing Modes Direct Mode: x=0; TA=address Indexed Mode: x=1; TA=address+(X) Instruction Set Load and store registers Integer arithmetic Value comparison Branching int a[10] for (int i=0; i<10; i++) a[i] = i; if ((a>b) && (x<y)) c=a+b; else c=20+y-x; 國立政治大學資訊科學系

14 存取指令:LDA Memory 位址 內容 CPU A暫存器 國立政治大學資訊科學系

15 存取指令:STA Memory 位址 內容 CPU A暫存器 國立政治大學資訊科學系

16 資料複製:LDA & STA Memory 位址 內容 CPU A暫存器 C1=D1 LDA D1 STA C1 國立政治大學資訊科學系

17 算術運算:ADD、SUB、MUL、DIV
Memory 位址 內容 CPU A暫存器 G1=R1+B1 LDA R1 ADD B1 STA G1 國立政治大學資訊科學系

18 SIC Machine Instructions
國立政治大學資訊科學系 2017/2/24 SIC Machine Instructions Examples: LDA (LoaD into the register A) addr=0300 TA=0300 addr=0300 (X)=0100 TA=addr+(X)=0400 (X)=0100 0300 103000 0400 103333 國立政治大學資訊科學系

19 SIC/XE Machine Architecture
國立政治大學資訊科學系 2017/2/24 SIC/XE Machine Architecture Memory: 1 MB Register: 4 new registers: B (base), S (general), T (general), F (floating-point accumulator) Float-point 48bits Data Format: n = fraction exponent 11 s 1 36 國立政治大學資訊科學系

20 SIC/XE Instruction Formats
國立政治大學資訊科學系 2017/2/24 SIC/XE Instruction Formats More complex instruction formats are required to meet the need to address 1MB. SIC/XE has four instruction formats: op 8 Discuss WHY 6 bits are sufficient. op r1 r2 4 n i x b p e op disp 6 12 n i x b p e op address 20 國立政治大學資訊科學系

21 SIC/XE Machine Instructions
國立政治大學資訊科學系 2017/2/24 SIC/XE Machine Instructions Please refer to Figure 1.1 on page 11 How does a SIC/XE processor differentiate format 1, 2, 3, and 4 instructions? differentiate format 3 and 4 instructions? know when to compute target address using based relative addressing, program-counter relative address, or neither? determine how to find actual operands with immediate, direct, indirect modes? 國立政治大學資訊科學系

22 Encoding Format Information
國立政治大學資訊科學系 2017/2/24 Encoding Format Information OPCODE 0X 1X 2X 3X 4X 5X 6X 7X FORMAT 3/4 OPCODE 8X 9X AX BX CX DX EX FX FORMAT 3/4 2 1 國立政治大學資訊科學系

23 Decoding SIC/XE instructions
國立政治大學資訊科學系 2017/2/24 Decoding SIC/XE instructions Suppose that you are given a machine instruction in the hexadecimal format. You decode the instruction with the following steps. Determine the format of the instruction (Rewrite the instruction in its binary format) If it is a format 1 or 2 instruction… If it is a format 3 or 4 instruction… 國立政治大學資訊科學系

24 Deciding SIC/XE Instruction Formats
Format 1: if first byte is CX or FX Format 2: if first byte is 9X, AX, or BX Format 3 or Format 4: all else If n=i=0: a SIC instruction, get two more bytes SIC/XE instructions all else Decode the next byte and check the e bit If e=0: Format 3 If e=1: Format 4 國立政治大學資訊科學系

25 Decoding Format 1/2 Instruction
國立政治大學資訊科學系 2017/2/24 Decoding Format 1/2 Instruction Format 1 Find the opcode in Appendix A Format 2 Translate register numbers back to corresponding register names Tables on pages 5 and 7 國立政治大學資訊科學系

26 Decoding Format 3/4 Instructions
國立政治大學資訊科學系 2017/2/24 Decoding Format 3/4 Instructions Steps: Fill the rightmost two bits of the opcode with 0s Find the opcode in Appendix A If format 3 instruction, add 8 zeros (if binary format) or 2 zeros (if hexadecimal format) to the left of disp Calculate target address according to bits x, b, and p Determine the addressing mode according to bits n and i Find the actual operand Carry out the operation 國立政治大學資訊科學系

27 解讀SIC/XE機器語言指令 找出Target Address

28 Figure 1.1 TA = (PC) + disp TA = (PC) + disp = 3000+600=3600
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA = (PC) + disp TA = (PC) + disp = =3600 國立政治大學資訊科學系

29 Figure 1.1 TA = (X)+(B) + disp TA = (X)+(B) + disp=90+6000+300=6390
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA = (X)+(B) + disp TA = (X)+(B) + disp= =6390 國立政治大學資訊科學系

30 Figure 1.1 TA = (PC) + disp TA = (PC) + disp = 3000+30=3030
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA = (PC) + disp TA = (PC) + disp = =3030 國立政治大學資訊科學系

31 國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA = disp TA = disp = 30 國立政治大學資訊科學系

32 Figure 1.1 TA = disp TA = disp = 0C303 國立政治大學資訊科學系 國立政治大學資訊科學系
2017/2/24 Figure 1.1 TA = disp TA = disp = 0C303 國立政治大學資訊科學系

33 Figure 1.1(Cont’d) The fifth example: 003600
國立政治大學資訊科學系 2017/2/24 Figure 1.1(Cont’d) The fifth example: According to the third paragraph on page 10, the b, p, and e bits merge with disp because n=i=0. Discussion: When would a SIC/XE assembler set n=i=0 and n=i=1? 國立政治大學資訊科學系

34 Figure 1.1 n=i=0 標記一個SIC指令 所以TA等於3600 國立政治大學資訊科學系 國立政治大學資訊科學系
2017/2/24 Figure 1.1 n=i=0 標記一個SIC指令 所以TA等於3600 國立政治大學資訊科學系

35 解讀SIC/XE機器語言指令 找出實際運算對象

36 Figure 1.1 TA是運算資料的位址 TA = (PC) + disp = 3000+600=3600
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA是運算資料的位址 TA = (PC) + disp = =3600 TA = (PC) + disp 國立政治大學資訊科學系

37 Figure 1.1 TA是運算資料的位址 TA = (X)+(B) + disp=90+6000+300=6390
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA是運算資料的位址 TA = (X)+(B) + disp= =6390 TA = (X)+(B) + disp 國立政治大學資訊科學系

38 Figure 1.1 TA是運算資料的位址的位址 TA = (PC) + disp = 3000+30=3030
國立政治大學資訊科學系 2017/2/24 Figure 1.1 TA是運算資料的位址的位址 TA = (PC) + disp = =3030 TA = (PC) + disp 國立政治大學資訊科學系

39 Figure 1.1 TA本身就是運算資料 TA = disp = 30 TA = disp 國立政治大學資訊科學系 國立政治大學資訊科學系
2017/2/24 Figure 1.1 TA本身就是運算資料 TA = disp = 30 TA = disp 國立政治大學資訊科學系

40 Figure 1.1 SIC指令只要看x是否為1 n=i=0 標記一個SIC指令 所以TA等於3600 國立政治大學資訊科學系
2017/2/24 Figure 1.1 SIC指令只要看x是否為1 n=i=0 標記一個SIC指令 所以TA等於3600 國立政治大學資訊科學系

41 Figure 1.1 TA是運算資料的位址 TA = disp = 0C303 TA = disp 國立政治大學資訊科學系
2017/2/24 Figure 1.1 TA是運算資料的位址 TA = disp = 0C303 TA = disp 國立政治大學資訊科學系

42 SIC/XE機器語言指令的解讀 實際上,機器語言的解讀是非常機械化的過程 附錄A(第三版課本的第499頁上面)有更多的解讀機制
除了提供解讀更多機制之外,附錄A(第三版課本的第499頁上面)的表格,還揭露了SIC/XE CPU的設計有更多的限制。有一些看似可以的addressing mode並沒有出現在表格中。這一些是來自於硬體線路的設計的限制。對於SIC/XE來說,當然是假想的限制。 國立政治大學資訊科學系

43 SIC/XE (1) e=1: format 4; e=0: format 3 b=1, p=0: base relative
國立政治大學資訊科學系 2017/2/24 SIC/XE (1) n i x b p e op disp 6 12 20 op n i x b p e address e=1: format 4; e=0: format 3 b=1, p=0: base relative TA=(B)+disp b=0, p=1: pc relative TA=(PC)+disp (Negative values are in 2’s complement notation.) n: indirect i: immediate x: index b: base p: program counter e: extended 國立政治大學資訊科學系

44 SIC/XE (2) b=0,p=0: disp is used as the TA.
國立政治大學資訊科學系 2017/2/24 SIC/XE (2) n i x b p e op disp 6 12 n i x b p e op address 20 b=0,p=0: disp is used as the TA. For a Format 4 instruction, b and p are normally set to 0. (simple addressing) i=1,n=0: immediate addressing i=0,n=1: indirect addressing (Data addressed by TA is used as the address of the real operand.) n: indirect i: immediate x: index b: base p: program counter e: extended 國立政治大學資訊科學系

45 國立政治大學資訊科學系 2017/2/24 SIC/XE (3) n i x b p e op disp 6 12 n i x b p e op address 20 i=n=0 or i=n=1: respectively, direct and simple addressing (TA is the location of the operand.) n: indirect i: immediate x: index b: base p: program counter e: extended 國立政治大學資訊科學系

46 SIC/XE (4) Summary of addressing modes n i x b p e Format 3 1 Format 4
國立政治大學資訊科學系 2017/2/24 SIC/XE (4) Summary of addressing modes n i x b p e Format 3 1 Format 4 1 Format 3, base relative 1 Format 3, pc relative 0/1 Format 3/4, disp is TA, direct 1 immediate (TA: operand) 1 indirect (TA: address of address) 1 1 simple (TA: address of operand) 1 index 國立政治大學資訊科學系

47 Figure 1.2 A register of SIC ?????? ALPHA LDA FIVE STA ALPHA
國立政治大學資訊科學系 2017/2/24 Figure 1.2 A register of SIC ?????? ALPHA LDA FIVE STA ALPHA LDCH CHARZ STCH C1 ……… ALPHA RESW 1 FIVE WORD 5 CHARZ BYTE C’Z’ C1 RESB 1 000005 FIVE 5A CHARZ ?? C1 國立政治大學資訊科學系

48 Figure 1.3 A = ALPHA+INCR-1 A = ALPHA A = ALPHA+INCR A register of SIC
國立政治大學資訊科學系 2017/2/24 Figure 1.3 A = ALPHA+INCR-1 A = ALPHA A = ALPHA+INCR A register of SIC 000001 ONE LDA ALPHA ADD INCR SUB ONE STA BETA ……… ONE WORD 1 ALPHA RESW 1 BETA RESW 1 GAMMA RESW 1 DELTA RESW 1 INCR RESW 1 ?????? ALPHA ?????? BETA ?????? GAMMA ?????? DELTA ?????? INCR 國立政治大學資訊科學系

49 Figure 1.4 X(X)+1: (X):ELEVEN A register of SIC STR1 STR2
國立政治大學資訊科學系 2017/2/24 Figure 1.4 X(X)+1: (X):ELEVEN STATUS WORD, CONDITION CODE A register of SIC STR1 STR2 T ? X X register of SIC E ? S ? LDX ZERO MOVECH LDCH STR1,X STCH STR2,X TIX ELEVEN JLT MOVECH ……… STR1 BYTE C’TEST STRING’ STR2 RESB 11 ZERO WORD 0 ELEVEN WORD 11 T ? ? S ? T ? R ? I ? N ? G ? ZERO 000000 ELEVEN 00000B 國立政治大學資訊科學系

50 SIC Programming Examples
國立政治大學資訊科學系 2017/2/24 SIC Programming Examples Figure 1.2 on page 13 Figure 1.3 on page 15 Figure 1.4 on page 16 Figure 1.5 on page 17 Figure 1.6 on page 19 Figure 1.7 on page 20 國立政治大學資訊科學系

51 Figure 1.2 RESW: REServe Word RESB: REServe Byte 1-8 label 9 blank
國立政治大學資訊科學系 2017/2/24 RESW: REServe Word RESB: REServe Byte Figure 1.2 int ALPHA; int FIVE=5; ALPHA=FIVE; CHAR CHARZ=‘Z’; CHAR C1; C1 = CHARZ; 1-8 label 9 blank 10-15 instruction 16-17 blank 18-35 operand 36-66 comments K1 WORD CHARS BYTE C’ABCDE’ 國立政治大學資訊科學系

52 Figure 1.3 BETA=ALPHA+INCR-1 DELTA=GAMMA+INCR-1 國立政治大學資訊科學系
2017/2/24 Figure 1.3 BETA=ALPHA+INCR-1 DELTA=GAMMA+INCR-1 國立政治大學資訊科學系

53 Figure 1.4 char str1[11]=“TEST STRING”, str2[11];
國立政治大學資訊科學系 2017/2/24 Figure 1.4 char str1[11]=“TEST STRING”, str2[11]; for (i=0; i<11; i++) str2[i]=str1[i]; 國立政治大學資訊科學系

54 Figure 1.5 int i, alpha[100], beta[100], gamma[100];
國立政治大學資訊科學系 2017/2/24 THREE WORD 3 Figure 1.5 int i, alpha[100], beta[100], gamma[100]; for (i=0; i<99; i++) gamma[i] = alpha[i]+beta[i]; 國立政治大學資訊科學系

55 國立政治大學資訊科學系 2017/2/24 Figure 1.6 國立政治大學資訊科學系

56 Figure 1.7 要記住回來的位址 L(PC); PCm 回到剛剛記住的返回位址 PC(L)
國立政治大學資訊科學系 2017/2/24 要記住回來的位址 L(PC); PCm Figure 1.7 回到剛剛記住的返回位址 PC(L) Fetch-Decode-Execute 國立政治大學資訊科學系

57 Gains by Using SIC/XE (Usually) smaller programs
(Usually) more efficient programs Why? 國立政治大學資訊科學系

58 Figure 1.2 假設記憶體存取費時n秒鐘 假設暫存器存取費時m秒鐘 LDA:2n 載入指令費時n秒鐘 載入資料再費時n秒鐘
國立政治大學資訊科學系 2017/2/24 假設記憶體存取費時n秒鐘 假設暫存器存取費時m秒鐘 Figure 1.2 LDA:2n 載入指令費時n秒鐘 載入資料再費時n秒鐘 STA:2n 載入指令費時n秒鐘 儲存資料再費時n秒鐘 合計2n+2n+2n+2n=8n秒鐘 LDA:n 載入指令費時n秒鐘 STA:2n 載入指令費時n秒鐘 儲存資料再費時n秒鐘 合計n+2n+n+2n=6n秒鐘 國立政治大學資訊科學系

59 Figure 1.3 LDA, ADD, SUB:2n 載入指令費時n秒鐘 載入資料再費時n秒鐘 STA:2n 載入指令費時n秒鐘
國立政治大學資訊科學系 2017/2/24 Figure 1.3 LDA, ADD, SUB:2n 載入指令費時n秒鐘 載入資料再費時n秒鐘 STA:2n 載入指令費時n秒鐘 儲存資料再費時n秒鐘 假設記憶體存取費時n秒鐘 假設暫存器存取費時m秒鐘 實務上,n>>m 合計8*2n=16n秒鐘 (程式大小:13*3=39 bytes) LDS, LDA:2n 載入指令費時n秒鐘 載入資料再費時n秒鐘 ADDR:m 載入資料費時m秒鐘 SUB #...:n 載入指令費時n秒鐘 合計2n+2n+m+n+2n+2n+m+n+2n=12n+2m秒鐘 STA:2n 國立政治大學資訊科學系 程式大小:12*3+2*2=30 bytes

60 Fetch-Decode-Execute Cycles
國立政治大學資訊科學系 2017/2/24 Fetch-Decode-Execute Cycles Source: Charles S. Parker, Understanding Computers Today & Tomorrow, Dryden, 1998 國立政治大學資訊科學系

61 Executing A Machine Instruction
國立政治大學資訊科學系 2017/2/24 Executing A Machine Instruction 0x103000 (A)  0x103333 (A)=000116,(X)= ,(PC)=010016 Instructions 000300 0100 008300 0103 A SW PC L X ALU CU Three steps: Fetch Decode Execution 103000 0300 103333 0400 國立政治大學資訊科學系

62 Fetch-Decode-Execute Cycles (2)
國立政治大學資訊科學系 2017/2/24 Fetch-Decode-Execute Cycles (2) The CPU fetches the data pointed by the PC, and increases its program counter (instruction pointer) appropriately. Then, the CPU decodes the fetched data as an instruction, and executes the instruction Questions: How does the CPU know where to get the very first instruction? Where is the very first executed instruction stored? What functions should the first few instructions perform? Ram: random access memory Rom: read only memory Bios: basic input output system 國立政治大學資訊科學系

63 CISC and RISC Complex Instruction Set Computers
國立政治大學資訊科學系 2017/2/24 CISC and RISC Complex Instruction Set Computers VAX (DEC) Pentium (Intel) Reduced Instruction Set Computers UltraSPARC (Sun Microsystems) PowerPC (IBM, Motorola, Apple) 國立政治大學資訊科學系

64 Big and Little Endian Word address: 0F03 Data ordering 000301 0F00
國立政治大學資訊科學系 2017/2/24 Big and Little Endian Word address: 0F03 Data ordering 000301 0F00 008302 0F03 008333 0F06 02 0F03 83 0F04 00 0F05 33 0F06 0F07 0F08 01 0F00 03 0F01 0F02 00 0F03 83 0F04 02 0F05 0F06 0F07 33 0F08 0F00 03 0F01 01 0F02 國立政治大學資訊科學系

65 Little endian n = 66051 n is allocated at Big endian #include <stdio.h> int main() { int n = 256*256+2*256+3; unsigned char *c; printf("n = %d\n", n); c = (unsigned char*) (void*) &n; printf("n is allocated at\n%11u\t%11u\t%11u\t%11u\n", c, c+1, c+2, c+3); printf("%11u\t", *c++); printf("%11u\n", *c++); return 0; } 國立政治大學資訊科學系

66 VAX 國立政治大學資訊科學系

67 VAX Memory 8-bit bytes, word, longword, quadword, octaword
國立政治大學資訊科學系 2017/2/24 VAX Memory 8-bit bytes, word, longword, quadword, octaword virtual address space of 4 giga bytes (4GB) system space and process space Registers 16 32-bit general registers; some have special uses processor status longword (PSL) Data Formats Instruction Formats opcode 1~2, oprand 0~6 Instruction Set and Addressing Modes I/O 國立政治大學資訊科學系

68 Pentium Pro Memory Byte, word, double word Segment, page Registers
國立政治大學資訊科學系 2017/2/24 Pentium Pro Memory Byte, word, double word Segment, page Registers 8 32bit GPR, 6 16bit segment register, EIP, FLAG Data Formats Instruction Formats 1~10 Addressing Modes Instruction Sets 400 I/O 國立政治大學資訊科學系

69 UltraSPARC Memory Byte, halfword, word, double word 2^64, support page
國立政治大學資訊科學系 2017/2/24 UltraSPARC Memory Byte, halfword, word, double word 2^64, support page Registers (>100) Procedure can only access 32 Data Formats Instruction Formats All 32 bit long Addressing Modes Instruction Sets >100 I/O 國立政治大學資訊科學系

70 Target address calculation Register indirect TA=(Register)
Mode Target address calculation Register indirect TA=(Register) Register indirect with index TA=(Register-1)+(Register-2) Register indirect with immediate index TA=(Register)+displacement 國立政治大學資訊科學系

71 PowerPC Memory Byte, halfword, word, double word 2^64, segments, pages
國立政治大學資訊科學系 2017/2/24 PowerPC Memory Byte, halfword, word, double word 2^64, segments, pages Registers 32 64bit GPRs, 32 64bit FGPRs Data Formats Instruction Formats 32bit Addressing Modes Instruction Sets 200 I/O 國立政治大學資訊科學系

72 Target address calculation PC-relative TA=(PC)+displacement
Mode Target address calculation PC-relative TA=(PC)+displacement Register indirect with displacement TA=(Register)+displacement Register indirect indexed TA=(Register-1)+(Register-2) 國立政治大學資訊科學系

73 Cell 國立政治大學資訊科學系

74 T3E-900 國立政治大學資訊科學系

75 Cray T3E Memory Registers (>100) Data Formats Instruction Formats
國立政治大學資訊科學系 2017/2/24 Cray T3E Memory Registers (>100) 32 64bit GPRs each node Data Formats Instruction Formats Addressing Modes Instruction Sets I/O 國立政治大學資訊科學系

76 Load and store Branch Mode Target address calculation Absolute
TA=actual address Relative TA=(PC)+displacement Link Register TA=(LR) Count Register TA=(CR) Branch Mode Target address calculation PC-relative TA=(PC)+displacement Register indirect with displacement TA=(Register)+displacement 國立政治大學資訊科學系

77 Appendix A: SIC/XE Instructions
國立政治大學資訊科學系 2017/2/24 Appendix A: SIC/XE Instructions FIX C416 ADDR A,X SIC/XE: SIC: 國立政治大學資訊科學系


Download ppt "國立政治大學資訊科學系 Introduction"

Similar presentations


Ads by Google