C

download C

of 222

  • date post

    23-Aug-2014
  • Category

    Documents

  • view

    283
  • download

    3

Embed Size (px)

Transcript of C

C , . 1 223 url:http://www.aegean.gr C 832 00 Copyright , All rights reserved - - C . . .. 2 223 1 , . . . . . . - - C . . .. 3 223 -. . ; - . , ( , , ). -. . , , . Pascal C -. - . - - .1.1. . , . - - C . . .. 4 223 . - . . : (opera-tion code) (operands) 0 1. - . . . - - C . . .. 5 223 CONTROL UNITINTERNAL BUSMARMBRADDRESSDATAMEMORYBUSCONTROL SIGNALSR0R1R15IRPCALUYZADDSUBANDXORCARRY_INALUCONTROLLINES 1.1: . - - C . . .. 6 223 1.1 . :1. ALU . - : () ( -). - 2 bit 22= 4 1.1,2. IR ,3. PC ,4. R0 . . . R15 ,5. Memory Address Register (MAR) - / ,6. Memory Buffer Register (MBR) MAR, MAR,7. CONTROL UNIT - IR CONTROL SIGNALS - . - - C . . .. 7 223 0 00 ADD1 01 SUB2 10 - AND3 11 - XOR 1.1: . - ( ) . . - R2 R3 R1. - , . :00 0001 0010 00112bit00 1.1, 4 bit 0001 = (1)10 R1. bit 0010 0011 R2 R3. , R1= R2 + R3. - . , - - - C . . .. 8 223 , , ., - . - (AssemblyLanguages). , - (mnemonics) . ADD R1, R2, R3 . - . , - (Assembler) . .1.2. 1.1, - . , - - C . . .. 9 223 , . -, . - . . d= a +bc ( b, c - d). - . :1. , ,2. , ( ) ,3. , , , - - C . . .. 10 223 4. , , . , - , . , . , - (reusability). - . FORTRAN (FORmula TRANslation) - IBM , LISP(LIStProcessing) - COBOL(COmmonBusiness-OrientedLanguage) . C, UNIX . - C. systemprogrammingLanguage. Prolog . (Object Oriented Programming OOP) 60 Small- - - C . . .. 11 223 talk. , . OOP , - . , - . . . - OOP C++ Java. - C.1.3. A= a, b, c, . . . , x, y, z . - n A - n-. chapter 7-((((((c,h),a),p),t),e),r). n An, A. A _ , :A= a, b, c, . . . , x, y, z, A, B, C, . . . , X, Y, Z, ., , , :, ; , !, _ p - , p A. - - C . . .. 12 223 : 1.3.1 A , A A. A . B CB = a, b, c, . . . , x, y, z, A, B, C, . . . , X, Y, Z, 0, 1, . . . , 8, 9,+, , /, %, , , &, ,, , !, , (, ), #, ?, :, ; , ., , , , , _, , \ C - B. - . - , . :1. .2. . , - , . - . 1.3.2 : - - C . . .. 13 223 1. T: ,2. N: , ,3. P. , {,, , , , , . . .}. x y xy . x y. :1. , - .2. ,3. - 1 2 . . - - C . . .. 14 223 , +, , = . T = A, B, C, +, , (, ), = N = asgn_stat, exp, term, factor, id :asgn_stat id= expexp exp + termtermterm term factorfactorfactor (exp)idid ABC id -. . :asgn_stat id= exp (1.1) id= exp + term (1.2) id= exp + term factor (1.3) id= exp + term id (1.4) id= exp + term C (1.5) id= exp + factor C (1.6) id= exp + id C (1.7) id= exp + B C (1.8)(1.9) - - C . . .. 15 223 id= term+ B C (1.10) id= factor+ B C (1.11) id= id + B C (1.12) id= A + B C (1.13) A= A + B C (1.14) 1.1 asgn_stat id=exp. - exp exp+term 1.2. - . -1.14 A B C. . - 2. 2. 2 (context-free grammar) . - . , - - C . . .. 16 223 - . . - . . - (typesystem) . - type theory. . , - (runtime exceptions).1.4. , . , , C, - (compilation). - - C . . .. 17 223 . C, - . (compiler) - .PreprocessorLexicalAnalysisSyntacticAnalysisObject CodeGenerationSource CodeLinkingExecutebleLibrariesMachine Dependent 1.2: . 1.2 - C. (preprocessor) , . (Lexical Analysis) (token) . (Syntax Analysis) - . (object code generation) - - C . . .. 18 223 - . , (Linking) ( ), . , - . . . . C - C - . . .. 19 223 2 C2.1. C C . main C main . : (standard lib) ANSI C (user dened). - C, ( .h) . - #include (preprocessor) C. . . . C - C - . . .. 20 223 C C. 2.1 ANSI C . stdarg.h io.h / limits.h & oat.h .math.h mem.h stdio.h stdlib.h string.h & ctype.h time.h 2.1: 2.1 C This is my rst code!!!. main - . main printf This is my rst code!!! ( 3 ). printf stdio.h ( 0 ) . . . C - C - . . .. 21 223 .0: #include 1:2: int main(){3: printf("This is my first code!!!\n");4: return 0;5: } 2.1: . 2.1 .c .. my-FirstCode.c. UNIX, cc - 2.1 #ccmyfirstCode.c myrstCode .2.2. C : char: byte 256 . - ASCII 128. int: byte . . . . C - C - . . .. 22 223 oat: double: , , - C byte . byte - sizeof sizeof(). oat sizeof(oat). < limits.h > < float.h >. , - :#include < limits.h >#include < float.h > C -. int short long. short int short long int long . - sizeof (short) sizeof (int) sizeof (long). int long 4 byte (32-bit) short 2 byte(16-bit). - (oat) 4 byte (32-bit) (double) 8 byte (64-bit). 754 IEEE (Institute of Electrical andElectronics Engineers). long double, long double, . . . C - C - . . .. 23 223 . - long double double. signed () unsigned ( -) char - 754 IEEE . - . char 8-bit bit , 1 0 +. 8-bit 10000001 1 ( ) unsigned 128 , 127+120= 128. - unsigned char 0. . . 255 128. . . 127. int. C typedef :typedef < newTypeName > < oldTypename >; ; C . int integer :typedef integerint; . . . C - C - . . .. 24 223 byte0. . . 255 :typedef byte unsignedchar;2.3. C case-sensitive . : _ . C . 2.2 (reservedwords). . . . C - C - . . .. 25 223 - int, char, double, oat long, short, signed, unsigned, register, static, extern, auto, voidconst, volatile break, case, continue, switch,default, do, while, for, if, else, return, gototypedef, enum struct, union 2.2: - . :< typename > < variable_name >=< value >; (2.1) . 2.1 = . . . C - C - . . .. 26 223 . ; C, . :intcount= 5; byte ( int) count 00000000 00000000 00000000 00000101 5. :double percent= 28.5, rate= 5.6; percent rate 28.5 5.6 . - . . count =5; 5 count.2.4. C, , -. . . . C - C - . . .. 27 223 . C: literal: =3.14159 literal 3.14159. , literal 3.14159 - PI . 2 C :1. const: constfloatPI = 3.14159;2. #dene:#define PI 3.14159 PI. #undef. PI :#undef PI int (signed) long. long L U, .. 2048L 2048U 2048UL. 0 0x 0X , .. 077= (63)10 0x2f = (63)10. . . . C - C - . . .. 28 223 (.. 23.45) (2e-3) ( 2103) double :F f oatL l double. .. x. , 8 bit ASCII x 120 x ASCII . . 2.3 ASCII - . C, \ . . - n n \n ASCII ASC