├── (完整word版)系统级编程总结.doc ├── 01-C++fundamentals └── slp-lab01-cfundamentals-230824.doc ├── 02.1-Representation of Data ├── slp-week02-lab-dlab │ └── slp-week02-lab-dlab │ │ ├── Data_Lab.html │ │ └── dlab │ │ ├── bin │ │ └── Debug │ │ │ └── dlab.exe │ │ ├── bits.c │ │ ├── bits.h │ │ ├── bits.o │ │ ├── btest.c │ │ ├── btest.h │ │ ├── decl.c │ │ ├── dlab.cbp │ │ ├── dlab.depend │ │ ├── dlab.layout │ │ ├── getopt.c │ │ ├── getopt.h │ │ ├── obj │ │ └── Debug │ │ │ ├── bits.o │ │ │ ├── btest.o │ │ │ ├── decl.o │ │ │ ├── getopt.o │ │ │ └── tests.o │ │ ├── tailor.h │ │ └── tests.c └── slp-week02.1-homework.doc ├── 02.2-Fixed-point Arithmetic ├── slp-week02-lab-fplab │ └── slp-week02-lab-fplab │ │ ├── Fixed-point arithmetic-lab.pdf │ │ └── fp │ │ └── fp │ │ ├── bin │ │ └── Debug │ │ │ └── fp.exe │ │ ├── fixedpoint.cpp │ │ ├── fixedpoint.h │ │ ├── fixedpoint_test.cpp │ │ ├── fp.cbp │ │ ├── fp.depend │ │ ├── fp.layout │ │ └── obj │ │ └── Debug │ │ ├── fixedpoint.o │ │ └── fixedpoint_test.o └── slp-week02.2-homework.doc ├── 03-Representation of Code ├── slp-week03-assemblylab │ └── slp-week03-assemblylab │ │ ├── 1 │ │ └── demo │ │ │ ├── AddSub.s │ │ │ ├── bin │ │ │ └── Debug │ │ │ │ └── demo.exe │ │ │ ├── demo.cbp │ │ │ ├── demo.depend │ │ │ ├── demo.layout │ │ │ ├── main.c │ │ │ └── obj │ │ │ └── Debug │ │ │ └── main.o │ │ └── 2 │ │ ├── FloppyWriter.exe │ │ ├── boot.asm │ │ ├── boot.bin │ │ ├── nasm-2.15.05-installer-x64.exe │ │ ├── nasm-2.15.05-installer-x86.exe │ │ └── slp-lab-BootLoader-e.pdf └── slp-week03-homework.doc ├── 04-Structured Data Repretation └── slp-week04-homework.doc ├── 05-Decoding Lab ├── Decoding_Lab_Instruction.pdf ├── decode │ ├── bin │ │ └── Debug │ │ │ └── decode.exe │ ├── decode.cbp │ ├── decode.depend │ ├── decode.layout │ ├── main.c │ └── obj │ │ └── Debug │ │ └── main.o └── slp-week05-homework.doc ├── 06-Buffer Overflow Attack ├── bufoverflow.c ├── slp-week06-bufferoverflowlab │ ├── main.c │ └── slp-week06-homework.pdf └── slp-week06-homework.doc ├── 07-Debugging Malloc ├── DebuggingMallocLab-Instruction.pdf ├── malloclab │ ├── bin │ │ └── Debug │ │ │ └── malloclab.exe │ ├── debugmalloc.c │ ├── debugmalloc.h │ ├── dmhelper.c │ ├── dmhelper.h │ ├── driver.c │ ├── getopt.c │ ├── getopt.h │ ├── malloclab.cbp │ ├── malloclab.depend │ ├── obj │ │ └── Debug │ │ │ ├── debugmalloc.o │ │ │ ├── dmhelper.o │ │ │ ├── driver.o │ │ │ └── getopt.o │ └── tailor.h └── slp-week07-homework.doc ├── 08.1Memory Debug └── slp-week08.1-memory debug.doc ├── 08.2-Binary Bomb ├── slp-week08.2-homework.doc └── slp-week08.2-lab │ └── slp-week08-lab │ └── code │ ├── bomb.ass │ ├── bomb.c │ └── bomb.exe ├── 09-Garbage Collector ├── slp-week09-homework.doc └── slp-week09-lab.zip ├── 10-Performance Measurement ├── slp-week10-homework.doc ├── slp-week10-lab │ ├── 1timer.rar │ ├── 1timer │ │ ├── timer.doc │ │ ├── timer.html │ │ └── timer │ │ │ └── project │ │ │ ├── graph │ │ │ ├── clsData.cls │ │ │ ├── clsThread.cls │ │ │ ├── frmGraph.frm │ │ │ ├── graph.exe │ │ │ └── graph.vbp │ │ │ ├── graph1.jpg │ │ │ ├── graph2.jpg │ │ │ ├── graph3.jpg │ │ │ ├── graph4.jpg │ │ │ ├── notes.html │ │ │ ├── threadedclient │ │ │ ├── RemoteServer.lib │ │ │ ├── ThreadedClient.cpp │ │ │ ├── ThreadedClient.dsp │ │ │ ├── ThreadedClient.dsw │ │ │ ├── ThreadedClient.ncb │ │ │ ├── ThreadedClient.opt │ │ │ ├── sclient.exe │ │ │ └── servers.h │ │ │ └── timestamp_v1 │ │ │ ├── Timestamp.dsp │ │ │ ├── Timestamp.dsw │ │ │ ├── Timestamp.exe │ │ │ ├── Timestamp.ncb │ │ │ ├── Timestamp.opt │ │ │ ├── Timestamp.plg │ │ │ ├── output.out │ │ │ ├── test.cpp │ │ │ ├── tsc.c │ │ │ └── tsc.h │ ├── 1timer_interval.pdf │ ├── 2profiling.pdf │ ├── precise.rar │ ├── slp-week10-lab-instruction.pptx │ └── timer.c └── 用CodeBlocks Code profiler插件剖析.pdf ├── 11-Program Performance ├── slp-week11-homework.doc └── slp-week11-lab │ ├── Program_Performance_Lab.htm │ ├── main.cpp │ ├── practice1 │ ├── life.txt │ ├── words.cpp │ ├── words3.cpp │ └── 参考的profile输出.txt │ └── practice2 │ ├── data.zip │ ├── data │ ├── call.cpp │ ├── compiler.cpp │ ├── mach.cpp │ ├── math.cpp │ ├── replace.txt │ └── semantics.cpp │ └── substitute.cpp ├── 12-Memory Moutain ├── slp-week12-homework.doc └── slp-week12-lab.zip ├── 13.1-Cache Miss Rate └── slp-week13.1-classwork.docx ├── 13.2-Cache Aware Programming └── slp-week13-lab │ ├── practice1 │ └── Cache miss rate calculation.doc │ └── practice2 │ ├── Cache Lab.htm │ └── cachelab │ ├── cache.c │ ├── cache.h │ ├── defs.h │ ├── driver.c │ ├── rotate.c │ ├── smooth.c │ ├── 屏幕截图 2023-12-04 151356.png │ ├── 屏幕截图 2023-12-04 151425.png │ ├── 屏幕截图 2023-12-04 161343.png │ └── 屏幕截图 2023-12-04 161406.png ├── 14.1-PE COFF File Format ├── slp-week14.1-homework.doc └── slp-week14.1-pe_coff_lab │ ├── pe_coff_lab.doc │ ├── 实验一 │ └── test.c │ ├── 实验三 │ ├── main.c │ ├── main.exe.txt │ ├── main.obj │ ├── main.txt │ ├── swap.c │ ├── swap.obj │ └── swap.txt │ └── 实验二 │ ├── a.c │ └── b.c ├── 14.2-Tiny Linker ├── slp-week14.2-homework.doc └── slp-week14.2-tiny_linker_lab │ ├── linker lab.doc │ ├── tiny_linker_instruction.ppt │ └── tinylinker │ ├── getopt.c │ ├── getopt.h │ ├── linker.c │ ├── linker.h │ ├── main.c │ ├── output-5.txt │ ├── tailor.h │ └── test │ ├── input-1.txt │ ├── input-2.txt │ ├── input-3.txt │ ├── input-4.txt │ ├── input-5.txt │ ├── input-6.txt │ ├── input-7.txt │ ├── input-8.txt │ ├── input-9.txt │ ├── output-1.txt │ ├── output-2.txt │ ├── output-3.txt │ ├── output-4.txt │ ├── output-5.txt │ ├── output-6.txt │ ├── output-7.txt │ ├── output-8.txt │ └── output-9.txt ├── 15-Exception ├── slp-week15-homework.doc └── slp-week15-lab │ ├── practice1 │ └── TwoThread │ │ ├── Debug │ │ ├── TwoThread_RaceCondition.exe │ │ ├── TwoThread_RaceCondition.ilk │ │ ├── TwoThread_RaceCondition.pch │ │ ├── TwoThread_RaceCondition.pdb │ │ ├── main.obj │ │ ├── vc60.idb │ │ └── vc60.pdb │ │ ├── TwoThread_RaceCondition.dsp │ │ ├── TwoThread_RaceCondition.dsw │ │ ├── TwoThread_RaceCondition.ncb │ │ ├── TwoThread_RaceCondition.opt │ │ ├── TwoThread_RaceCondition.plg │ │ └── main.c │ └── practice2 │ ├── Thread_Programming.html │ └── handout │ ├── RemoteServer.lib │ ├── ThreadedClient.cpp │ ├── ThreadedClient.dsp │ ├── ThreadedClient.dsw │ ├── ThreadedClient.ncb │ ├── ThreadedClient.opt │ ├── notes.html │ ├── sclient.exe │ └── servers.h ├── README.md ├── slp-week01.0-e-20230824.pptx ├── slp-week01.1-e.ppt ├── slp-week02-e.pptx ├── slp-week03.pdf ├── slp-week04.pptx ├── slp-week05.pptx ├── slp-week06-231011.pptx ├── slp-week07.pdf ├── slp-week08.pdf ├── slp-week09.pdf ├── slp-week10.pdf ├── slp-week11.ppt ├── slp-week12.pptx ├── slp-week13.ppt ├── 平时mq试题及答案 ├── mq01.doc ├── mq02.doc ├── mq03.doc ├── mq04.doc ├── mq05.doc ├── mq06.doc ├── mq07.doc ├── mq08.doc ├── mq09.doc ├── mq10.doc ├── mq11.doc ├── mq12.doc ├── mq13.doc └── mq14.doc └── 系统级编程选择题.pdf /(完整word版)系统级编程总结.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/(完整word版)系统级编程总结.doc -------------------------------------------------------------------------------- /01-C++fundamentals/slp-lab01-cfundamentals-230824.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/01-C++fundamentals/slp-lab01-cfundamentals-230824.doc -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bin/Debug/dlab.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bin/Debug/dlab.exe -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bits.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bits.c -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bits.h: -------------------------------------------------------------------------------- 1 | 2 | int bitAnd(int, int); 3 | int test_bitAnd(int, int); 4 | 5 | 6 | 7 | 8 | 9 | 10 | int bitOr(int, int); 11 | int test_bitOr(int, int); 12 | 13 | 14 | 15 | 16 | 17 | 18 | int isZero(int); 19 | int test_isZero(int); 20 | 21 | 22 | 23 | 24 | 25 | 26 | int minusOne(); 27 | int test_minusOne(); 28 | 29 | 30 | 31 | 32 | 33 | 34 | int tmax(); 35 | int test_tmax(); 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | int bitXor(int, int); 44 | int test_bitXor(int, int); 45 | 46 | 47 | 48 | 49 | 50 | 51 | int getByte(int, int); 52 | int test_getByte(int, int); 53 | 54 | 55 | 56 | 57 | 58 | 59 | int isEqual(int, int); 60 | int test_isEqual(int, int); 61 | 62 | 63 | 64 | 65 | 66 | 67 | int negate(int); 68 | int test_negate(int); 69 | 70 | 71 | 72 | 73 | 74 | 75 | int isPositive(int); 76 | int test_isPositive(int); 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bits.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/bits.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/btest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CS:APP Data Lab 3 | */ 4 | 5 | /* 6 | * Students enter their personal names and login IDs in a struct of 7 | * this type in their bits.c file. 8 | */ 9 | typedef struct { 10 | char *name; 11 | char *id; 12 | } info_struct; 13 | 14 | /* Declare different function types */ 15 | typedef int (*funct_t) (void); 16 | typedef int (*funct1_t)(int); 17 | typedef int (*funct2_t)(int, int); 18 | typedef int (*funct3_t)(int, int, int); 19 | 20 | /* Combine all the information about a function and its tests as structure */ 21 | typedef struct { 22 | char *name; 23 | funct_t solution_funct; /* These will typically be casted */ 24 | funct_t test_funct; 25 | int args; 26 | char *ops; 27 | int op_limit; 28 | int rating; 29 | int arg_ranges[3][2]; /* Min & Max values for each argument */ 30 | } test_rec, *test_ptr; 31 | 32 | extern test_rec test_set[]; 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/decl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define TMin LONG_MIN 6 | #define TMax LONG_MAX 7 | 8 | #include "btest.h" 9 | #include "bits.h" 10 | 11 | test_rec test_set[] = { 12 | 13 | 14 | {"bitAnd", (funct_t) bitAnd, (funct_t) test_bitAnd, 2, "| ~", 8, 1, 15 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 16 | 17 | 18 | 19 | 20 | 21 | 22 | {"bitOr", (funct_t) bitOr, (funct_t) test_bitOr, 2, "& ~", 8, 1, 23 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 24 | 25 | 26 | 27 | 28 | 29 | 30 | {"isZero", (funct_t) isZero, (funct_t) test_isZero, 1, "! ~ & ^ | + << >>", 2, 1, 31 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 32 | 33 | 34 | 35 | 36 | 37 | 38 | {"minusOne", (funct_t) minusOne, (funct_t) test_minusOne, 0, 39 | "! ~ & ^ | + << >>", 2, 1, 40 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 41 | 42 | 43 | 44 | 45 | 46 | 47 | {"tmax", (funct_t) tmax, (funct_t) test_tmax, 0, "! ~ & ^ | + << >>", 4, 1, 48 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {"bitXor", (funct_t) bitXor, (funct_t) test_bitXor, 2, "& ~", 14, 2, 57 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 58 | 59 | 60 | 61 | 62 | 63 | 64 | {"getByte", (funct_t) getByte, (funct_t) test_getByte, 2, 65 | "! ~ & ^ | + << >>", 6, 2, 66 | {{TMin, TMax},{0,3},{TMin,TMax}}}, 67 | 68 | 69 | 70 | 71 | 72 | 73 | {"isEqual", (funct_t) isEqual, (funct_t) test_isEqual, 2, 74 | "! ~ & ^ | + << >>", 5, 2, 75 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 76 | 77 | 78 | 79 | 80 | 81 | 82 | {"negate", (funct_t) negate, (funct_t) test_negate, 1, 83 | "! ~ & ^ | + << >>", 5, 2, 84 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 85 | 86 | 87 | 88 | 89 | 90 | 91 | {"isPositive", (funct_t) isPositive, (funct_t) test_isPositive, 1, 92 | "! ~ & ^ | + << >>", 8, 3, 93 | {{TMin, TMax},{TMin,TMax},{TMin,TMax}}}, 94 | 95 | 96 | 97 | 98 | {"", NULL, NULL, 0, "", 0, 0, 99 | {{0, 0},{0,0},{0,0}}} 100 | }; 101 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/dlab.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 58 | 59 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/dlab.depend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/dlab.depend -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/dlab.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published by the 6 | Free Software Foundation; either version 2, or (at your option) any 7 | later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 | 18 | #ifndef _GETOPT_H 19 | #define _GETOPT_H 1 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* For communication from `getopt' to the caller. 26 | When `getopt' finds an option that takes an argument, 27 | the argument value is returned here. 28 | Also, when `ordering' is RETURN_IN_ORDER, 29 | each non-option ARGV-element is returned here. */ 30 | 31 | extern char *optarg; 32 | 33 | /* Index in ARGV of the next element to be scanned. 34 | This is used for communication to and from the caller 35 | and for communication between successive calls to `getopt'. 36 | 37 | On entry to `getopt', zero means this is the first call; initialize. 38 | 39 | When `getopt' returns EOF, this is the index of the first of the 40 | non-option elements that the caller should itself scan. 41 | 42 | Otherwise, `optind' communicates from one call to the next 43 | how much of ARGV has been scanned so far. */ 44 | 45 | extern int optind; 46 | 47 | /* Callers store zero here to inhibit the error message `getopt' prints 48 | for unrecognized options. */ 49 | 50 | extern int opterr; 51 | 52 | /* Set to an option character which was unrecognized. */ 53 | 54 | extern int optopt; 55 | 56 | /* Describe the long-named options requested by the application. 57 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 58 | of `struct option' terminated by an element containing a name which is 59 | zero. 60 | 61 | The field `has_arg' is: 62 | no_argument (or 0) if the option does not take an argument, 63 | required_argument (or 1) if the option requires an argument, 64 | optional_argument (or 2) if the option takes an optional argument. 65 | 66 | If the field `flag' is not NULL, it points to a variable that is set 67 | to the value given in the field `val' when the option is found, but 68 | left unchanged if the option is not found. 69 | 70 | To have a long-named option do something other than set an `int' to 71 | a compiled-in constant, such as set a value from `optarg', set the 72 | option's `flag' field to zero and its `val' field to a nonzero 73 | value (the equivalent single-letter option character, if there is 74 | one). For long options that have a zero `flag' field, `getopt' 75 | returns the contents of the `val' field. */ 76 | 77 | struct option 78 | { 79 | #if __STDC__ 80 | const char *name; 81 | #else 82 | char *name; 83 | #endif 84 | /* has_arg can't be an enum because some compilers complain about 85 | type mismatches in all the code that assumes it is an int. */ 86 | int has_arg; 87 | int *flag; 88 | int val; 89 | }; 90 | 91 | /* Names for the values of the `has_arg' field of `struct option'. */ 92 | 93 | #define no_argument 0 94 | #define required_argument 1 95 | #define optional_argument 2 96 | 97 | #if __STDC__ || defined(PROTO) 98 | #if defined(__GNU_LIBRARY__) 99 | /* Many other libraries have conflicting prototypes for getopt, with 100 | differences in the consts, in stdlib.h. To avoid compilation 101 | errors, only prototype getopt for the GNU C library. */ 102 | extern int getopt (int argc, char *const *argv, const char *shortopts); 103 | #endif /* not __GNU_LIBRARY__ */ 104 | extern int getopt_long (int argc, char *const *argv, const char *shortopts, 105 | const struct option *longopts, int *longind); 106 | extern int getopt_long_only (int argc, char *const *argv, 107 | const char *shortopts, 108 | const struct option *longopts, int *longind); 109 | 110 | /* Internal only. Users should not call this directly. */ 111 | extern int _getopt_internal (int argc, char *const *argv, 112 | const char *shortopts, 113 | const struct option *longopts, int *longind, 114 | int long_only); 115 | #else /* not __STDC__ */ 116 | extern int getopt (); 117 | extern int getopt_long (); 118 | extern int getopt_long_only (); 119 | 120 | extern int _getopt_internal (); 121 | #endif /* not __STDC__ */ 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* _GETOPT_H */ 128 | 129 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/bits.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/bits.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/btest.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/btest.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/decl.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/decl.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/getopt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/getopt.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/tests.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/obj/Debug/tests.o -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02-lab-dlab/slp-week02-lab-dlab/dlab/tests.c: -------------------------------------------------------------------------------- 1 | /* Testing Code */ 2 | 3 | #include 4 | 5 | 6 | 7 | 8 | int test_bitAnd(int x, int y) 9 | { 10 | return x&y; 11 | } 12 | 13 | 14 | 15 | 16 | 17 | 18 | int test_bitOr(int x, int y) 19 | { 20 | return x|y; 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | int test_isZero(int x) { 29 | return x == 0; 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | int test_minusOne(void) { 38 | return -1; 39 | } 40 | 41 | 42 | 43 | 44 | 45 | 46 | int test_tmax(void) { 47 | return LONG_MAX; 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | int test_bitXor(int x, int y) 57 | { 58 | return x^y; 59 | } 60 | 61 | 62 | 63 | 64 | 65 | 66 | int test_getByte(int x, int n) 67 | { 68 | union { 69 | int word; 70 | unsigned char bytes[4]; 71 | } u; 72 | int test = 1; 73 | int littleEndian = (int) *(char *) &test; 74 | u.word = x; 75 | return littleEndian ? (unsigned) u.bytes[n] : (unsigned) u.bytes[3-n]; 76 | } 77 | 78 | 79 | 80 | 81 | 82 | 83 | int test_isEqual(int x, int y) 84 | { 85 | return x == y; 86 | } 87 | 88 | 89 | 90 | 91 | 92 | 93 | int test_negate(int x) { 94 | return -x; 95 | } 96 | 97 | 98 | 99 | 100 | 101 | 102 | int test_isPositive(int x) { 103 | return x > 0; 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /02.1-Representation of Data/slp-week02.1-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.1-Representation of Data/slp-week02.1-homework.doc -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/Fixed-point arithmetic-lab.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/Fixed-point arithmetic-lab.pdf -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/bin/Debug/fp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/bin/Debug/fp.exe -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fixedpoint.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fixedpoint.cpp -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fixedpoint.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fixedpoint.h -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fp.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 44 | 45 | -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fp.depend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fp.depend -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/fp.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/obj/Debug/fixedpoint.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/obj/Debug/fixedpoint.o -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/obj/Debug/fixedpoint_test.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02-lab-fplab/slp-week02-lab-fplab/fp/fp/obj/Debug/fixedpoint_test.o -------------------------------------------------------------------------------- /02.2-Fixed-point Arithmetic/slp-week02.2-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/02.2-Fixed-point Arithmetic/slp-week02.2-homework.doc -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/AddSub.s: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE Irvine32.inc 3 | 4 | 5 | .section .rodata 6 | 7 | longIntFmt: 8 | .string "%ld" 9 | 10 | resultFmt: 11 | .string "Result is %ld\n" 12 | 13 | .section .text 14 | .globl addLongs 15 | addLongs: 16 | addq %rdi, %rsi 17 | movq %rsi, (%rdx) 18 | ret 19 | 20 | .globl main 21 | main: 22 | pushq %rbp 23 | subq $32, %rsp 24 | movq %rsp, %rbp 25 | 26 | movq $longIntFmt, %rdi 27 | leaq 0(%rbp), %rsi 28 | call scanf 29 | 30 | movq $longIntFmt, %rdi 31 | leaq 8(%rbp), %rsi 32 | call scanf 33 | 34 | movq 0(%rbp), %rdi 35 | movq 8(%rbp), %rsi 36 | leaq 16(%rbp), %rdx 37 | call addLongs 38 | movq $resultFmt, %rdi 39 | movq 16(%rbp), %rsi 40 | call printf 41 | addq $32, %rsp 42 | popq %rbp 43 | ret 44 | -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/bin/Debug/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/bin/Debug/demo.exe -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/demo.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 40 | 41 | -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/demo.depend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/demo.depend -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/demo.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/main.c: -------------------------------------------------------------------------------- 1 | //==================================================================== 2 | //程序1:一个空程序 3 | //==================================================================== 4 | 5 | #include 6 | 7 | 8 | //int main () 9 | //{ 10 | // printf("null\n"); 11 | // 12 | // return 0; 13 | //} 14 | 15 | 16 | 17 | 18 | //==================================================================== 19 | //程序2:一个只有赋值语句的程序 20 | //==================================================================== 21 | 22 | //#include 23 | // 24 | //int a; 25 | // 26 | //int main () 27 | //{ 28 | // 29 | // a=5; 30 | // 31 | // printf("null\n"); 32 | // 33 | // return 0; 34 | //} 35 | 36 | 37 | 38 | //==================================================================== 39 | //程序3:一个打印 a=5对应指令的程序:from SSD6.chm文件的1.5.1.1 40 | //==================================================================== 41 | 42 | //#include 43 | // 44 | //int a; 45 | //int main (int argc, char *argv[]) 46 | //{ 47 | // int i; 48 | // unsigned char * c; 49 | // 50 | // a = 5; 51 | // 52 | // //Notes by 教师:这个数值可能需要修改,according to你的运行情况 53 | // 54 | // //c = ((unsigned char *) 0x00401028); 55 | // c = ((unsigned char *)0x0040B768); 56 | // 57 | // for (i = 0; i < 10; i++) 58 | // { 59 | // printf("%02X ", *c); 60 | // c++; 61 | // } 62 | // 63 | // printf("\n"); 64 | // 65 | // return 0; 66 | //} 67 | 68 | 69 | 70 | //==================================================================== 71 | //程序4:一个带有算术运算的程序:from SSD6.chm文件的1.5.3.2 72 | //==================================================================== 73 | 74 | //#include 75 | // 76 | //int a; 77 | //int b = 4; 78 | //int c = 3; 79 | // 80 | //int main ( int argc, char * argv[]) 81 | //{ 82 | // 83 | // a = b + 3 * c; 84 | // 85 | // printf("\n"); 86 | // return 0; 87 | //} 88 | 89 | 90 | 91 | //==================================================================== 92 | //程序5:一个带有位运算的程序: 93 | //==================================================================== 94 | 95 | //#include 96 | // 97 | //int a =4; 98 | //int b =5; 99 | //int c =0; 100 | // 101 | //int main ( int argc, char * argv[]) 102 | //{ 103 | // 104 | // c = a&b; 105 | // 106 | // printf("\n"); 107 | // return 0; 108 | //} 109 | 110 | 111 | 112 | //==================================================================== 113 | //程序6:一个带有逻辑运算的程序: 114 | //==================================================================== 115 | 116 | #include 117 | 118 | 119 | int a =4; 120 | int b =5; 121 | int c =0; 122 | 123 | int main ( int argc, char * argv[]) 124 | { 125 | 126 | c = a&&b; 127 | 128 | printf("\n"); 129 | return 0; 130 | } 131 | 132 | 133 | //==================================================================== 134 | //程序7:一个if分支的程序 135 | //==================================================================== 136 | /* 137 | #include 138 | 139 | 140 | int a; 141 | 142 | int main ( int argc, char * argv[]) 143 | { 144 | 145 | a = 5; 146 | 147 | if (a>0) 148 | { 149 | printf("a>0 \n"); 150 | } 151 | 152 | return 0; 153 | } 154 | */ 155 | 156 | //==================================================================== 157 | //程序8:一个if分支的程序 158 | //==================================================================== 159 | /* 160 | #include 161 | 162 | 163 | int a; 164 | 165 | int main ( int argc, char * argv[]) 166 | { 167 | 168 | a = 5; 169 | 170 | if (a>3) 171 | { 172 | printf("a>3 \n"); 173 | } 174 | 175 | return 0; 176 | } 177 | */ 178 | 179 | 180 | //==================================================================== 181 | //程序9:一个if-else分支的程序 182 | //==================================================================== 183 | /* 184 | #include 185 | 186 | 187 | int a; 188 | 189 | int main ( int argc, char * argv[]) 190 | { 191 | 192 | a = 5; 193 | 194 | if (a>0) 195 | { 196 | printf("a>0 \n"); 197 | } 198 | else 199 | { 200 | printf("a<0 \n"); 201 | } 202 | 203 | return 0; 204 | } 205 | */ 206 | 207 | 208 | //==================================================================== 209 | //程序10:一个switch分支的程序 210 | //==================================================================== 211 | /* 212 | #include 213 | 214 | int a; 215 | 216 | int main ( int argc, char * argv[]) 217 | { 218 | 219 | a = 2; 220 | switch (a) 221 | { 222 | case 1: 223 | a=1; 224 | break; 225 | 226 | case 2: 227 | a=2; 228 | 229 | case 3: 230 | a=3; 231 | break; 232 | 233 | default: 234 | a=5; 235 | } 236 | 237 | return 0; 238 | } 239 | */ 240 | 241 | 242 | 243 | 244 | //==================================================================== 245 | //程序11:一个while循环的程序 246 | //==================================================================== 247 | /* 248 | #include 249 | 250 | int a; 251 | 252 | int main ( int argc, char * argv[]) 253 | { 254 | 255 | int b; 256 | a = 5; 257 | 258 | while(a>0) 259 | { 260 | b++; 261 | a--; 262 | } 263 | 264 | return 0; 265 | } 266 | */ 267 | 268 | //==================================================================== 269 | //程序12:一个do-while循环的程序 270 | //==================================================================== 271 | /* 272 | #include 273 | 274 | int a; 275 | 276 | int main ( int argc, char * argv[]) 277 | { 278 | 279 | int b; 280 | a = 5; 281 | 282 | do 283 | { 284 | b++; 285 | a--; 286 | }while(a>0); 287 | 288 | return 0; 289 | 290 | } 291 | */ 292 | 293 | 294 | 295 | //==================================================================== 296 | //程序13:一个for循环的程序 297 | //==================================================================== 298 | /* 299 | #include 300 | 301 | int a; 302 | int b; 303 | 304 | int main ( int argc, char * argv[]) 305 | { 306 | 307 | b=0; 308 | 309 | for(a=5;a>0;a--) 310 | { 311 | b++; 312 | } 313 | 314 | return 0; 315 | } 316 | */ 317 | -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/obj/Debug/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/1/demo/obj/Debug/main.o -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/FloppyWriter.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/FloppyWriter.exe -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/boot.asm: -------------------------------------------------------------------------------- 1 | org 07c00h ; 2 | mov ax, cs 3 | mov ds, ax 4 | mov es, ax 5 | call DispStr ; 6 | jmp $ ; 7 | 8 | DispStr: 9 | mov ax, BootMessage 10 | mov bp, ax ; 11 | mov cx, 16 ; 12 | mov ax, 01301h ; 13 | mov bx, 000ch ; 14 | mov dl, 0 15 | int 10h ; 16 | ret 17 | BootMessage: db "Hello, jiangjunyu2021141461016" 18 | times 510-($-$$) db 0 ; 19 | ; 20 | dw 0xaa55 -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/boot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/boot.bin -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/nasm-2.15.05-installer-x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/nasm-2.15.05-installer-x64.exe -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/nasm-2.15.05-installer-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/nasm-2.15.05-installer-x86.exe -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/slp-lab-BootLoader-e.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-assemblylab/slp-week03-assemblylab/2/slp-lab-BootLoader-e.pdf -------------------------------------------------------------------------------- /03-Representation of Code/slp-week03-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/03-Representation of Code/slp-week03-homework.doc -------------------------------------------------------------------------------- /04-Structured Data Repretation/slp-week04-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/04-Structured Data Repretation/slp-week04-homework.doc -------------------------------------------------------------------------------- /05-Decoding Lab/Decoding_Lab_Instruction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/05-Decoding Lab/Decoding_Lab_Instruction.pdf -------------------------------------------------------------------------------- /05-Decoding Lab/decode/bin/Debug/decode.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/05-Decoding Lab/decode/bin/Debug/decode.exe -------------------------------------------------------------------------------- /05-Decoding Lab/decode/decode.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 41 | 42 | -------------------------------------------------------------------------------- /05-Decoding Lab/decode/decode.depend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/05-Decoding Lab/decode/decode.depend -------------------------------------------------------------------------------- /05-Decoding Lab/decode/decode.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /05-Decoding Lab/decode/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //可参考https://www.bilibili.com/video/BV1914y1A7RM/?spm_id_from=333.880.my_history.page.click 6 | 7 | int prologue [] = { 8 | 0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F, 9 | 0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69, 10 | 0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72, 11 | 0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72, 12 | 0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966, 13 | 0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F, 14 | 0x20206F74, 0x74786565, 0x65617276, 0x32727463, 15 | 0x594E2020, 0x206F776F, 0x79727574, 0x4563200A 16 | }; 17 | 18 | int data [] = { 19 | 0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72, 20 | 0x466D203A, 0x65693A72, 0x43646E20, 0x6F54540A, 21 | 0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F, 22 | 0x594E2020, 0x206F776F, 0x79727574, 0x4563200A, 23 | 0x6F786F68, 0x6E696373, 0x6C206765, 0x796C656B, 24 | 0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966, 25 | 0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F, 26 | 0x20206F74, 0x74786565, 0x65617276, 0x32727463, 27 | 0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69, 28 | 0x21687467, 0x63002065, 0x6C6C7861, 0x78742078, 29 | 0x6578206F, 0x72747878, 0x78636178, 0x00783174 30 | }; 31 | 32 | int epilogue [] = { 33 | 0x594E2020, 0x206F776F, 0x79727574, 0x4563200A, 34 | 0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69, 35 | 0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F, 36 | 0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966, 37 | 0x20206F74, 0x74786565, 0x65617276, 0x32727463 38 | }; 39 | 40 | char message[100]; 41 | 42 | void usage_and_exit(char * program_name) { 43 | fprintf(stderr, "USAGE: %s key1 key2 key3 key4\n", program_name); 44 | exit(1); 45 | } 46 | 47 | void process_keys12 (int * key1, int * key2) { 48 | 49 | *((int *) (key1 + *key1)) = *key2; 50 | } 51 | 52 | void process_keys34 (int * key3, int * key4) { 53 | *(((int64_t *)&key3) + *key3) += *key4;//若此处为*(((int *)&key3) + *key3) += *key4;则采用x86来编译 54 | } 55 | 56 | char * extract_message1(int start, int stride) { 57 | int i, j, k; 58 | int done = 0; 59 | 60 | for (i = 0, j = start + 1; ! done; j++) { 61 | for (k = 1; k < stride; k++, j++, i++) { 62 | 63 | if (*(((char *) data) + j) == '\0') { 64 | done = 1; 65 | break; 66 | } 67 | 68 | message[i] = *(((char *) data) + j); 69 | } 70 | } 71 | message[i] = '\0'; 72 | return message; 73 | } 74 | 75 | 76 | char * extract_message2(int start, int stride) { 77 | int i, j; 78 | 79 | for (i = 0, j = start; 80 | *(((char *) data) + j) != '\0'; 81 | i++, j += stride) 82 | { 83 | message[i] = *(((char *) data) + j); 84 | } 85 | message[i] = '\0'; 86 | return message; 87 | } 88 | 89 | int main (int argc, char *argv[]) 90 | { 91 | int dummy = 1; 92 | int start, stride; 93 | int key1, key2, key3, key4; 94 | char * msg1, * msg2; 95 | 96 | key3 = key4 = 0; 97 | if (argc < 3) { 98 | usage_and_exit(argv[0]); 99 | } 100 | key1 = strtol(argv[1], NULL, 0); 101 | key2 = strtol(argv[2], NULL, 0); 102 | if (argc > 3) key3 = strtol(argv[3], NULL, 0); 103 | if (argc > 4) key4 = strtol(argv[4], NULL, 0); 104 | 105 | process_keys12(&key1, &key2); 106 | 107 | start = (int)(*(((char *) &dummy))); 108 | stride = (int)(*(((char *) &dummy) + 1)); 109 | 110 | if (key3 != 0 && key4 != 0) { 111 | process_keys34(&key3, &key4); 112 | } 113 | 114 | msg1 = extract_message1(start, stride); 115 | 116 | if (*msg1 == '\0') { 117 | process_keys34(&key3, &key4); 118 | msg2 = extract_message2(start, stride); 119 | printf("%s\n", msg2); 120 | } 121 | else { 122 | printf("%s\n", msg1); 123 | } 124 | 125 | return 0; 126 | } 127 | -------------------------------------------------------------------------------- /05-Decoding Lab/decode/obj/Debug/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/05-Decoding Lab/decode/obj/Debug/main.o -------------------------------------------------------------------------------- /05-Decoding Lab/slp-week05-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/05-Decoding Lab/slp-week05-homework.doc -------------------------------------------------------------------------------- /06-Buffer Overflow Attack/bufoverflow.c: -------------------------------------------------------------------------------- 1 | // bufoverflow.c 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /* Like gets, except that characters are typed as pairs of hex digits. 8 | Nondigit characters are ignored. Stops when encounters newline */ 9 | char *getxs(char *dest) 10 | { 11 | int c; 12 | int even = 1; /* Have read even number of digits */ 13 | int otherd = 0; /* Other hex digit of pair */ 14 | char *sp = dest; 15 | while ((c = getchar()) != EOF && c != '\n') { 16 | if (isxdigit(c)) { 17 | int val; 18 | if ('0' <= c && c <= '9') 19 | val = c - '0'; 20 | else if ('A' <= c && c <= 'F') 21 | val = c - 'A' + 10; 22 | else 23 | val = c - 'a' + 10; 24 | if (even) { 25 | otherd = val; 26 | even = 0; 27 | } else { 28 | *sp++ = otherd * 16 + val; 29 | even = 1; 30 | } 31 | } 32 | } 33 | *sp++ = '\0'; 34 | return dest; 35 | } 36 | 37 | int getbuf() 38 | { 39 | char buf[32]; 40 | getxs(buf); 41 | return 1; 42 | } 43 | 44 | void test() 45 | { 46 | int val; 47 | printf("Type Hex string:"); 48 | val = getbuf(); 49 | printf("getbuf returned 0x%x\n", val); 50 | } 51 | 52 | int main() 53 | { 54 | int buf[32]; 55 | /* This little hack is an attempt to get the stack to be in a 56 | stable position 57 | */ 58 | int offset = (((int) buf) & 0xFFF); 59 | int *space = (int *) malloc(offset); 60 | *space = 0; /* So that don't get complaint of unused variable */ 61 | test(); 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /06-Buffer Overflow Attack/slp-week06-bufferoverflowlab/main.c: -------------------------------------------------------------------------------- 1 | // bufoverflow.c 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /* Like gets, except that characters are typed as pairs of hex digits. 8 | Nondigit characters are ignored. Stops when encounters newline */ 9 | char *getxs(char *dest) 10 | { 11 | int c; 12 | int even = 1; /* Have read even number of digits */ 13 | int otherd = 0; /* Other hex digit of pair */ 14 | char *sp = dest; 15 | while ((c = getchar()) != EOF && c != '\n') { 16 | if (isxdigit(c)) { 17 | int val; 18 | if ('0' <= c && c <= '9') 19 | val = c - '0'; 20 | else if ('A' <= c && c <= 'F') 21 | val = c - 'A' + 10; 22 | else 23 | val = c - 'a' + 10; 24 | if (even) { 25 | otherd = val; 26 | even = 0; 27 | } else { 28 | *sp++ = otherd * 16 + val; 29 | even = 1; 30 | } 31 | } 32 | } 33 | *sp++ = '\0'; 34 | return dest; 35 | } 36 | 37 | int getbuf() 38 | { 39 | char buf[32]; 40 | getxs(buf); 41 | return 1; 42 | } 43 | 44 | void test() 45 | { 46 | int val; 47 | printf("Type Hex string:"); 48 | val = getbuf(); 49 | printf("getbuf returned 0x%x\n", val); 50 | } 51 | 52 | int main() 53 | { 54 | int buf[32]; 55 | /* This little hack is an attempt to get the stack to be in a 56 | stable position 57 | */ 58 | int offset = (((int) buf) & 0xFFF); 59 | int *space = (int *) malloc(offset); 60 | *space = 0; /* So that don't get complaint of unused variable */ 61 | test(); 62 | 63 | 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /06-Buffer Overflow Attack/slp-week06-bufferoverflowlab/slp-week06-homework.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/06-Buffer Overflow Attack/slp-week06-bufferoverflowlab/slp-week06-homework.pdf -------------------------------------------------------------------------------- /06-Buffer Overflow Attack/slp-week06-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/06-Buffer Overflow Attack/slp-week06-homework.doc -------------------------------------------------------------------------------- /07-Debugging Malloc/DebuggingMallocLab-Instruction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/DebuggingMallocLab-Instruction.pdf -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/bin/Debug/malloclab.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/bin/Debug/malloclab.exe -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/debugmalloc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/debugmalloc.c -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/debugmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUGMALLOC_H 2 | #define DEBUGMALLOC_H 3 | 4 | #include 5 | 6 | /* Macros that will call the wrapper functions with 7 | the current filename and line number */ 8 | 9 | #define MALLOC(s) MyMalloc(s, __FILE__, __LINE__) 10 | #define FREE(p) MyFree(p, __FILE__, __LINE__) 11 | 12 | /* Wrappers for malloc and free. You will implement 13 | these functions. */ 14 | 15 | void *MyMalloc(size_t size, char *filename, int linenumber); 16 | void MyFree(void *ptr, char *filename, int linenumber); 17 | 18 | 19 | /* Required function for detecting memory leaks */ 20 | 21 | int AllocatedSize(); /* returns number of bytes allocated */ 22 | 23 | 24 | /* Optional functions if you wish to implement the global list */ 25 | 26 | void PrintAllocatedBlocks(); 27 | int HeapCheck(); /* returns 0 if all blocks have not been corrupted, 28 | -1 if an error is detected */ 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/dmhelper.c: -------------------------------------------------------------------------------- 1 | #include "dmhelper.h" 2 | #include 3 | #include 4 | 5 | /* returns 1 if c is in str, 0 if not */ 6 | int checkString(char *str, char c) { 7 | while (*str++) { 8 | if (*str == c) { 9 | return 1; 10 | } 11 | } 12 | return 0; 13 | } 14 | 15 | char *getMsg(int error) { 16 | switch(error) { 17 | case 1: 18 | return "Starting edge of the payload has been overwritten."; 19 | case 2: 20 | return "Ending edge of the payload has been overwritten."; 21 | case 3: 22 | return "Header has been corrupted."; 23 | case 4: 24 | return "Attempting to free an unallocated block."; 25 | } 26 | return ""; 27 | } 28 | 29 | /* Prints out an error message in a readable format, given 30 | the message, filename and line number. 31 | First checks to make sure '\n' does not exist in 32 | msg and filename. 33 | Returns 0 on success, -1 on failure. */ 34 | int error(int errorCode, char *filename, int linenumber) { 35 | char *msg = getMsg(errorCode); 36 | if (checkString(filename, '\n')) { 37 | printf("Invalid filename\n"); 38 | return -1; 39 | } 40 | printf("Error: %s\n\tin block freed at %s, line %d\n", msg, filename, linenumber); 41 | exit(-1); 42 | } 43 | 44 | 45 | 46 | int errorfl(int errorCode, char *filename_malloc, int linenumber_malloc, char *filename_free, int linenumber_free) { 47 | char *msg = getMsg(errorCode); 48 | if (checkString(filename_malloc, '\n')) { 49 | printf("Invalid \"malloc\" filename\n"); 50 | return -1; 51 | } 52 | if (checkString(filename_free, '\n')) { 53 | printf("Invalid \"free\" filename\n"); 54 | return -1; 55 | } 56 | printf("Error: %s\n\tin block allocated at %s, line %d\n", msg, filename_malloc, linenumber_malloc); 57 | printf("\tand freed at %s, line %d\n", filename_free, linenumber_free); 58 | exit(-1); 59 | } 60 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/dmhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef DMHELPER_H 2 | #define DMHELPER_H 3 | 4 | /* Prints out an error message in a readable format, given 5 | the message, filename and line number, then exits. 6 | First checks to make sure '\n' does not exist in 7 | msg and filename. 8 | Returns 0 on success, -1 on failure. */ 9 | int error(int errorCode, char *filename, int linenumber); 10 | 11 | /* Prints out an error message in a readable format, given 12 | the message, filename and line number, then exits. 13 | First checks to make sure '\n' does not exist in 14 | msg and filename. 15 | Returns 0 on success, -1 on failure. */ 16 | int errorfl(int errorCode, char *filename_malloc, int linenumber_malloc, char *filename_free, int linenumber_free); 17 | 18 | char *getMsg(int error); 19 | #define PRINTBLOCK(s, f, l) printf("\t%d bytes, created at %s, line %d\n", s, f, l) 20 | #define PRINTERROR(e, f, l) printf("Error: %s\n\tInvalid block created at %s, line %d\n", getMsg(e), f, l); 21 | 22 | 23 | #endif -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/driver.c: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "getopt.h" 8 | #include "debugmalloc.h" 9 | 10 | #define NUMTESTCASES 8 11 | 12 | static void run_test_case(int n) { 13 | switch(n) { 14 | case 1: { /* no error, just a basic test */ 15 | char *str = (char *) MALLOC(12); 16 | strcpy(str, "123456789"); 17 | FREE(str); 18 | printf("Size: %d\n", AllocatedSize()); 19 | PrintAllocatedBlocks(); 20 | } 21 | break; 22 | case 2: { /* should overflow by 1 */ 23 | char *str = (char *) MALLOC(8); 24 | strcpy(str, "12345678"); 25 | FREE(str); 26 | } 27 | break; 28 | case 3: { /* should overflow by 1, harder to catch 29 | because of alignment */ 30 | char *str = (char *) MALLOC(2); 31 | strcpy(str, "12"); 32 | FREE(str); 33 | } 34 | break; 35 | case 4: { /* memory leak */ 36 | void *ptr = MALLOC(4), *ptr2 = MALLOC(6); 37 | FREE(ptr); 38 | printf("Size: %d\n", AllocatedSize()); 39 | PrintAllocatedBlocks(); 40 | } 41 | break; 42 | case 5: { 43 | void *ptr = MALLOC(4); 44 | FREE(ptr); 45 | FREE(ptr); 46 | } 47 | break; 48 | case 6: { 49 | char *ptr = (char *) MALLOC(4); 50 | *((int *) (ptr - 8)) = 8 + (1 << 31); 51 | FREE(ptr); 52 | } 53 | break; 54 | case 7: { 55 | char ptr[5]; 56 | FREE(ptr); 57 | } 58 | break; 59 | case 8: { 60 | int i; 61 | int *intptr = (int *) MALLOC(6); 62 | char *str = (char *) MALLOC(12); 63 | 64 | for(i = 0; i < 6; i++) { 65 | intptr[i] = i; 66 | } 67 | if (HeapCheck() == -1) { 68 | printf("\nCaught Errors\n"); 69 | } 70 | } 71 | default: 72 | ; 73 | } 74 | } 75 | 76 | static void usage(char *cmd) { 77 | printf("Usage: %s [-h] [-t ]\n", cmd); 78 | printf(" -h Prints this message\n"); 79 | printf(" -t Runs n-th test\n"); 80 | exit(1); 81 | } 82 | 83 | 84 | int main(int argc, char *argv[]) { 85 | char c; 86 | int tracenum = 0; 87 | 88 | while ((c = getopt(argc, argv, "ht:")) != -1) { 89 | switch (c) { 90 | case 'h': 91 | usage(argv[0]); 92 | break; 93 | case 't': 94 | if ((tracenum = atoi(optarg)) > NUMTESTCASES || tracenum <= 0) { 95 | usage(argv[0]); 96 | } 97 | break; 98 | default: 99 | usage(argv[0]); 100 | } 101 | } 102 | 103 | if (tracenum) { 104 | run_test_case(tracenum); 105 | } 106 | else { 107 | usage(argv[0]); 108 | } 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published by the 6 | Free Software Foundation; either version 2, or (at your option) any 7 | later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 | 18 | #ifndef _GETOPT_H 19 | #define _GETOPT_H 1 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* For communication from `getopt' to the caller. 26 | When `getopt' finds an option that takes an argument, 27 | the argument value is returned here. 28 | Also, when `ordering' is RETURN_IN_ORDER, 29 | each non-option ARGV-element is returned here. */ 30 | 31 | extern char *optarg; 32 | 33 | /* Index in ARGV of the next element to be scanned. 34 | This is used for communication to and from the caller 35 | and for communication between successive calls to `getopt'. 36 | 37 | On entry to `getopt', zero means this is the first call; initialize. 38 | 39 | When `getopt' returns EOF, this is the index of the first of the 40 | non-option elements that the caller should itself scan. 41 | 42 | Otherwise, `optind' communicates from one call to the next 43 | how much of ARGV has been scanned so far. */ 44 | 45 | extern int optind; 46 | 47 | /* Callers store zero here to inhibit the error message `getopt' prints 48 | for unrecognized options. */ 49 | 50 | extern int opterr; 51 | 52 | /* Set to an option character which was unrecognized. */ 53 | 54 | extern int optopt; 55 | 56 | /* Describe the long-named options requested by the application. 57 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 58 | of `struct option' terminated by an element containing a name which is 59 | zero. 60 | 61 | The field `has_arg' is: 62 | no_argument (or 0) if the option does not take an argument, 63 | required_argument (or 1) if the option requires an argument, 64 | optional_argument (or 2) if the option takes an optional argument. 65 | 66 | If the field `flag' is not NULL, it points to a variable that is set 67 | to the value given in the field `val' when the option is found, but 68 | left unchanged if the option is not found. 69 | 70 | To have a long-named option do something other than set an `int' to 71 | a compiled-in constant, such as set a value from `optarg', set the 72 | option's `flag' field to zero and its `val' field to a nonzero 73 | value (the equivalent single-letter option character, if there is 74 | one). For long options that have a zero `flag' field, `getopt' 75 | returns the contents of the `val' field. */ 76 | 77 | struct option 78 | { 79 | #if __STDC__ 80 | const char *name; 81 | #else 82 | char *name; 83 | #endif 84 | /* has_arg can't be an enum because some compilers complain about 85 | type mismatches in all the code that assumes it is an int. */ 86 | int has_arg; 87 | int *flag; 88 | int val; 89 | }; 90 | 91 | /* Names for the values of the `has_arg' field of `struct option'. */ 92 | 93 | #define no_argument 0 94 | #define required_argument 1 95 | #define optional_argument 2 96 | 97 | #if __STDC__ || defined(PROTO) 98 | #if defined(__GNU_LIBRARY__) 99 | /* Many other libraries have conflicting prototypes for getopt, with 100 | differences in the consts, in stdlib.h. To avoid compilation 101 | errors, only prototype getopt for the GNU C library. */ 102 | extern int getopt (int argc, char *const *argv, const char *shortopts); 103 | #endif /* not __GNU_LIBRARY__ */ 104 | extern int getopt_long (int argc, char *const *argv, const char *shortopts, 105 | const struct option *longopts, int *longind); 106 | extern int getopt_long_only (int argc, char *const *argv, 107 | const char *shortopts, 108 | const struct option *longopts, int *longind); 109 | 110 | /* Internal only. Users should not call this directly. */ 111 | extern int _getopt_internal (int argc, char *const *argv, 112 | const char *shortopts, 113 | const struct option *longopts, int *longind, 114 | int long_only); 115 | #else /* not __STDC__ */ 116 | extern int getopt (); 117 | extern int getopt_long (); 118 | extern int getopt_long_only (); 119 | 120 | extern int _getopt_internal (); 121 | #endif /* not __STDC__ */ 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* _GETOPT_H */ 128 | 129 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/malloclab.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 41 | 42 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/malloclab.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1028826732 source:d:\myteaching\2022f-slp\week07\malloclab\debugmalloc.c 3 | 4 | 5 | "debugmalloc.h" 6 | "dmhelper.h" 7 | 8 | 9 | 1028826860 d:\myteaching\2022f-slp\week07\malloclab\debugmalloc.h 10 | 11 | 12 | 1028722654 d:\myteaching\2022f-slp\week07\malloclab\dmhelper.h 13 | 14 | 1028722658 source:d:\myteaching\2022f-slp\week07\malloclab\dmhelper.c 15 | "dmhelper.h" 16 | 17 | 18 | 19 | 1028886494 source:d:\myteaching\2022f-slp\week07\malloclab\driver.c 20 | 21 | 22 | 23 | 24 | "getopt.h" 25 | "debugmalloc.h" 26 | 27 | 1027396680 d:\myteaching\2022f-slp\week07\malloclab\getopt.h 28 | 29 | -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/obj/Debug/debugmalloc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/obj/Debug/debugmalloc.o -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/obj/Debug/dmhelper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/obj/Debug/dmhelper.o -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/obj/Debug/driver.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/obj/Debug/driver.o -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/obj/Debug/getopt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/malloclab/obj/Debug/getopt.o -------------------------------------------------------------------------------- /07-Debugging Malloc/malloclab/tailor.h: -------------------------------------------------------------------------------- 1 | /* tailor.h -- target dependent definitions 2 | * Copyright (C) 1992-1993 Jean-loup Gailly. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the GNU General Public License, see the file COPYING. 5 | */ 6 | 7 | /* The target dependent definitions should be defined here only. 8 | * The target dependent functions should be defined in tailor.c. 9 | */ 10 | 11 | /* $Id: tailor.h,v 0.18 1993/06/14 19:32:20 jloup Exp $ */ 12 | 13 | #if defined(__MSDOS__) && !defined(MSDOS) 14 | # define MSDOS 15 | #endif 16 | 17 | #if defined(__OS2__) && !defined(OS2) 18 | # define OS2 19 | #endif 20 | 21 | #if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */ 22 | # undef MSDOS 23 | #endif 24 | 25 | #ifdef MSDOS 26 | # ifdef __GNUC__ 27 | /* DJGPP version 1.09+ on MS-DOS. 28 | * The DJGPP 1.09 stat() function must be upgraded before gzip will 29 | * fully work. 30 | * No need for DIRENT, since defines POSIX_SOURCE which 31 | * implies DIRENT. 32 | */ 33 | # define near 34 | # else 35 | # define MAXSEG_64K 36 | # ifdef __TURBOC__ 37 | # define NO_OFF_T 38 | # ifdef __BORLANDC__ 39 | # define DIRENT 40 | # else 41 | # define NO_UTIME 42 | # endif 43 | # else /* MSC */ 44 | # define HAVE_SYS_UTIME_H 45 | # define NO_UTIME_H 46 | # endif 47 | # endif 48 | # define PATH_SEP2 '\\' 49 | # define PATH_SEP3 ':' 50 | # define MAX_PATH_LEN 128 51 | # define NO_MULTIPLE_DOTS 52 | # define MAX_EXT_CHARS 3 53 | # define Z_SUFFIX "z" 54 | # define NO_CHOWN 55 | # define PROTO 56 | # define STDC_HEADERS 57 | # define NO_SIZE_CHECK 58 | # define casemap(c) tolow(c) /* Force file names to lower case */ 59 | # include 60 | # define OS_CODE 0x00 61 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 62 | # if !defined(NO_ASM) && !defined(ASMV) 63 | # define ASMV 64 | # endif 65 | #else 66 | # define near 67 | #endif 68 | 69 | #ifdef OS2 70 | # define PATH_SEP2 '\\' 71 | # define PATH_SEP3 ':' 72 | # define MAX_PATH_LEN 260 73 | # ifdef OS2FAT 74 | # define NO_MULTIPLE_DOTS 75 | # define MAX_EXT_CHARS 3 76 | # define Z_SUFFIX "z" 77 | # define casemap(c) tolow(c) 78 | # endif 79 | # define NO_CHOWN 80 | # define PROTO 81 | # define STDC_HEADERS 82 | # include 83 | # define OS_CODE 0x06 84 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 85 | # ifdef _MSC_VER 86 | # define HAVE_SYS_UTIME_H 87 | # define NO_UTIME_H 88 | # define MAXSEG_64K 89 | # undef near 90 | # define near _near 91 | # endif 92 | # ifdef __EMX__ 93 | # define HAVE_SYS_UTIME_H 94 | # define NO_UTIME_H 95 | # define DIRENT 96 | # define EXPAND(argc,argv) \ 97 | {_response(&argc, &argv); _wildcard(&argc, &argv);} 98 | # endif 99 | # ifdef __BORLANDC__ 100 | # define DIRENT 101 | # endif 102 | # ifdef __ZTC__ 103 | # define NO_DIR 104 | # define NO_UTIME_H 105 | # include 106 | # define EXPAND(argc,argv) \ 107 | {response_expand(&argc, &argv);} 108 | # endif 109 | #endif 110 | 111 | #ifdef WIN32 /* Windows NT */ 112 | # define HAVE_SYS_UTIME_H 113 | # define NO_UTIME_H 114 | # define PATH_SEP2 '\\' 115 | # define PATH_SEP3 ':' 116 | # define MAX_PATH_LEN 260 117 | # define NO_CHOWN 118 | # define PROTO 119 | # define STDC_HEADERS 120 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 121 | # include 122 | # include 123 | # ifdef NTFAT 124 | # define NO_MULTIPLE_DOTS 125 | # define MAX_EXT_CHARS 3 126 | # define Z_SUFFIX "z" 127 | # define casemap(c) tolow(c) /* Force file names to lower case */ 128 | # endif 129 | # define OS_CODE 0x0b 130 | #endif 131 | 132 | #ifdef MSDOS 133 | # ifdef __TURBOC__ 134 | # include 135 | # define DYN_ALLOC 136 | /* Turbo C 2.0 does not accept static allocations of large arrays */ 137 | void * fcalloc (unsigned items, unsigned size); 138 | void fcfree (void *ptr); 139 | # else /* MSC */ 140 | # include 141 | # define fcalloc(nitems,itemsize) halloc((long)(nitems),(itemsize)) 142 | # define fcfree(ptr) hfree(ptr) 143 | # endif 144 | #else 145 | # ifdef MAXSEG_64K 146 | # define fcalloc(items,size) calloc((items),(size)) 147 | # else 148 | # define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size)) 149 | # endif 150 | # define fcfree(ptr) free(ptr) 151 | #endif 152 | 153 | #if defined(VAXC) || defined(VMS) 154 | # define PATH_SEP ']' 155 | # define PATH_SEP2 ':' 156 | # define SUFFIX_SEP ';' 157 | # define NO_MULTIPLE_DOTS 158 | # define Z_SUFFIX "-gz" 159 | # define RECORD_IO 1 160 | # define casemap(c) tolow(c) 161 | # define OS_CODE 0x02 162 | # define OPTIONS_VAR "GZIP_OPT" 163 | # define STDC_HEADERS 164 | # define NO_UTIME 165 | # define EXPAND(argc,argv) vms_expand_args(&argc,&argv); 166 | # include 167 | # define unlink delete 168 | # ifdef VAXC 169 | # define NO_FCNTL_H 170 | # include 171 | # endif 172 | #endif 173 | 174 | #ifdef AMIGA 175 | # define PATH_SEP2 ':' 176 | # define STDC_HEADERS 177 | # define OS_CODE 0x01 178 | # define ASMV 179 | # ifdef __GNUC__ 180 | # define DIRENT 181 | # define HAVE_UNISTD_H 182 | # else /* SASC */ 183 | # define NO_STDIN_FSTAT 184 | # define SYSDIR 185 | # define NO_SYMLINK 186 | # define NO_CHOWN 187 | # define NO_FCNTL_H 188 | # include /* for read() and write() */ 189 | # define direct dirent 190 | extern void _expand_args(int *argc, char ***argv); 191 | # define EXPAND(argc,argv) _expand_args(&argc,&argv); 192 | # undef O_BINARY /* disable useless --ascii option */ 193 | # endif 194 | #endif 195 | 196 | #if defined(ATARI) || defined(atarist) 197 | # ifndef STDC_HEADERS 198 | # define STDC_HEADERS 199 | # define HAVE_UNISTD_H 200 | # define DIRENT 201 | # endif 202 | # define ASMV 203 | # define OS_CODE 0x05 204 | # ifdef TOSFS 205 | # define PATH_SEP2 '\\' 206 | # define PATH_SEP3 ':' 207 | # define MAX_PATH_LEN 128 208 | # define NO_MULTIPLE_DOTS 209 | # define MAX_EXT_CHARS 3 210 | # define Z_SUFFIX "z" 211 | # define NO_CHOWN 212 | # define casemap(c) tolow(c) /* Force file names to lower case */ 213 | # define NO_SYMLINK 214 | # endif 215 | #endif 216 | 217 | #ifdef MACOS 218 | # define PATH_SEP ':' 219 | # define DYN_ALLOC 220 | # define PROTO 221 | # define NO_STDIN_FSTAT 222 | # define NO_CHOWN 223 | # define NO_UTIME 224 | # define chmod(file, mode) (0) 225 | # define OPEN(name, flags, mode) open(name, flags) 226 | # define OS_CODE 0x07 227 | # ifdef MPW 228 | # define isatty(fd) ((fd) <= 2) 229 | # endif 230 | #endif 231 | 232 | #ifdef __50SERIES /* Prime/PRIMOS */ 233 | # define PATH_SEP '>' 234 | # define STDC_HEADERS 235 | # define NO_MEMORY_H 236 | # define NO_UTIME_H 237 | # define NO_UTIME 238 | # define NO_CHOWN 239 | # define NO_STDIN_FSTAT 240 | # define NO_SIZE_CHECK 241 | # define NO_SYMLINK 242 | # define RECORD_IO 1 243 | # define casemap(c) tolow(c) /* Force file names to lower case */ 244 | # define put_char(c) put_byte((c) & 0x7F) 245 | # define get_char(c) ascii2pascii(get_byte()) 246 | # define OS_CODE 0x0F /* temporary, subject to change */ 247 | # ifdef SIGTERM 248 | # undef SIGTERM /* We don't want a signal handler for SIGTERM */ 249 | # endif 250 | #endif 251 | 252 | #if defined(pyr) && !defined(NOMEMCPY) /* Pyramid */ 253 | # define NOMEMCPY /* problem with overlapping copies */ 254 | #endif 255 | 256 | #ifdef TOPS20 257 | # define OS_CODE 0x0a 258 | #endif 259 | 260 | #ifndef unix 261 | # define NO_ST_INO /* don't rely on inode numbers */ 262 | #endif 263 | 264 | 265 | /* Common defaults */ 266 | 267 | #ifndef OS_CODE 268 | # define OS_CODE 0x03 /* assume Unix */ 269 | #endif 270 | 271 | #ifndef PATH_SEP 272 | # define PATH_SEP '/' 273 | #endif 274 | 275 | #ifndef casemap 276 | # define casemap(c) (c) 277 | #endif 278 | 279 | #ifndef OPTIONS_VAR 280 | # define OPTIONS_VAR "GZIP" 281 | #endif 282 | 283 | #ifndef Z_SUFFIX 284 | # define Z_SUFFIX ".gz" 285 | #endif 286 | 287 | #ifdef MAX_EXT_CHARS 288 | # define MAX_SUFFIX MAX_EXT_CHARS 289 | #else 290 | # define MAX_SUFFIX 30 291 | #endif 292 | 293 | #ifndef MAKE_LEGAL_NAME 294 | # ifdef NO_MULTIPLE_DOTS 295 | # define MAKE_LEGAL_NAME(name) make_simple_name(name) 296 | # else 297 | # define MAKE_LEGAL_NAME(name) 298 | # endif 299 | #endif 300 | 301 | #ifndef MIN_PART 302 | # define MIN_PART 3 303 | /* keep at least MIN_PART chars between dots in a file name. */ 304 | #endif 305 | 306 | #ifndef EXPAND 307 | # define EXPAND(argc,argv) 308 | #endif 309 | 310 | #ifndef RECORD_IO 311 | # define RECORD_IO 0 312 | #endif 313 | 314 | #ifndef SET_BINARY_MODE 315 | # define SET_BINARY_MODE(fd) 316 | #endif 317 | 318 | #ifndef OPEN 319 | # define OPEN(name, flags, mode) open(name, flags, mode) 320 | #endif 321 | 322 | #ifndef get_char 323 | # define get_char() get_byte() 324 | #endif 325 | 326 | #ifndef put_char 327 | # define put_char(c) put_byte(c) 328 | #endif 329 | 330 | -------------------------------------------------------------------------------- /07-Debugging Malloc/slp-week07-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/07-Debugging Malloc/slp-week07-homework.doc -------------------------------------------------------------------------------- /08.1Memory Debug/slp-week08.1-memory debug.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/08.1Memory Debug/slp-week08.1-memory debug.doc -------------------------------------------------------------------------------- /08.2-Binary Bomb/slp-week08.2-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/08.2-Binary Bomb/slp-week08.2-homework.doc -------------------------------------------------------------------------------- /08.2-Binary Bomb/slp-week08.2-lab/slp-week08-lab/code/bomb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | FILE *infile; 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | char *input; 8 | 9 | /* Note to self: remember to port this bomb to Windows and put a 10 | * fantastic GUI on it. */ 11 | 12 | /* When run with no arguments, the bomb reads its input lines 13 | * from standard input. */ 14 | if (argc == 1) { 15 | infile = stdin; 16 | } 17 | 18 | /* When run with one argument , the bomb reads from 19 | * until EOF, and then switches to standard input. Thus, as you 20 | * defuse each phase, you can add its defusing string to and 21 | * avoid having to retype it. */ 22 | else if (argc == 2) { 23 | if (!(infile = fopen(argv[1], "r"))) { 24 | printf("%s: Error: Couldn't open %s\n", argv[0], argv[1]); 25 | exit(8); 26 | } 27 | } 28 | 29 | /* You can't call the bomb with more than 1 command line argument. */ 30 | else { 31 | printf("Usage: %s []\n", argv[0]); 32 | exit(8); 33 | } 34 | 35 | /* Do all sorts of secret stuff that makes the bomb harder to defuse. */ 36 | initialize_bomb(); 37 | 38 | printf("Welcome to my fiendish little bomb. You have 6 phases with\n"); 39 | printf("which to blow yourself up. Have a nice day!\n"); 40 | 41 | /* Hmm... Six phases must be more secure than one phase! */ 42 | input = read_line(); /* Get input */ 43 | phase_1(input); /* Run the phase */ 44 | phase_defused(); /* Drat! They figured it out! 45 | * Let me know how they did it. */ 46 | printf("Phase 1 defused. How about the next one?\n"); 47 | 48 | /* The second phase is harder. No one will ever figure out 49 | * how to defuse this... */ 50 | input = read_line(); 51 | phase_2(input); 52 | phase_defused(); 53 | printf("That's number 2. Keep going!\n"); 54 | 55 | /* I guess this is too easy so far. Some more complex code will 56 | * confuse people. */ 57 | input = read_line(); 58 | phase_3(input); 59 | phase_defused(); 60 | printf("Halfway there!\n"); 61 | 62 | /* Oh yeah? Well, how good is your math? Try on this saucy problem! */ 63 | input = read_line(); 64 | phase_4(input); 65 | phase_defused(); 66 | printf("So you got that one. Try this one.\n"); 67 | 68 | /* Round and 'round in memory we go, where we stop, the bomb blows! */ 69 | input = read_line(); 70 | phase_5(input); 71 | phase_defused(); 72 | printf("Good work! On to the next...\n"); 73 | 74 | /* This phase will never be used, since no one will get past the 75 | * earlier ones. But just in case, make this one extra hard. */ 76 | input = read_line(); 77 | phase_6(input); 78 | phase_defused(); 79 | 80 | /* Wow, they got it! But isn't something... missing? Perhaps 81 | * something they overlooked? Mua ha ha ha ha! */ 82 | 83 | return 0; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /08.2-Binary Bomb/slp-week08.2-lab/slp-week08-lab/code/bomb.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/08.2-Binary Bomb/slp-week08.2-lab/slp-week08-lab/code/bomb.exe -------------------------------------------------------------------------------- /09-Garbage Collector/slp-week09-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/09-Garbage Collector/slp-week09-homework.doc -------------------------------------------------------------------------------- /09-Garbage Collector/slp-week09-lab.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/09-Garbage Collector/slp-week09-lab.zip -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-homework.doc -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer.rar -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer.doc -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph/clsData.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "clsData" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Option Explicit 15 | 16 | Private mThreads() As clsThread 17 | Private mlThreadCount As Long 18 | Private mdMax As Double 19 | Private mdMin As Double 20 | 21 | Public Property Get thread(lIndex As Long) As clsThread 22 | Set thread = mThreads(lIndex) 23 | End Property 24 | 25 | Public Property Get Max() As Double 26 | Max = mdMax 27 | End Property 28 | 29 | Public Property Get Min() As Double 30 | Min = mdMin 31 | End Property 32 | 33 | Public Property Get ThreadCount() As Long 34 | 35 | If mlThreadCount > 10 Then 36 | ThreadCount = 10 37 | Else 38 | ThreadCount = mlThreadCount 39 | End If 40 | 41 | End Property 42 | 43 | Public Sub ReadData(sFileName As String) 44 | 45 | mdMin = -1 46 | Dim iFileNum As Integer 47 | iFileNum = FreeFile 48 | Open sFileName For Input As #iFileNum 49 | 50 | Dim lThread As Long 51 | Dim dStart As Double, dEnd As Double 52 | Dim thread As clsThread 53 | 54 | Do Until EOF(iFileNum) 55 | 56 | Input #iFileNum, lThread, dStart, dEnd 57 | 58 | If (lThread + 1 > mlThreadCount) Then 59 | mlThreadCount = lThread + 1 60 | ReDim Preserve mThreads(mlThreadCount - 1) 61 | Set thread = New clsThread 62 | thread.ThreadID = lThread 63 | Set mThreads(lThread) = thread 64 | End If 65 | 66 | If (mThreads(lThread) Is Nothing) Then 67 | Set thread = New clsThread 68 | thread.ThreadID = lThread 69 | Set mThreads(lThread) = thread 70 | End If 71 | 72 | Set thread = mThreads(lThread) 73 | 74 | 75 | If lThread = 0 Then 76 | Dim test As Integer 77 | test = test + 1 78 | ' If test = 7 Then Stop 79 | End If 80 | 81 | thread.AddData dStart, dEnd 82 | 83 | 84 | 85 | If dEnd > mdMax Then mdMax = dEnd 86 | If dStart < mdMin Or mdMin = -1 Then mdMin = dStart 87 | 88 | Loop 89 | 90 | Close #iFileNum 91 | 92 | End Sub 93 | 94 | Public Property Get ScaleFactor() As Double 95 | 96 | If Len(CStr(mdMax)) > 9 Then 97 | 98 | ScaleFactor = 1 / (10 ^ (Len(CStr(mdMax)) - 9)) 99 | 100 | Else 101 | ScaleFactor = 1# 102 | End If 103 | 104 | End Property 105 | 106 | Public Sub FindClosestInt(cycles As Double, lThread As Long, lTime As Long) 107 | 108 | Dim thread As clsThread 109 | Set thread = mThreads(0) 110 | 111 | Dim lT As Long 112 | Dim dMin As Double, lMin As Long, lBestThread As Long 113 | dMin = Abs(thread.EndTime(0) - cycles) 114 | lMin = 0 115 | 116 | For lT = 0 To mlThreadCount - 1 117 | Set thread = mThreads(lT) 118 | Dim l As Long 119 | For l = 0 To thread.TimeCount - 1 120 | If Abs(thread.EndTime(l) - cycles) < dMin Then 121 | dMin = Abs(thread.EndTime(l) - cycles) 122 | lBestThread = lT 123 | lMin = l 124 | End If 125 | Next 126 | Next 127 | 128 | lThread = lBestThread 129 | lTime = lMin 130 | 131 | End Sub 132 | 133 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph/clsThread.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "clsThread" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Option Explicit 15 | 16 | Private miThreadID As Integer 17 | Private mdStart() As Double 18 | Private mdEnd() As Double 19 | Private mlCount As Long 20 | 21 | Public Property Get TimeCount() As Integer 22 | TimeCount = mlCount 23 | End Property 24 | 25 | Public Property Get ThreadID() As Integer 26 | ThreadID = miThreadID 27 | End Property 28 | 29 | Public Property Let ThreadID(i As Integer) 30 | miThreadID = i 31 | End Property 32 | 33 | Public Sub AddData(dStart As Double, dEnd As Double) 34 | 35 | ReDim Preserve mdStart(mlCount) 36 | ReDim Preserve mdEnd(mlCount) 37 | mdStart(mlCount) = dStart 38 | mdEnd(mlCount) = dEnd 39 | 40 | mlCount = mlCount + 1 41 | 42 | End Sub 43 | 44 | Public Property Get StartTime(lIndex As Long) As Double 45 | StartTime = mdStart(lIndex) 46 | End Property 47 | 48 | Public Property Get EndTime(lIndex As Long) As Double 49 | EndTime = mdEnd(lIndex) 50 | End Property 51 | 52 | Public Sub FindClosestInt(cycles As Double, lTime As Long) 53 | 54 | Dim dMin As Double, lMin As Long 55 | dMin = Abs(mdEnd(0) - cycles) 56 | lMin = 0 57 | Dim l As Long 58 | 59 | For l = 1 To mlCount - 1 60 | If Abs(mdEnd(l) - cycles) < dMin Then 61 | dMin = Abs(mdEnd(l) - cycles) 62 | lMin = l 63 | End If 64 | Next 65 | 66 | lTime = lMin 67 | 68 | End Sub 69 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph/graph.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph/graph.exe -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph/graph.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=frmGraph.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINNT\System32\Stdole2.tlb#OLE Automation 4 | Class=clsThread; clsThread.cls 5 | Class=clsData; clsData.cls 6 | Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX 7 | IconForm="frmGraph" 8 | Startup="frmGraph" 9 | HelpFile="" 10 | ExeName32="graph.exe" 11 | Command32="" 12 | Name="graph" 13 | HelpContextID="0" 14 | CompatibleMode="0" 15 | MajorVer=1 16 | MinorVer=0 17 | RevisionVer=0 18 | AutoIncrementVer=0 19 | ServerSupportFiles=0 20 | VersionCompanyName="Carnegie Technology Education" 21 | CompilationType=0 22 | OptimizationType=0 23 | FavorPentiumPro(tm)=0 24 | CodeViewDebugInfo=0 25 | NoAliasing=0 26 | BoundsCheck=0 27 | OverflowCheck=0 28 | FlPointCheck=0 29 | FDIVCheck=0 30 | UnroundedFP=0 31 | StartMode=0 32 | Unattended=0 33 | Retained=0 34 | ThreadPerObject=0 35 | MaxNumberOfThreads=1 36 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph1.jpg -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph2.jpg -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph3.jpg -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/graph4.jpg -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/RemoteServer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/RemoteServer.lib -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ThreadedClient.cpp 3 | 4 | A threaded database client. 5 | */ 6 | 7 | #include 8 | 9 | #include "servers.h" 10 | 11 | #ifdef _MSC_VER 12 | #include 13 | #include 14 | #include 15 | typedef __int64 INT64_T; 16 | typedef unsigned __int64 UINT64_T; 17 | 18 | typedef LONGLONG time_ms_t; 19 | 20 | time_ms_t getTimeInMilliseconds() { 21 | SYSTEMTIME stime; 22 | 23 | GetSystemTime( &stime ); 24 | 25 | FILETIME ftime; 26 | LARGE_INTEGER time; 27 | 28 | SystemTimeToFileTime( &stime, &ftime ); /* if this fails... */ 29 | 30 | time.HighPart = ftime.dwHighDateTime; 31 | time.LowPart = ftime.dwLowDateTime; 32 | 33 | /* FileTime is in 100ns intervals since 1/1/1601 */ 34 | return time.QuadPart / 10000; 35 | } 36 | #endif 37 | 38 | /* 39 | ostream &operator <<( ostream &out, string *str ) { 40 | 41 | Send a string to an output stream. 42 | */ 43 | ostream &operator<<(ostream &out, string *str) { 44 | if (str) 45 | return out << str->data(); 46 | else 47 | return out; 48 | } 49 | 50 | /* 51 | ostream & operator<< ( ostream &out, INT64_T num ) 52 | 53 | Print a 64-bit unsigned integer to the given output stream. 54 | */ 55 | ostream &operator<<( ostream &out, INT64_T snum ) { 56 | #define _OSTR_LL_LEN 21 57 | if (snum) { 58 | char buffer[_OSTR_LL_LEN]; 59 | int i = _OSTR_LL_LEN - 1; 60 | UINT64_T num; 61 | if (snum < 0) num = -snum; else num = snum; 62 | 63 | buffer[i] = '\0'; 64 | while (num) { 65 | buffer[--i] = ('0' + (int) (num % 10)); 66 | num /= 10; 67 | } 68 | if (snum < 0) buffer[--i] = '-'; 69 | return out << buffer + i; 70 | }else return out << '0'; 71 | } 72 | 73 | /* 74 | int main( int argc, char *argv[] 75 | 76 | You should modify this function to use threads. 77 | */ 78 | int main( int argc, char *argv[] ) { 79 | if (argc != 2) { 80 | cerr << "usage: " << argv[0] << " [account_number]" << endl; 81 | exit(1); 82 | } 83 | int account = atoi( argv[1] ); 84 | 85 | time_ms_t start = getTimeInMilliseconds(); 86 | cout << "Retrieving..."; 87 | cout.flush(); 88 | 89 | Personal *pers = GetPersonalInformation( account ); 90 | AccountInfo *acct = GetAccountInformation( account ); 91 | 92 | time_ms_t end = getTimeInMilliseconds(); 93 | cout << "done (" << end - start << "ms)" << endl; 94 | 95 | if (pers) { 96 | cout << account << ": " << pers->FirstName << " " 97 | << pers->LastName << endl; 98 | cout << pers->Address << endl; 99 | cout << "Balance: " << acct->Balance << ", " << acct->Pending 100 | << " pending, " << acct->Share << " share" << endl; 101 | 102 | delete pers; 103 | delete acct; 104 | }else cout << "No client matches that account number" << endl; 105 | return 0; 106 | } -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="ThreadedClient" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=ThreadedClient - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "ThreadedClient.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "ThreadedClient.mak" CFG="ThreadedClient - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "ThreadedClient - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "ThreadedClient - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "ThreadedClient - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 46 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 | # ADD RSC /l 0x409 /d "NDEBUG" 48 | BSC32=bscmake.exe 49 | # ADD BASE BSC32 /nologo 50 | # ADD BSC32 /nologo 51 | LINK32=link.exe 52 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"tclient.exe" 54 | 55 | !ELSEIF "$(CFG)" == "ThreadedClient - Win32 Debug" 56 | 57 | # PROP BASE Use_MFC 0 58 | # PROP BASE Use_Debug_Libraries 1 59 | # PROP BASE Output_Dir "Debug" 60 | # PROP BASE Intermediate_Dir "Debug" 61 | # PROP BASE Target_Dir "" 62 | # PROP Use_MFC 0 63 | # PROP Use_Debug_Libraries 1 64 | # PROP Output_Dir "Debug" 65 | # PROP Intermediate_Dir "Debug" 66 | # PROP Ignore_Export_Lib 0 67 | # PROP Target_Dir "" 68 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 69 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 70 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 | # ADD RSC /l 0x409 /d "_DEBUG" 72 | BSC32=bscmake.exe 73 | # ADD BASE BSC32 /nologo 74 | # ADD BSC32 /nologo 75 | LINK32=link.exe 76 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 77 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib RemoteServer.lib /nologo /subsystem:console /debug /machine:I386 /out:"tclient.exe" /pdbtype:sept 78 | 79 | !ENDIF 80 | 81 | # Begin Target 82 | 83 | # Name "ThreadedClient - Win32 Release" 84 | # Name "ThreadedClient - Win32 Debug" 85 | # Begin Group "Source Files" 86 | 87 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 88 | # Begin Source File 89 | 90 | SOURCE=.\ThreadedClient.cpp 91 | 92 | !IF "$(CFG)" == "ThreadedClient - Win32 Release" 93 | 94 | !ELSEIF "$(CFG)" == "ThreadedClient - Win32 Debug" 95 | 96 | # ADD CPP /MTd 97 | 98 | !ENDIF 99 | 100 | # End Source File 101 | # End Group 102 | # Begin Group "Header Files" 103 | 104 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 105 | # Begin Source File 106 | 107 | SOURCE=..\RemoteServer\servers.h 108 | # End Source File 109 | # End Group 110 | # Begin Group "Resource Files" 111 | 112 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 113 | # End Group 114 | # End Target 115 | # End Project 116 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "ThreadedClient"=".\ThreadedClient.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.ncb -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/ThreadedClient.opt -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/sclient.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/sclient.exe -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/threadedclient/servers.h: -------------------------------------------------------------------------------- 1 | /* 2 | servers.h 3 | 4 | Open a TCP/IP connection to a server, request the specified 5 | information, and return the information required in a struct. 6 | */ 7 | #include 8 | using namespace std; 9 | 10 | /* 11 | Personal 12 | 13 | Personal information about the owner of an account. 14 | */ 15 | struct Personal { 16 | Personal( int account, string *firstname, string *lastname, 17 | string *address ) { 18 | 19 | FirstName = firstname; 20 | LastName = lastname; 21 | Account = account; 22 | Address = address; 23 | } 24 | ~Personal() { 25 | delete FirstName; 26 | delete LastName; 27 | delete Address; 28 | } 29 | string *FirstName; 30 | string *LastName; 31 | string *Address; 32 | int Account; 33 | }; 34 | 35 | /* 36 | Personal *GetPersonalInformation( int account ) 37 | 38 | Retrieve personal information about the user of a certain account. 39 | Return NULL if there is no such account. 40 | */ 41 | Personal *GetPersonalInformation( int account ); 42 | 43 | /* 44 | AccountInfo 45 | 46 | A struct to hold account-related information. 47 | */ 48 | struct AccountInfo { 49 | AccountInfo( int account, int balance_in_cents, int share, int pending ) { 50 | Account = account; 51 | Balance = balance_in_cents; 52 | Share = share; 53 | Pending = pending; 54 | } 55 | int Account; 56 | int Balance; 57 | int Share; 58 | int Pending; 59 | }; 60 | 61 | AccountInfo *GetAccountInformation( int account ); -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="Timestamp" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=Timestamp - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "Timestamp.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "Timestamp.mak" CFG="Timestamp - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "Timestamp - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "Timestamp - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "Timestamp - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 46 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 | # ADD RSC /l 0x409 /d "NDEBUG" 48 | BSC32=bscmake.exe 49 | # ADD BASE BSC32 /nologo 50 | # ADD BSC32 /nologo 51 | LINK32=link.exe 52 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Timestamp.exe" 54 | 55 | !ELSEIF "$(CFG)" == "Timestamp - Win32 Debug" 56 | 57 | # PROP BASE Use_MFC 0 58 | # PROP BASE Use_Debug_Libraries 1 59 | # PROP BASE Output_Dir "Debug" 60 | # PROP BASE Intermediate_Dir "Debug" 61 | # PROP BASE Target_Dir "" 62 | # PROP Use_MFC 0 63 | # PROP Use_Debug_Libraries 1 64 | # PROP Output_Dir "Debug" 65 | # PROP Intermediate_Dir "Debug" 66 | # PROP Ignore_Export_Lib 0 67 | # PROP Target_Dir "" 68 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 69 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 70 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 | # ADD RSC /l 0x409 /d "_DEBUG" 72 | BSC32=bscmake.exe 73 | # ADD BASE BSC32 /nologo 74 | # ADD BSC32 /nologo 75 | LINK32=link.exe 76 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 77 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Timestamp.exe" /pdbtype:sept 78 | 79 | !ENDIF 80 | 81 | # Begin Target 82 | 83 | # Name "Timestamp - Win32 Release" 84 | # Name "Timestamp - Win32 Debug" 85 | # Begin Group "Source Files" 86 | 87 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 88 | # Begin Source File 89 | 90 | SOURCE=.\test.cpp 91 | # End Source File 92 | # Begin Source File 93 | 94 | SOURCE=.\tsc.c 95 | # End Source File 96 | # End Group 97 | # Begin Group "Header Files" 98 | 99 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 100 | # Begin Source File 101 | 102 | SOURCE=.\tsc.h 103 | # End Source File 104 | # End Group 105 | # Begin Group "Resource Files" 106 | 107 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 108 | # End Group 109 | # End Target 110 | # End Project 111 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Timestamp"=".\Timestamp.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.exe -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.ncb -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.opt -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/Timestamp.plg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
 4 | 

Build Log

5 |

6 | --------------------Configuration: Timestamp - Win32 Release-------------------- 7 |

8 |

Command Lines

9 | Creating temporary file "C:\TEMP\RSP6C0.tmp" with contents 10 | [ 11 | /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Release/Timestamp.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c 12 | "C:\Working\SSD6\Exercise6\handout\timestamp\test.cpp" 13 | "C:\Working\SSD6\Exercise6\handout\timestamp\tsc.c" 14 | ] 15 | Creating command line "cl.exe @C:\TEMP\RSP6C0.tmp" 16 | Creating temporary file "C:\TEMP\RSP6C1.tmp" with contents 17 | [ 18 | kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"Release/Timestamp.pdb" /machine:I386 /out:"Timestamp.exe" 19 | .\Release\test.obj 20 | .\Release\tsc.obj 21 | ] 22 | Creating command line "link.exe @C:\TEMP\RSP6C1.tmp" 23 |

Output Window

24 | Compiling... 25 | test.cpp 26 | tsc.c 27 | Linking... 28 | 29 | 30 | 31 |

Results

32 | Timestamp.exe - 0 error(s), 0 warning(s) 33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/output.out: -------------------------------------------------------------------------------- 1 | 0,0,306496 2 | 0,321536,3537792 3 | 0,3562944,6731392 4 | 0,6758688,6814848 5 | 0,6817120,6826528 6 | 0,6827680,6838208 7 | 0,6839584,6842240 8 | 0,6843360,6846464 9 | 0,6848064,6851360 10 | 0,6854080,7051136 11 | 0,7052256,7056960 12 | 0,7057984,7061120 13 | 0,7062752,7063104 14 | 0,7064448,7077984 15 | 0,7079008,9925088 16 | 0,9950720,13119360 17 | 0,13138048,16314176 18 | 0,16335264,19507136 19 | 0,19528192,22701152 20 | 0,22721664,25895104 21 | 0,25917568,25965376 22 | 0,25967040,25975872 23 | 0,25977664,25993248 24 | 0,25994368,25996576 25 | 0,25999456,25999552 26 | 0,26000576,26003040 27 | 0,26005216,26008352 28 | 0,26009568,26031200 29 | 0,26148258,26148290 30 | 0,26150242,26169378 31 | 0,26170562,26172194 32 | 0,26173698,26175650 33 | 0,26177090,26179010 34 | 0,26180738,26182146 35 | 0,26183234,26184098 36 | 0,26186146,26186434 37 | 0,26187650,26188514 38 | 0,26189762,26191234 39 | 0,26192290,26194754 40 | 0,26195778,26199426 41 | 0,26200866,26203266 42 | 0,26204290,26204546 43 | 0,26206658,26207234 44 | 0,26209218,26211554 45 | 0,26212578,26219394 46 | 0,26220930,26222498 47 | 0,26223714,26223778 48 | 0,26224898,26228066 49 | 0,26229122,26235138 50 | 0,26299360,26406112 51 | 0,26633602,26635426 52 | 0,26692290,26932066 53 | 0,27126690,27238018 54 | 0,27307266,29087042 55 | 0,29106818,32281058 56 | 0,32300258,35475074 57 | 0,35493570,38669730 58 | 0,38686434,39197666 59 | 3,956987,957339 60 | 3,959035,1934331 61 | 3,1936027,2452603 62 | 3,2453851,2862907 63 | 3,2864443,3194043 64 | 3,3197627,3442363 65 | 3,3443835,3459643 66 | 3,3460827,3464123 67 | 3,3465787,3536411 68 | 3,3563131,3684955 69 | 3,3687387,3710523 70 | 3,3712091,3910907 71 | 3,3912379,4332763 72 | 3,4334107,4359771 73 | 3,4361243,6730043 74 | 3,6754075,6797467 75 | 3,6798683,6809883 76 | 3,6811707,6828187 77 | 3,6830811,6833403 78 | 3,6835035,7050331 79 | 3,7052155,7056667 80 | 3,7058267,7061371 81 | 3,7062747,7074587 82 | 3,7076571,7113371 83 | 3,7114619,9923707 84 | 3,9948923,13117979 85 | 3,13143963,16312763 86 | 3,16332667,19505627 87 | 3,19526363,19655675 88 | 3,19657755,22699707 89 | 3,22722715,25893787 90 | 3,25914267,25972059 91 | 3,25974715,26006107 92 | 3,26007163,26009499 93 | 3,26011003,26016443 94 | 3,26017691,26017819 95 | 3,27365426,27379794 96 | 3,27504130,27534466 97 | 3,27535682,27604386 98 | 3,27605666,27608226 99 | 3,27609474,27633474 100 | 3,27634530,27647106 101 | 3,27648610,27649506 102 | 3,27650978,27659362 103 | 3,27660386,27660642 104 | 3,27661858,27727906 105 | 3,27729698,27752674 106 | 3,27754018,27763298 107 | 3,27764322,27765186 108 | 3,27766274,27780866 109 | 3,27783394,27784162 110 | 3,27785634,27785890 111 | 3,27787266,27787522 112 | 3,27788546,27788802 113 | 3,27789922,27792226 114 | 3,27793634,27793922 115 | 3,27796130,27799170 116 | 3,27800898,27808834 117 | 3,27810178,27820194 118 | 3,27821570,27828770 119 | 3,27829826,27832962 120 | 3,27834178,27856322 121 | 3,27857506,27873282 122 | 3,27874370,27908322 123 | 3,27909506,27909794 124 | 3,27910818,27955298 125 | 3,27956674,27959650 126 | 3,27960706,27984066 127 | 3,27985122,27992962 128 | 3,27994018,28013538 129 | 3,28014722,28032002 130 | 3,28033058,28049570 131 | 3,28050882,28055842 132 | 3,28056930,28062466 133 | 3,28063778,28066274 134 | 3,28067586,28081218 135 | 3,28082402,28107298 136 | 3,28108482,28178626 137 | 3,28180930,28182434 138 | 3,28185058,28185922 139 | 3,28187426,28189666 140 | 3,28192002,28192258 141 | 3,28194626,28196034 142 | 3,28197922,28198178 143 | 3,28199874,28201794 144 | 3,28202914,28204610 145 | 3,28207074,28207362 146 | 3,28208674,28208962 147 | 3,28209986,28210274 148 | 3,28211522,28214338 149 | 3,28216706,28216994 150 | 3,28218146,28218434 151 | 3,28219586,28223074 152 | 3,28225186,28225474 153 | 3,28227010,28227298 154 | 3,28230114,28231618 155 | 3,28234786,28235074 156 | 3,28236194,28236450 157 | 3,28238754,28242178 158 | 3,28243490,28244610 159 | 3,28246178,28246466 160 | 3,28247714,28257410 161 | 3,28258594,28280738 162 | 3,28281922,28994114 163 | 3,28996194,29003746 164 | 3,29005282,29011906 165 | 3,29013282,29021666 166 | 3,29022946,29039170 167 | 3,29040642,29087170 168 | 3,29114850,32280898 169 | 3,32303266,32667618 170 | 3,32669058,35475202 171 | 3,35496770,38669826 172 | 3,38691298,41434882 173 | 1,1565282,1565378 174 | 1,1567330,3537858 175 | 1,3566370,6731554 176 | 1,6762370,9925154 177 | 1,9954178,13119426 178 | 1,13146754,16314018 179 | 1,16339106,19507202 180 | 1,19533282,22701186 181 | 1,22725890,25895170 182 | 1,25921122,26416994 183 | 1,26418530,26426690 184 | 1,26428738,26440354 185 | 1,26441890,26444226 186 | 1,26445922,26446082 187 | 1,26448578,26454530 188 | 1,26455842,26458978 189 | 1,26460386,26463522 190 | 1,26552864,26553056 191 | 1,26554848,26590208 192 | 1,26591488,26613696 193 | 1,26615264,26618176 194 | 1,26619712,26621664 195 | 1,26622784,26625920 196 | 1,26627040,26698720 197 | 1,26699904,26702240 198 | 1,26703264,26705952 199 | 1,26707104,26710240 200 | 1,26711584,26716928 201 | 1,26718048,26724672 202 | 1,26726208,26751264 203 | 1,26752736,26753088 204 | 1,26754144,26776896 205 | 1,26777984,26800960 206 | 1,26802208,26824224 207 | 1,26825312,26846464 208 | 1,26848000,26858304 209 | 1,26859424,26893920 210 | 1,26895200,26897152 211 | 1,26899648,26904960 212 | 1,26906048,26908544 213 | 1,26910944,26911264 214 | 1,26913280,26953024 215 | 1,26954368,26956864 216 | 1,26958208,26958496 217 | 1,26959840,26961760 218 | 1,26962944,26993216 219 | 1,26994432,26996640 220 | 1,26999040,27001664 221 | 1,27002880,27003200 222 | 1,27004224,27006176 223 | 1,27008544,27011296 224 | 1,27012640,27020960 225 | 1,27022848,27052224 226 | 1,27053824,27055616 227 | 1,27056704,27059168 228 | 1,27062016,27062336 229 | 1,27063744,27065632 230 | 1,27066944,27105440 231 | 1,27106496,27123680 232 | 1,27125248,27128192 233 | 1,27129376,27132416 234 | 1,27134592,27155616 235 | 1,27156736,27170976 236 | 1,27172032,27174528 237 | 1,27175744,27178784 238 | 1,27179840,27257280 239 | 1,27258432,27272224 240 | 1,27273472,27320704 241 | 1,27321920,27329248 242 | 1,27330528,29021216 243 | 1,29022912,29086944 244 | 1,29110624,32281120 245 | 1,32303232,35475008 246 | 1,35496224,38669632 247 | 1,38690656,41478272 248 | 1,41479712,41481056 249 | 1,41482240,41485120 250 | 1,41487744,41492128 251 | 1,41493216,41493664 252 | 1,41494816,41496960 253 | 1,41498208,41510656 254 | 1,41511808,41704096 255 | 2,1580736,2476224 256 | 2,2478624,3537664 257 | 2,3566720,6731328 258 | 2,6763072,9924960 259 | 2,9954144,13119200 260 | 2,13146720,14520288 261 | 2,14521440,16314240 262 | 2,16338432,19507008 263 | 2,19535040,22701024 264 | 2,22725856,25895392 265 | 2,25921088,26416576 266 | 2,26555872,26626240 267 | 2,26627360,26640544 268 | 2,26642144,26647392 269 | 2,26648960,26651904 270 | 2,26653024,26659456 271 | 2,26660512,26679936 272 | 2,26681024,26683648 273 | 2,26684736,26685056 274 | 2,26686400,26932512 275 | 2,26934240,26951488 276 | 2,26952704,27004832 277 | 2,27006720,27013120 278 | 2,27015424,27113792 279 | 2,27115168,27117952 280 | 2,27119392,27238432 281 | 2,27240352,27244544 282 | 2,27246688,27252832 283 | 2,27254176,27256736 284 | 2,27257856,27258176 285 | 2,27259264,27261216 286 | 2,27263296,27294976 287 | 2,27296128,29086816 288 | 2,29106848,32281280 289 | 2,32300224,35474848 290 | 2,35493472,38669504 291 | 2,38686528,40259840 292 | 2,40261760,40270016 293 | 2,40271104,41831904 294 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/tsc.c: -------------------------------------------------------------------------------- 1 | /* 2 | tsc.c 3 | 4 | Assembly-level routines to read the processor timestamp counter. 5 | */ 6 | #include 7 | #include "tsc.h" 8 | 9 | int tsc_valid( void ) { 10 | int is_valid = 0; 11 | 12 | /* presumably Visual C++ specific */ 13 | #ifdef _MSC_VER 14 | 15 | /* the "ID" bit on CFLAGS */ 16 | #define ID_BIT 21 17 | /* the "supports processor counter" bitmask */ 18 | #define TSC_BITMASK 0x10 19 | 20 | __asm { 21 | /* alright, first we should check for the CPUID instruction */ 22 | pushfd /* put EFLAGS on the stack */ 23 | mov eax, [esp] /* copy over to eax */ 24 | btc [esp], ID_BIT /* flip the bit on the stack */ 25 | popfd /* put the stack back in EFLAGS */ 26 | pushfd /* and take it out again */ 27 | test eax, [esp] /* test for similarity */ 28 | jz done /* identical: flip didn't take */ 29 | mov eax, [esp] /* copy over to eax */ 30 | btc [esp], ID_BIT /* flip the bit again */ 31 | popfd /* put the stack back in EFLAGS */ 32 | pushfd /* and take it out again again */ 33 | test eax, [esp] /* test for similarity */ 34 | jz done /* identical: flip didn't take */ 35 | 36 | mov eax, 0x1 /* the code for what we want */ 37 | cpuid /* get it */ 38 | and edx, TSC_BITMASK /* check only the bit we want */ 39 | jz done /* zero if it wasn't set, i.e. no capability */ 40 | mov is_valid, 1 /* set is_valid */ 41 | jmp done /* goto done */ 42 | done: 43 | add esp, 4 /* clean up the stack */ 44 | } 45 | 46 | /* no other cases: note that we "cleverly" compile to constant-zero */ 47 | #endif 48 | 49 | return is_valid; 50 | } 51 | 52 | tsc_t tsc_get( void ) { 53 | /* 54 | union { 55 | UINT64_T whole; 56 | struct { 57 | UINT32_T high; 58 | UINT32_T low; 59 | } split; 60 | } store; 61 | */ 62 | 63 | #ifdef _MSC_VER 64 | 65 | __asm { 66 | rdtsc 67 | 68 | /* This nicely puts our returned value in storage, from which 69 | we can conveniently return. Note that standard calling 70 | conventions have us returning 64 bit quantities in eax and 71 | edx anyway, so we might as well skip the middle step. 72 | 73 | mov store.split.high, eax 74 | mov store.split.low, edx 75 | */ 76 | } 77 | #endif 78 | /* fprintf( stderr, "dbg_ts: got %lx, %lx: %I64x\n", store.split.high, 79 | store.split.low, store.whole ); */ 80 | /* return store.whole; */ 81 | } -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer/timer/project/timestamp_v1/tsc.h: -------------------------------------------------------------------------------- 1 | /* 2 | tsc.h 3 | 4 | Interface to the IA-32 timestamp register instruction, 5 | RDTSC. 6 | */ 7 | 8 | #if defined(__STDC__) 9 | #define ARGS( prototype ) prototype 10 | #else 11 | #define ARGS( prototype ) 12 | #endif 13 | 14 | /* defined if Visual C++ */ 15 | #if defined(_MSC_VER) 16 | #define UINT64_T unsigned __int64 17 | #define UINT32_T unsigned __int32 18 | #elif defined(__unix) 19 | #define UINT64_T uint64_t 20 | #define UINT32_T uint32_t 21 | #else 22 | #define UINT64_T uint64_t 23 | #define UINT32_T uint32_t 24 | #endif 25 | 26 | /* 27 | __cplusplus was in the draft ANSI C++ standard, but for some reason 28 | got dropped. Regardless, it appears in most C++ compilers, by which 29 | I mean gcc and Visual C++. 30 | */ 31 | #if defined(__cplusplus) 32 | extern "C" { 33 | #endif 34 | 35 | typedef UINT64_T tsc_t; 36 | 37 | /* 38 | int tsc_valid() 39 | 40 | Determine whether the (Intel) processor has the RDTSC instruction 41 | for reading the timestamp counter. Return zero to mean "no"; 42 | else, return nonzero. 43 | 44 | If tsc_valid() is false, programs should not call 45 | tsc_get(). 46 | */ 47 | int tsc_valid( ARGS(void) ); 48 | 49 | /* 50 | tsc_t tsc_get() 51 | 52 | Retrieve the current value of the timestamp counter. 53 | */ 54 | tsc_t tsc_get( ARGS(void) ); 55 | 56 | #if defined(__cplusplus) 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/1timer_interval.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/1timer_interval.pdf -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/2profiling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/2profiling.pdf -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/precise.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/precise.rar -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/slp-week10-lab-instruction.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/slp-week10-lab/slp-week10-lab-instruction.pptx -------------------------------------------------------------------------------- /10-Performance Measurement/slp-week10-lab/timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "time.h" 4 | #include "iostream.h" 5 | 6 | void my_subroutine(long n) 7 | { 8 | // this routine just does something that 9 | // takes some time so we can illustrate 10 | // timing a subroutine call: 11 | char s[16]; 12 | for (long i = 0; i < n; i++) { 13 | _itoa(i, s, sizeof(s)); 14 | } 15 | } 16 | 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | long n = 1000000; 21 | clock_t start = clock(); 22 | my_subroutine(n); 23 | clock_t finish = clock(); 24 | double duration = (double)(finish - start) / CLOCKS_PER_SEC; 25 | cout << "Time for " << n << " iterations: " << 26 | duration << "s," << " precision is " << 27 | CLOCKS_PER_SEC << " clocks per second." << 28 | endl; 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /10-Performance Measurement/用CodeBlocks Code profiler插件剖析.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/10-Performance Measurement/用CodeBlocks Code profiler插件剖析.pdf -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/11-Program Performance/slp-week11-homework.doc -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | std::cout << "Hello, World!" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice1/words.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | #include "ctype.h" 4 | #include "string.h" 5 | #include "time.h" 6 | 7 | 8 | FILE *inp; 9 | int wordcount = 0; 10 | // we don't know how many words there will be, so 11 | // for simplicity, just allocate a big array: 12 | char *words[100000]; 13 | // this array points to strings that are allocated 14 | // on the heap 15 | 16 | 17 | void fatal(char *msg) 18 | { 19 | printf("FATAL ERROR: %s\n", msg); 20 | exit(1); 21 | } 22 | 23 | 24 | void opentext(char *filename) 25 | { 26 | inp = fopen(filename, "r"); 27 | if (!inp) fatal("file open failed"); 28 | } 29 | 30 | 31 | // getword -- return true if you got a word 32 | // 33 | int getword(char *word) 34 | { 35 | int index = 0; 36 | int c = getc(inp); 37 | if (c <= 0) return false; 38 | // scan to alpha 39 | while (!isalpha(c)) { 40 | c = getc(inp); 41 | if (c <= 0) return false; 42 | } 43 | // scan to non-alpha and save in word 44 | while (isalpha(c) && (c >= 0)) { 45 | word[index++] = c; 46 | c = getc(inp); 47 | } 48 | word[index] = 0; /* eos */ 49 | /* be careful if c is eof indication */ 50 | if (c >= 0) ungetc(c, inp); 51 | return true; 52 | } 53 | 54 | 55 | // string_to_heap -- move a string to the heap 56 | // 57 | char *string_to_heap(char *s) 58 | { 59 | char *h = (char *) malloc(strlen(s) + 1); 60 | if (!h) fatal("no more memory for words"); 61 | strcpy(h, s); 62 | return h; 63 | } 64 | 65 | 66 | // readwords -- read words to array 67 | // 68 | void readwords() 69 | { 70 | // each word goes here first: 71 | char word[1024]; 72 | while (getword(word)) { 73 | // then we figure out how much memory was 74 | // really needed, allocate that on the heap, 75 | // copy word to the heap memory, and save 76 | // a pointer in words array: 77 | words[wordcount++] = string_to_heap(word); 78 | } 79 | } 80 | 81 | 82 | #define streql(s1, s2) (strcmp(s1, s2) == 0) 83 | 84 | // countpairs -- how many pairs (word1, word2) 85 | // 86 | int countpairs(char *word1, char *word2) 87 | { 88 | int count = 0; 89 | int i; 90 | for (i = 0; i < wordcount; i++) { 91 | // find word1: 92 | if (streql(words[i], word1)) { 93 | // if found, check if it's followed by word2: 94 | if (streql(words[(i + 1) % wordcount], word2)) { 95 | // yes, we found (word1, word2) 96 | count++; 97 | } 98 | } 99 | } 100 | return count; 101 | } 102 | 103 | 104 | // pick_nth -- find word after the nth pair 105 | // 106 | // this works like countpairs(), but it stops 107 | // after finding n words and returns the next 108 | // word 109 | // 110 | char *pick_nth(char *word1, char *word2, int n) 111 | { 112 | int count = 0; 113 | int i; 114 | for (i = 0; i < wordcount; i++) { 115 | if (streql(words[i], word1)) { 116 | if (streql(words[(i + 1) % wordcount], word2)) { 117 | count++; 118 | if (count == n) 119 | return words[(i + 2) % wordcount]; 120 | } 121 | } 122 | } 123 | fatal("pick_nth did not find nth tuple"); 124 | return NULL; // this avoids a compiler warning, but 125 | // is never executed 126 | } 127 | 128 | 129 | /* generate -- generate from trigram model */ 130 | /**/ 131 | void generate(int howmany, char *word1, char *word2) 132 | { 133 | int count; 134 | char sep; /* word separator */ 135 | printf("%s %s", word1, word2); 136 | for (count = 2; count < howmany; count++) { 137 | /* first see how many pairs there are: */ 138 | int n = countpairs(word1, word2); 139 | char *newword; 140 | if (n == 0) fatal("no pairs found"); 141 | /* now pick a random number from 1 to n: */ 142 | n = (rand() % n) + 1; 143 | /* find nth word: */ 144 | newword = pick_nth(word1, word2, n); 145 | /* shift */ 146 | word1 = word2; 147 | word2 = newword; 148 | /* break the line every 10 words */ 149 | if (count % 10 == 0) sep = '\n'; 150 | else sep = ' '; 151 | /* and add periods before capitalized words */ 152 | if (isupper(word2[0])) printf("."); 153 | printf("%c%s", sep, word2); 154 | } 155 | printf(".\n"); 156 | } 157 | 158 | 159 | void main() 160 | { 161 | // seed the random number generator: 162 | srand((unsigned) time(NULL)); 163 | opentext("..\\life.txt"); 164 | 165 | readwords(); 166 | 167 | fclose(inp); 168 | 169 | generate(200, words[wordcount/2], 170 | words[wordcount/2 + 1]); 171 | 172 | getchar(); // this prevents the output window from 173 | // closing until the user has looked at it 174 | } 175 | 176 | -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice1/words3.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | #include "ctype.h" 4 | #include "string.h" 5 | #include "time.h" 6 | 7 | #define streql(s1, s2) (strcmp(s1, s2) == 0) 8 | 9 | 10 | FILE *inp; 11 | int wordcount = 0; 12 | // we don't know how many words there will be, so 13 | // for simplicity, just allocate a big array: 14 | char *words[100000]; 15 | // this array points to strings that are allocated 16 | // on the heap 17 | 18 | 19 | void fatal(char *msg) 20 | { 21 | printf("FATAL ERROR: %s\n", msg); 22 | exit(1); 23 | } 24 | 25 | 26 | void opentext(char *filename) 27 | { 28 | inp = fopen(filename, "r"); 29 | if (!inp) fatal("file open failed"); 30 | } 31 | 32 | 33 | // getword -- return true if you got a word 34 | // 35 | int getword(char *word) 36 | { 37 | int index = 0; 38 | int c = getc(inp); 39 | if (c <= 0) return false; 40 | // scan to alpha 41 | while (!isalpha(c)) { 42 | c = getc(inp); 43 | if (c <= 0) return false; 44 | } 45 | // scan to non-alpha and save in word 46 | while (isalpha(c) && (c >= 0)) { 47 | word[index++] = c; 48 | c = getc(inp); 49 | } 50 | word[index] = 0; /* eos */ 51 | /* be careful if c is eof indication */ 52 | if (c >= 0) ungetc(c, inp); 53 | return true; 54 | } 55 | 56 | 57 | // string_to_heap -- move a string to the heap 58 | // 59 | char *string_to_heap(char *s) 60 | { 61 | for (int i = 0; i < wordcount; i++) { 62 | if (streql(s, words[i])) { 63 | return words[i]; 64 | } 65 | } 66 | char *h = (char *) malloc(strlen(s) + 1); 67 | if (!h) fatal("no more memory for words"); 68 | strcpy(h, s); 69 | return h; 70 | } 71 | 72 | 73 | // readwords -- read words to array 74 | // 75 | void readwords() 76 | { 77 | // each word goes here first: 78 | char word[1024]; 79 | while (getword(word)) { 80 | // then we figure out how much memory was 81 | // really needed, allocate that on the heap, 82 | // copy word to the heap memory, and save 83 | // a pointer in words array: 84 | words[wordcount] = string_to_heap(word); 85 | wordcount++; 86 | } 87 | } 88 | 89 | 90 | 91 | // countpairs -- how many pairs (word1, word2) 92 | // 93 | int countpairs(char *word1, char *word2) 94 | { 95 | int count = 0; 96 | int i; 97 | for (i = 0; i < wordcount; i++) { 98 | // find word1: 99 | if (words[i] == word1) { 100 | // if found, check if it's followed by word2: 101 | if (words[(i + 1) % wordcount] == word2) { 102 | // yes, we found (word1, word2) 103 | count++; 104 | } 105 | } 106 | } 107 | return count; 108 | } 109 | 110 | 111 | // pick_nth -- find word after the nth pair 112 | // 113 | // this works like countpairs(), but it stops 114 | // after finding n words and returns the next 115 | // word 116 | // 117 | char *pick_nth(char *word1, char *word2, int n) 118 | { 119 | int count = 0; 120 | int i; 121 | for (i = 0; i < wordcount; i++) { 122 | if (words[i] == word1) { 123 | if (words[(i + 1) % wordcount] == word2) { 124 | count++; 125 | if (count == n) 126 | return words[(i + 2) % wordcount]; 127 | } 128 | } 129 | } 130 | fatal("pick_nth did not find nth tuple"); 131 | return NULL; // this avoids a compiler warning, but 132 | // is never executed 133 | } 134 | 135 | 136 | /* generate -- generate from trigram model */ 137 | /**/ 138 | void generate(int howmany, char *word1, char *word2) 139 | { 140 | int count; 141 | char sep; /* word separator */ 142 | printf("%s %s", word1, word2); 143 | for (count = 2; count < howmany; count++) { 144 | /* first see how many pairs there are: */ 145 | int n = countpairs(word1, word2); 146 | char *newword; 147 | if (n == 0) fatal("no pairs found"); 148 | /* now pick a random number from 1 to n: */ 149 | n = (rand() % n) + 1; 150 | /* find nth word: */ 151 | newword = pick_nth(word1, word2, n); 152 | /* shift */ 153 | word1 = word2; 154 | word2 = newword; 155 | /* break the line every 10 words */ 156 | if (count % 10 == 0) sep = '\n'; 157 | else sep = ' '; 158 | /* and add periods before capitalized words */ 159 | if (isupper(word2[0])) printf("."); 160 | printf("%c%s", sep, word2); 161 | } 162 | printf(".\n"); 163 | } 164 | 165 | 166 | void main() 167 | { 168 | // seed the random number generator: 169 | srand((unsigned) time(NULL)); 170 | opentext("..\\life.txt"); 171 | 172 | readwords(); 173 | 174 | fclose(inp); 175 | 176 | generate(10000, words[wordcount/2], 177 | words[wordcount/2 + 1]); 178 | 179 | getchar(); // this prevents the output window from 180 | // closing until the user has looked at it 181 | } 182 | 183 | -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice1/参考的profile输出.txt: -------------------------------------------------------------------------------- 1 | Func Func+Child Hit 2 | Time % Time % Count Function 3 | --------------------------------------------------------- 4 | 24222.677 65.4 24222.677 65.4 9998 countpairs(char *,char *) (words.obj) 5 | 12217.216 33.0 12217.216 33.0 9998 pick_nth(char *,char *,int) (words.obj) 6 | 380.951 1.0 36820.844 99.4 1 generate(int,char *,char *) (words.obj) 7 | 133.249 0.4 133.249 0.4 8254 getword(char *) (words.obj) 8 | 67.732 0.2 67.732 0.2 8253 string_to_heap(char *) (words.obj) 9 | 1.952 0.0 37019.650 100.0 1 _main (words.obj) 10 | 1.004 0.0 1.004 0.0 1 opentext(char *) (words.obj) 11 | 0.000 0.0 195.850 0.5 1 readwords(void) (words.obj) 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Func Func+Child Hit 20 | Time % Time % Count Function 21 | --------------------------------------------------------- 22 | 7471.087 53.7 7471.087 53.7 9998 countpairs(char *,char *) (words.obj) 23 | 3752.341 27.0 3752.341 27.0 9998 pick_nth(char *,char *,int) (words.obj) 24 | 2268.408 16.3 2268.408 16.3 8253 string_to_heap(char *) (words.obj) 25 | 272.704 2.0 11496.132 82.7 1 generate(int,char *,char *) (words.obj) 26 | 137.970 1.0 137.970 1.0 8254 getword(char *) (words.obj) 27 | 1.936 0.0 13902.930 100.0 1 _main (words.obj) 28 | 0.961 0.0 0.961 0.0 1 opentext(char *) (words.obj) 29 | 0.000 0.0 2403.901 17.3 1 readwords(void) (words.obj) 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice2/data.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/11-Program Performance/slp-week11-lab/practice2/data.zip -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice2/data/replace.txt: -------------------------------------------------------------------------------- 1 | "Machine" "Mach" 2 | "Compiler" "Comp" 3 | "Semantics" "Sem" 4 | "Symbol_ptr" "Symbol *" 5 | "Method_ptr" "Method *" 6 | "Object_ptr" "Object *" 7 | "FClass_ptr" "FClass *" 8 | "Builtin_ptr" "Builtin *" 9 | "Frame_ptr" "Frame *" 10 | "Array_ptr" "Array *" 11 | "Mach_ptr" "Mach *" 12 | "::create" "::make" 13 | "expected_" "exp_" 14 | "op_" "oper_" 15 | "OP_" "OPCODE_" 16 | "aa" "ba" 17 | "cd" "dd" 18 | -------------------------------------------------------------------------------- /11-Program Performance/slp-week11-lab/practice2/substitute.cpp: -------------------------------------------------------------------------------- 1 | /* substitute -- substitute strings in a list of files 2 | 3 | This program operates on a set of files listed on 4 | the command line. The first file specifies a list of 5 | string substitutions to be performed on the remaining 6 | files. The list of string substitutions has the form: 7 | 8 | "string 1" "replacement 1" 9 | "string 2" "replacement 2" 10 | ... 11 | 12 | If a string contains a double quote character or 13 | a backslash character, escape the character with 14 | backslash: "\"" denotes the string with one double 15 | quote character. "\\" contains one backslash. 16 | Each file is searched for instances of "string 1". 17 | Any occurences are replaced with "replacement 1". 18 | In a similar manner, all "string 2"s are replaced 19 | with "replacement 2"s, and so on. 20 | 21 | The results are written to the input file. Be sure 22 | to keep a backup of files if you do not want to lose 23 | the originals when you run this program. 24 | */ 25 | 26 | #include "fx.h" 27 | #include "iostream.h" 28 | 29 | // parse a quoted string from buffer 30 | // return final index in string 31 | int parse1(CString *buffer, int start, CString *str) 32 | { 33 | // look for initial quote: 34 | int i = buffer->Find("\"", start); 35 | if (i != -1) { 36 | // copy to result string 37 | str->Empty(); 38 | int j = 0; // index into str 39 | i++; // skip over the opening double-quote 40 | // scan and copy up to the closing double-quote: 41 | while ((*buffer)[i] != 0) { 42 | if ((*buffer)[i] == '\\') { 43 | // read next char to see what to do 44 | i++; 45 | if ((*buffer)[i] != 0) { 46 | str->Insert(j++, CString((*buffer)[i])); 47 | } 48 | } else if ((*buffer)[i] == '\"') { 49 | return i + 1; 50 | } 51 | str->Insert(j++, CString((*buffer)[i])); 52 | i++; 53 | } 54 | } 55 | return -1; 56 | } 57 | 58 | 59 | // parse two quoted strings from buffer; return false on failure 60 | // 61 | bool parse(CString *buffer, CString *pattern, CString *replacement) 62 | { 63 | int start = parse1(buffer, 0, pattern); 64 | if (start < 0) { 65 | return false; 66 | } 67 | start = parse1(buffer, start, replacement); 68 | return (start >= 0); 69 | } 70 | 71 | 72 | 73 | void substitute(CString *data, CString *pattern, CString *replacement) 74 | { 75 | int loc; 76 | int location = 0; 77 | int pl = pattern->Length; 78 | // find every occurrence of pattern: 79 | for (loc = data->Find(*pattern, 0); loc >= 0; 80 | loc = data->Find(*pattern, 0)) { 81 | int dis = loc - pl; 82 | if (dis >= 0){ 83 | location = dis; 84 | } 85 | else{ 86 | location = 0; 87 | } 88 | // delete the pattern string from loc: 89 | data->Delete(loc, pattern->GetLength()); 90 | // insert each character of the replacement string: 91 | // for (int i = 0; i < replacement->GetLength(); i++) { 92 | // data->Insert(loc + i, (*replacement)[i]);} 93 | // } 94 | data->Insert(loc,replacement); 95 | } 96 | 97 | 98 | 99 | void do_substitutions(CString *data, CString *subs_filename) 100 | { 101 | TRY { 102 | CStdioFile file(*subs_filename, CFile::modeRead); 103 | while (true) { 104 | CString buffer; // holds line from file 105 | CString pattern; 106 | CString replacement; 107 | file.ReadString(buffer); 108 | // handle end of file 109 | if (buffer.GetLength() == 0) break; 110 | if (parse(&buffer, &pattern, &replacement)) { 111 | substitute(data, &pattern, &replacement); 112 | } else { 113 | cout << "Bad pattern/replacement line: " << buffer << endl; 114 | return; 115 | } 116 | } 117 | } 118 | CATCH(CFileException, e ) { 119 | cout << "File could not be opened or read " << e->m_cause << endl; 120 | } 121 | END_CATCH 122 | } 123 | 124 | 125 | void process_file(CString *filename, CString *subs_filename) 126 | { 127 | // read in filename to a CString 128 | TRY { 129 | CFile file(*filename, CFile::modeRead); 130 | int size = file.GetLength(); 131 | // read the data, allocate more than we need 132 | char *data = new char[size + 16]; 133 | file.Read(data, size); 134 | // files are not zero-terminated but string should be: 135 | data[size] = 0; 136 | // now we can make a CString from the data: 137 | CString content(data); 138 | delete data; // data is no longer needed 139 | do_substitutions(&content, subs_filename); 140 | // write the data 141 | file.Close(); 142 | file.Open(*filename, CFile::modeWrite); 143 | file.Write(content, content.GetLength()); 144 | file.SetLength(content.GetLength()); 145 | file.Close(); 146 | } 147 | CATCH(CFileException, e ) { 148 | cout << "File could not be opened or read " << 149 | e->m_cause << " " << *filename << endl; 150 | } 151 | END_CATCH 152 | 153 | } 154 | 155 | 156 | 157 | 158 | int main(int argc, char *argv[]) 159 | { 160 | if (argc < 3) { 161 | cout << "Not enough input arguments" << endl; 162 | cout << "Usage: substitute subs-file src1 src2 ..." << endl; 163 | } else { 164 | CString subs_filename(argv[1]); 165 | for (int i = 2; i < argc; i++) { 166 | CString filename(argv[i]); 167 | process_file(&filename, &subs_filename); 168 | } 169 | } 170 | return 0; 171 | } 172 | 173 | 174 | -------------------------------------------------------------------------------- /12-Memory Moutain/slp-week12-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/12-Memory Moutain/slp-week12-homework.doc -------------------------------------------------------------------------------- /12-Memory Moutain/slp-week12-lab.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/12-Memory Moutain/slp-week12-lab.zip -------------------------------------------------------------------------------- /13.1-Cache Miss Rate/slp-week13.1-classwork.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/13.1-Cache Miss Rate/slp-week13.1-classwork.docx -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice1/Cache miss rate calculation.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/13.2-Cache Aware Programming/slp-week13-lab/practice1/Cache miss rate calculation.doc -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/cache.c: -------------------------------------------------------------------------------- 1 | /* Cache simulator: 2 | Simulates 4-way set-associative cache, using LRU for replacement policy 3 | Cache parameters configured at compile time */ 4 | 5 | 6 | #include "cache.h" 7 | #include "defs.h" 8 | #include "math.h" 9 | 10 | /* cache parameters */ 11 | #define CACHE_SIZE 16384 /* 16KB cache */ 12 | #define SET_ASSOCIATIVITY 1 /* 4-way set associative */ 13 | #define BLOCK_SIZE 32 /* 32-byte lines */ 14 | 15 | 16 | 17 | /* By default, configured for 16KB cache with 32B block size */ 18 | static int block_bits = 5; 19 | static int set_bits = 9; //log(CACHE_SIZE/SET_ASSOCIATIVITY/BLOCK_SIZE); 20 | 21 | #define MAX_SET_COUNT (1 << 10) 22 | 23 | 24 | //#define BLOCK_SIZE (1<<(block_bits)) 25 | #define SET_COUNT (1<<(set_bits)) 26 | #define SET_MASK (SET_COUNT-1) 27 | 28 | /* Get cache index from address */ 29 | #define GET_INDEX(addr) (SET_MASK & ((unsigned) (addr) >> block_bits)) 30 | /* Get cache tag from address */ 31 | #define GET_TAG(addr) ((unsigned) (addr) >> (block_bits + set_bits)) 32 | 33 | static unsigned tags[MAX_SET_COUNT][SET_ASSOCIATIVITY]; 34 | 35 | static int read_misses = 0; 36 | static int reads = 0; 37 | static int write_misses = 0; 38 | static int writes = 0; 39 | 40 | 41 | 42 | void set_cache_measurement_enabled(int enabled) { 43 | return; 44 | } 45 | 46 | 47 | 48 | /* Reset cache statistics without clearing cache */ 49 | void clear_cache_statistics() 50 | { 51 | read_misses = 0; 52 | reads = 0; 53 | write_misses = 0; 54 | writes = 0; 55 | } 56 | 57 | /* Create empty cache with #sets = 2^s_bits, block size = 2^b_bits */ 58 | void reset_cache(void) 59 | { 60 | clear_cache_statistics(); 61 | reset_cache2(set_bits, block_bits); 62 | } 63 | 64 | void reset_cache2(int s_bits, int b_bits) 65 | { 66 | int i, j; 67 | set_bits = s_bits; 68 | block_bits = b_bits; 69 | for (i = 0; i < SET_COUNT; i++) { 70 | for( j=0; j0 ; j-- ) { 121 | tags[tindex][j] = tags[tindex][j-1]; 122 | } 123 | tags[tindex][0] = tag; 124 | return; 125 | } 126 | } 127 | read_misses++; 128 | for(j=SET_ASSOCIATIVITY-1; j>0; j--) { 129 | tags[tindex][j] = tags[tindex][j-1]; 130 | } 131 | tags[tindex][0] = tag; 132 | return; 133 | } 134 | 135 | static void cache_write(int *addr) 136 | { 137 | int i, j; 138 | unsigned tindex = GET_INDEX(addr); 139 | unsigned tag = GET_TAG(addr); 140 | writes++; 141 | for(i=0; i0 ; j-- ) { 144 | tags[tindex][j] = tags[tindex][j-1]; 145 | } 146 | tags[tindex][0] = tag; 147 | return; 148 | } 149 | } 150 | write_misses++; 151 | for(j=SET_ASSOCIATIVITY-1; j>0; j--) { 152 | tags[tindex][j] = tags[tindex][j-1]; 153 | } 154 | tags[tindex][0] = tag; 155 | return; 156 | } 157 | 158 | void cache_copy(pixel* daddr, pixel* saddr) 159 | { 160 | cache_read((int*) saddr); 161 | cache_write((int*) daddr); 162 | *daddr = *saddr; 163 | } 164 | 165 | #define ps pixel* 166 | void cache_smooth(ps dst,ps s1,ps s2,ps s3,ps s4,ps s5,ps s6,ps s7,ps s8,ps s9) 167 | { 168 | int red=0, green=0, blue=0, i; 169 | pixel* src[] = {s1, s2, s3, s4, s5, s6, s7, s8, s9}; 170 | pixel p; 171 | for( i=0; i < 5; i++) { 172 | cache_read((int*)src[i]); 173 | red += src[i]->red; 174 | green += src[i]->green; 175 | blue += src[i]->blue; 176 | } 177 | cache_write((int*)dst); 178 | p.red = red/5; 179 | p.green = green/5; 180 | p.blue = blue/5; 181 | *dst = p; 182 | } 183 | #undef ps 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/cache.h: -------------------------------------------------------------------------------- 1 | /* For cache simulator */ 2 | #ifndef CACHE_H 3 | #define CACHE_H 4 | 5 | #include "defs.h" 6 | 7 | 8 | void set_cache_measurement_enabled(int enabled); 9 | 10 | /* Create empty cache with #sets = 2^s_bits, block size = 2^b_bits */ 11 | void reset_cache(void); 12 | void reset_cache2(int s_bits, int b_bits); 13 | 14 | /* Reset cache statistics without clearing cache */ 15 | void clear_cache_statistics(); 16 | 17 | void cache_copy(pixel* daddr, pixel* saddr); 18 | void cache_smooth(pixel* dst, pixel* s1, pixel* s2, pixel* s3, pixel* s4, pixel* s5, pixel* s6, pixel* s7, pixel* s8, pixel* s9); 19 | 20 | int get_read_count(); 21 | int get_write_count(); 22 | int get_read_miss_count(); 23 | int get_write_miss_count(); 24 | 25 | double get_read_miss_rate(); 26 | double get_write_miss_rate(); 27 | 28 | double get_miss_rate(); 29 | 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | defs.h 4 | 5 | Useful definitions for Exercise 5. 6 | 7 | DO NOT MODIFY ANYTHING IN THIS FILE 8 | 9 | */ 10 | 11 | #ifndef _DEFS_H_ 12 | #define _DEFS_H_ 13 | 14 | #include 15 | 16 | #define PIXEL(i,j,n) ((i%n)*(n)+(j%n)) 17 | 18 | #define COPY(daddr, saddr) cache_copy(daddr, saddr) 19 | #define SMOOTH(d, s1, s2, s3, s4, s5, s6, s7, s8, s9) cache_smooth(d,s1,s2,s3,s4,s5,s6,s7,s8,s9) 20 | #define READ(saddr) cache_read(saddr) 21 | #define WRITE(daddr) cache_write(daddr) 22 | 23 | typedef struct { 24 | unsigned short red : 8; 25 | unsigned short green : 8; 26 | unsigned short blue : 8; 27 | unsigned short alpha : 8; 28 | } pixel; 29 | 30 | 31 | typedef void (*lab_test_func) (int, pixel*, pixel*); 32 | 33 | void rotate(int, pixel *, pixel *); 34 | 35 | void register_rotate_functions(void); 36 | void add_rotate_function(lab_test_func, char*); 37 | void register_smooth_functions(void); 38 | void add_smooth_function(lab_test_func, char*); 39 | 40 | #endif /* _DEFS_H_ */ 41 | -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/rotate.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/rotate.c -------------------------------------------------------------------------------- /13.2-Cache Aware Programming/slp-week13-lab/practice2/cachelab/smooth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "defs.h" 4 | #include "cache.h" 5 | 6 | 7 | 8 | 9 | /* Here is an our naive implementation */ 10 | char smooth_descr[] = "SMOOTH: Naive Row-wise Traversal of src"; 11 | void smooth(int dim, pixel *src, pixel *dst) { 12 | int i, j; 13 | for(i=0; i 2 | #include 3 | #include "getopt.h" 4 | #include "linker.h" 5 | 6 | /*output usage*/ 7 | void display_usage(char *file) 8 | { 9 | fprintf(stderr, "Usage: %s -t test_num -f filename\n", file); 10 | fprintf(stderr, "test_num must be from 1 to 9\n"); 11 | fprintf(stderr, "filename which you want to test, it must be exit!\n"); 12 | } 13 | 14 | int 15 | main(int argc, char *argv[]) 16 | { 17 | int opt; 18 | int test_num; //which file test, it must between 1 and 9 19 | char *file; //the name of file that we test, you can find all test files in the "test" floder 20 | while((opt=getopt(argc, argv, "t:f:"))!=-1) 21 | { 22 | switch(opt) 23 | { 24 | case 't': 25 | test_num = atoi(optarg); 26 | if(test_num<=0||test_num>9) 27 | { 28 | display_usage(argv[0]); 29 | exit(-1); 30 | } 31 | break; 32 | case 'f': 33 | file = optarg; 34 | if(file==NULL) 35 | { 36 | display_usage(argv[0]); 37 | exit(-1); 38 | } 39 | break; 40 | default: /*'?'*/ 41 | display_usage(argv[0]); 42 | exit(-1); 43 | } 44 | } 45 | //link module 46 | link(test_num, file); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/output-5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/output-5.txt -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/tailor.h: -------------------------------------------------------------------------------- 1 | /* tailor.h -- target dependent definitions 2 | * Copyright (C) 1992-1993 Jean-loup Gailly. 3 | * This is free software; you can redistribute it and/or modify it under the 4 | * terms of the GNU General Public License, see the file COPYING. 5 | */ 6 | 7 | /* The target dependent definitions should be defined here only. 8 | * The target dependent functions should be defined in tailor.c. 9 | */ 10 | 11 | /* $Id: tailor.h,v 0.18 1993/06/14 19:32:20 jloup Exp $ */ 12 | 13 | #if defined(__MSDOS__) && !defined(MSDOS) 14 | # define MSDOS 15 | #endif 16 | 17 | #if defined(__OS2__) && !defined(OS2) 18 | # define OS2 19 | #endif 20 | 21 | #if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */ 22 | # undef MSDOS 23 | #endif 24 | 25 | #ifdef MSDOS 26 | # ifdef __GNUC__ 27 | /* DJGPP version 1.09+ on MS-DOS. 28 | * The DJGPP 1.09 stat() function must be upgraded before gzip will 29 | * fully work. 30 | * No need for DIRENT, since defines POSIX_SOURCE which 31 | * implies DIRENT. 32 | */ 33 | # define near 34 | # else 35 | # define MAXSEG_64K 36 | # ifdef __TURBOC__ 37 | # define NO_OFF_T 38 | # ifdef __BORLANDC__ 39 | # define DIRENT 40 | # else 41 | # define NO_UTIME 42 | # endif 43 | # else /* MSC */ 44 | # define HAVE_SYS_UTIME_H 45 | # define NO_UTIME_H 46 | # endif 47 | # endif 48 | # define PATH_SEP2 '\\' 49 | # define PATH_SEP3 ':' 50 | # define MAX_PATH_LEN 128 51 | # define NO_MULTIPLE_DOTS 52 | # define MAX_EXT_CHARS 3 53 | # define Z_SUFFIX "z" 54 | # define NO_CHOWN 55 | # define PROTO 56 | # define STDC_HEADERS 57 | # define NO_SIZE_CHECK 58 | # define casemap(c) tolow(c) /* Force file names to lower case */ 59 | # include 60 | # define OS_CODE 0x00 61 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 62 | # if !defined(NO_ASM) && !defined(ASMV) 63 | # define ASMV 64 | # endif 65 | #else 66 | # define near 67 | #endif 68 | 69 | #ifdef OS2 70 | # define PATH_SEP2 '\\' 71 | # define PATH_SEP3 ':' 72 | # define MAX_PATH_LEN 260 73 | # ifdef OS2FAT 74 | # define NO_MULTIPLE_DOTS 75 | # define MAX_EXT_CHARS 3 76 | # define Z_SUFFIX "z" 77 | # define casemap(c) tolow(c) 78 | # endif 79 | # define NO_CHOWN 80 | # define PROTO 81 | # define STDC_HEADERS 82 | # include 83 | # define OS_CODE 0x06 84 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 85 | # ifdef _MSC_VER 86 | # define HAVE_SYS_UTIME_H 87 | # define NO_UTIME_H 88 | # define MAXSEG_64K 89 | # undef near 90 | # define near _near 91 | # endif 92 | # ifdef __EMX__ 93 | # define HAVE_SYS_UTIME_H 94 | # define NO_UTIME_H 95 | # define DIRENT 96 | # define EXPAND(argc,argv) \ 97 | {_response(&argc, &argv); _wildcard(&argc, &argv);} 98 | # endif 99 | # ifdef __BORLANDC__ 100 | # define DIRENT 101 | # endif 102 | # ifdef __ZTC__ 103 | # define NO_DIR 104 | # define NO_UTIME_H 105 | # include 106 | # define EXPAND(argc,argv) \ 107 | {response_expand(&argc, &argv);} 108 | # endif 109 | #endif 110 | 111 | #ifdef WIN32 /* Windows NT */ 112 | # define HAVE_SYS_UTIME_H 113 | # define NO_UTIME_H 114 | # define PATH_SEP2 '\\' 115 | # define PATH_SEP3 ':' 116 | # define MAX_PATH_LEN 260 117 | # define NO_CHOWN 118 | # define PROTO 119 | # define STDC_HEADERS 120 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 121 | # include 122 | # include 123 | # ifdef NTFAT 124 | # define NO_MULTIPLE_DOTS 125 | # define MAX_EXT_CHARS 3 126 | # define Z_SUFFIX "z" 127 | # define casemap(c) tolow(c) /* Force file names to lower case */ 128 | # endif 129 | # define OS_CODE 0x0b 130 | #endif 131 | 132 | #ifdef MSDOS 133 | # ifdef __TURBOC__ 134 | # include 135 | # define DYN_ALLOC 136 | /* Turbo C 2.0 does not accept static allocations of large arrays */ 137 | void * fcalloc (unsigned items, unsigned size); 138 | void fcfree (void *ptr); 139 | # else /* MSC */ 140 | # include 141 | # define fcalloc(nitems,itemsize) halloc((long)(nitems),(itemsize)) 142 | # define fcfree(ptr) hfree(ptr) 143 | # endif 144 | #else 145 | # ifdef MAXSEG_64K 146 | # define fcalloc(items,size) calloc((items),(size)) 147 | # else 148 | # define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size)) 149 | # endif 150 | # define fcfree(ptr) free(ptr) 151 | #endif 152 | 153 | #if defined(VAXC) || defined(VMS) 154 | # define PATH_SEP ']' 155 | # define PATH_SEP2 ':' 156 | # define SUFFIX_SEP ';' 157 | # define NO_MULTIPLE_DOTS 158 | # define Z_SUFFIX "-gz" 159 | # define RECORD_IO 1 160 | # define casemap(c) tolow(c) 161 | # define OS_CODE 0x02 162 | # define OPTIONS_VAR "GZIP_OPT" 163 | # define STDC_HEADERS 164 | # define NO_UTIME 165 | # define EXPAND(argc,argv) vms_expand_args(&argc,&argv); 166 | # include 167 | # define unlink delete 168 | # ifdef VAXC 169 | # define NO_FCNTL_H 170 | # include 171 | # endif 172 | #endif 173 | 174 | #ifdef AMIGA 175 | # define PATH_SEP2 ':' 176 | # define STDC_HEADERS 177 | # define OS_CODE 0x01 178 | # define ASMV 179 | # ifdef __GNUC__ 180 | # define DIRENT 181 | # define HAVE_UNISTD_H 182 | # else /* SASC */ 183 | # define NO_STDIN_FSTAT 184 | # define SYSDIR 185 | # define NO_SYMLINK 186 | # define NO_CHOWN 187 | # define NO_FCNTL_H 188 | # include /* for read() and write() */ 189 | # define direct dirent 190 | extern void _expand_args(int *argc, char ***argv); 191 | # define EXPAND(argc,argv) _expand_args(&argc,&argv); 192 | # undef O_BINARY /* disable useless --ascii option */ 193 | # endif 194 | #endif 195 | 196 | #if defined(ATARI) || defined(atarist) 197 | # ifndef STDC_HEADERS 198 | # define STDC_HEADERS 199 | # define HAVE_UNISTD_H 200 | # define DIRENT 201 | # endif 202 | # define ASMV 203 | # define OS_CODE 0x05 204 | # ifdef TOSFS 205 | # define PATH_SEP2 '\\' 206 | # define PATH_SEP3 ':' 207 | # define MAX_PATH_LEN 128 208 | # define NO_MULTIPLE_DOTS 209 | # define MAX_EXT_CHARS 3 210 | # define Z_SUFFIX "z" 211 | # define NO_CHOWN 212 | # define casemap(c) tolow(c) /* Force file names to lower case */ 213 | # define NO_SYMLINK 214 | # endif 215 | #endif 216 | 217 | #ifdef MACOS 218 | # define PATH_SEP ':' 219 | # define DYN_ALLOC 220 | # define PROTO 221 | # define NO_STDIN_FSTAT 222 | # define NO_CHOWN 223 | # define NO_UTIME 224 | # define chmod(file, mode) (0) 225 | # define OPEN(name, flags, mode) open(name, flags) 226 | # define OS_CODE 0x07 227 | # ifdef MPW 228 | # define isatty(fd) ((fd) <= 2) 229 | # endif 230 | #endif 231 | 232 | #ifdef __50SERIES /* Prime/PRIMOS */ 233 | # define PATH_SEP '>' 234 | # define STDC_HEADERS 235 | # define NO_MEMORY_H 236 | # define NO_UTIME_H 237 | # define NO_UTIME 238 | # define NO_CHOWN 239 | # define NO_STDIN_FSTAT 240 | # define NO_SIZE_CHECK 241 | # define NO_SYMLINK 242 | # define RECORD_IO 1 243 | # define casemap(c) tolow(c) /* Force file names to lower case */ 244 | # define put_char(c) put_byte((c) & 0x7F) 245 | # define get_char(c) ascii2pascii(get_byte()) 246 | # define OS_CODE 0x0F /* temporary, subject to change */ 247 | # ifdef SIGTERM 248 | # undef SIGTERM /* We don't want a signal handler for SIGTERM */ 249 | # endif 250 | #endif 251 | 252 | #if defined(pyr) && !defined(NOMEMCPY) /* Pyramid */ 253 | # define NOMEMCPY /* problem with overlapping copies */ 254 | #endif 255 | 256 | #ifdef TOPS20 257 | # define OS_CODE 0x0a 258 | #endif 259 | 260 | #ifndef unix 261 | # define NO_ST_INO /* don't rely on inode numbers */ 262 | #endif 263 | 264 | 265 | /* Common defaults */ 266 | 267 | #ifndef OS_CODE 268 | # define OS_CODE 0x03 /* assume Unix */ 269 | #endif 270 | 271 | #ifndef PATH_SEP 272 | # define PATH_SEP '/' 273 | #endif 274 | 275 | #ifndef casemap 276 | # define casemap(c) (c) 277 | #endif 278 | 279 | #ifndef OPTIONS_VAR 280 | # define OPTIONS_VAR "GZIP" 281 | #endif 282 | 283 | #ifndef Z_SUFFIX 284 | # define Z_SUFFIX ".gz" 285 | #endif 286 | 287 | #ifdef MAX_EXT_CHARS 288 | # define MAX_SUFFIX MAX_EXT_CHARS 289 | #else 290 | # define MAX_SUFFIX 30 291 | #endif 292 | 293 | #ifndef MAKE_LEGAL_NAME 294 | # ifdef NO_MULTIPLE_DOTS 295 | # define MAKE_LEGAL_NAME(name) make_simple_name(name) 296 | # else 297 | # define MAKE_LEGAL_NAME(name) 298 | # endif 299 | #endif 300 | 301 | #ifndef MIN_PART 302 | # define MIN_PART 3 303 | /* keep at least MIN_PART chars between dots in a file name. */ 304 | #endif 305 | 306 | #ifndef EXPAND 307 | # define EXPAND(argc,argv) 308 | #endif 309 | 310 | #ifndef RECORD_IO 311 | # define RECORD_IO 0 312 | #endif 313 | 314 | #ifndef SET_BINARY_MODE 315 | # define SET_BINARY_MODE(fd) 316 | #endif 317 | 318 | #ifndef OPEN 319 | # define OPEN(name, flags, mode) open(name, flags, mode) 320 | #endif 321 | 322 | #ifndef get_char 323 | # define get_char() get_byte() 324 | #endif 325 | 326 | #ifndef put_char 327 | # define put_char(c) put_byte(c) 328 | #endif 329 | 330 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-1.txt: -------------------------------------------------------------------------------- 1 | 1 xy 2 2 | 1 z 4 3 | 5 R 1004 I 5678 E 2777 R 8002 E 7002 4 | 5 | 0 6 | 1 z 3 7 | 6 R 8001 E 1777 E 1001 E 3002 R 1002 A 1010 8 | 9 | 0 10 | 1 z 1 11 | 2 R 5001 E 4777 12 | 13 | 1 z 2 14 | 1 xy 2 15 | 3 A 8000 E 1777 E 2001 16 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-2.txt: -------------------------------------------------------------------------------- 1 | 1 xy 2 | 2 3 | 1 z 4 5 4 | R 1004 5 | I 6 | 5678 E 2777 R 8002 E 7002 7 | 0 8 | 1 z 3 9 | 6 R 8001 10 | E 1777 E 1001 E 3002 R 1002 A 1010 11 | 0 1 z 1 12 | 2 R 5001 E 4777 1 z 2 1 xy 2 13 | 3 A 8000 E 1777 14 | 15 | 16 | 17 | E 2001 18 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-3.txt: -------------------------------------------------------------------------------- 1 | 3 X11 6 X12 8 X13 9 2 | 2 X22 5 X31 3 3 | 10 R 1000 E 1777 E 1777 E 1001 E 1002 E 1004 A 1006 R 1007 A 1008 R 1009 4 | 5 | 3 X21 0 X22 2 X23 5 6 | 3 X11 3 X13 4 X31 7 7 | 8 E 2777 E 2777 R 2002 E 2001 E 2006 R 2005 E 2000 E 2777 8 | 9 | 1 X31 2 10 | 0 11 | 3 A 3000 I 3701 A 3002 12 | 13 | 0 14 | 3 X31 1 X11 2 X22 5 15 | 6 R 4000 E 4777 E 4777 R 4003 R 4004 E 4777 16 | 17 | 0 18 | 0 19 | 3 R 5000 I 5987 R 5002 20 | 21 | 1 X61 2 22 | 1 X31 1 23 | 6 R 6000 E 6777 A 6002 A 6003 R 6004 I 6005 24 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-4.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 X21 2 3 | 3 E 1001 E 1777 E 1000 4 | 5 | 1 X21 0 6 | 0 7 | 1 A 2456 8 | 9 | 1 X21 1 10 | 0 11 | 1 I 3456 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-5.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 X21 2 3 | 3 E 1001 E 1777 E 1000 4 | 5 | 0 6 | 0 7 | 1 A 2456 8 | 9 | 1 X31 0 10 | 0 11 | 1 I 3456 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-6.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 X21 2 3 | 3 E 1001 E 1777 E 1000 4 | 5 | 1 X21 1 6 | 0 7 | 1 A 2456 8 | 9 | 1 X31 0 10 | 0 11 | 1 I 3456 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-7.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 X21 2 3 | 3 E 1555 E 1777 E 1000 4 | 5 | 1 X21 0 6 | 0 7 | 1 A 2456 8 | 9 | 1 X31 0 10 | 0 11 | 1 R 3000 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-8.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 X21 0 3 | 3 E 1001 E 1777 E 1000 4 | 5 | 1 X21 0 6 | 0 7 | 1 A 2456 8 | 9 | 1 X21 1 10 | 0 11 | 1 I 3456 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/input-9.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 A 2009 4 | 5 | 0 6 | 1 X31 2 7 | 4 R 2001 E 2777 A 2003 I 2000 8 | 9 | 1 X31 0 10 | 0 11 | 1 R 3000 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-1.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | xy=2 3 | z=15 4 | 5 | Memory Map 6 | 0: 1004 7 | 1: 5678 8 | 2: 2015 9 | 3: 8002 10 | 4: 7015 11 | 5: 8006 12 | 6: 1015 13 | 7: 1015 14 | 8: 3015 15 | 9: 1007 16 | 10: 1010 17 | 11: 5012 18 | 12: 4015 19 | 13: 8000 20 | 14: 1002 21 | 15: 2002 22 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-2.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | xy=2 3 | z=15 4 | 5 | Memory Map 6 | 0: 1004 7 | 1: 5678 8 | 2: 2015 9 | 3: 8002 10 | 4: 7015 11 | 5: 8006 12 | 6: 1015 13 | 7: 1015 14 | 8: 3015 15 | 9: 1007 16 | 10: 1010 17 | 11: 5012 18 | 12: 4015 19 | 13: 8000 20 | 14: 1002 21 | 15: 2002 22 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-3.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X11=6 3 | X12=8 4 | X13=9 5 | X21=10 6 | X22=12 7 | X23=15 8 | X31=20 9 | X61=32 10 | 11 | Memory Map 12 | 0: 1000 13 | 1: 1020 14 | 2: 1012 15 | 3: 1020 16 | 4: 1012 17 | 5: 1012 18 | 6: 1006 19 | 7: 1007 20 | 8: 1008 21 | 9: 1009 22 | 10: 2009 23 | 11: 2006 24 | 12: 2012 25 | 13: 2006 26 | 14: 2009 27 | 15: 2015 28 | 16: 2009 29 | 17: 2020 30 | 18: 3000 31 | 19: 3701 32 | 20: 3002 33 | 21: 4021 34 | 22: 4020 35 | 23: 4006 36 | 24: 4024 37 | 25: 4025 38 | 26: 4012 39 | 27: 5027 40 | 28: 5987 41 | 29: 5029 42 | 30: 6030 43 | 31: 6020 44 | 32: 6002 45 | 33: 6003 46 | 34: 6034 47 | 35: 6005 48 | 49 | Warning: X12 was defined in module 1 but never used. 50 | Warning: X21 was defined in module 2 but never used. 51 | Warning: X23 was defined in module 2 but never used. 52 | Warning: X61 was defined in module 6 but never used. 53 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-4.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X21=3 Error: This variable is multiply defined; first value used. 3 | 4 | Memory Map 5 | 0: 1003 6 | 1: 1003 7 | 2: 1003 8 | 3: 2456 9 | 4: 3456 10 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-5.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X31=4 3 | 4 | Memory Map 5 | 0: 1000 Error: X21 is not defined; zero used. 6 | 1: 1000 Error: X21 is not defined; zero used. 7 | 2: 1000 Error: X21 is not defined; zero used. 8 | 3: 2456 9 | 4: 3456 10 | 11 | Warning: X31 was defined in module 3 but never used. 12 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-6.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X21=3 Error: The value of X21 is outside module 2; zero (relative) used 3 | X31=4 4 | 5 | Memory Map 6 | 0: 1003 7 | 1: 1003 8 | 2: 1003 9 | 3: 2456 10 | 4: 3456 11 | 12 | Warning: X31 was defined in module 3 but never used. 13 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-7.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X21=3 3 | X31=4 4 | 5 | Memory Map 6 | 0: 1003 Error: Pointer in use chain exceeds module size; chain terminated. 7 | 1: 1777 Error: E type address not on use chain; treated as I type. 8 | 2: 1003 9 | 3: 2456 10 | 4: 3004 11 | 12 | Warning: X31 was defined in module 3 but never used. 13 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-8.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X21=3 Error: This variable is multiply defined; first value used. 3 | 4 | Memory Map 5 | 0: 1003 6 | 1: 1003 7 | 2: 1000 Error: E type address not on use chain; treated as I type. 8 | 3: 2456 9 | 4: 3456 10 | -------------------------------------------------------------------------------- /14.2-Tiny Linker/slp-week14.2-tiny_linker_lab/tinylinker/test/output-9.txt: -------------------------------------------------------------------------------- 1 | Symbol Table 2 | X31=5 3 | 4 | Memory Map 5 | 0: 2009 6 | 1: 2005 Error: R type address on use chain; treated as E type. 7 | 2: 2005 8 | 3: 2005 Error: A type address on use chain; treated as E type. 9 | 4: 2005 Error: I type address on use chain; treated as E type. 10 | 5: 3005 11 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-homework.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-homework.doc -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.exe -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.ilk -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.pch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.pch -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/TwoThread_RaceCondition.pdb -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/main.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/main.obj -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/vc60.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/vc60.idb -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/Debug/vc60.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/Debug/vc60.pdb -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="TwoThread_RaceCondition" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=TwoThread_RaceCondition - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "TwoThread_RaceCondition.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "TwoThread_RaceCondition.mak" CFG="TwoThread_RaceCondition - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "TwoThread_RaceCondition - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "TwoThread_RaceCondition - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "TwoThread_RaceCondition - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 46 | # ADD RSC /l 0x804 /d "NDEBUG" 47 | BSC32=bscmake.exe 48 | # ADD BASE BSC32 /nologo 49 | # ADD BSC32 /nologo 50 | LINK32=link.exe 51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | 54 | !ELSEIF "$(CFG)" == "TwoThread_RaceCondition - Win32 Debug" 55 | 56 | # PROP BASE Use_MFC 0 57 | # PROP BASE Use_Debug_Libraries 1 58 | # PROP BASE Output_Dir "Debug" 59 | # PROP BASE Intermediate_Dir "Debug" 60 | # PROP BASE Target_Dir "" 61 | # PROP Use_MFC 0 62 | # PROP Use_Debug_Libraries 1 63 | # PROP Output_Dir "Debug" 64 | # PROP Intermediate_Dir "Debug" 65 | # PROP Target_Dir "" 66 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 67 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 68 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 69 | # ADD RSC /l 0x804 /d "_DEBUG" 70 | BSC32=bscmake.exe 71 | # ADD BASE BSC32 /nologo 72 | # ADD BSC32 /nologo 73 | LINK32=link.exe 74 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 75 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 76 | 77 | !ENDIF 78 | 79 | # Begin Target 80 | 81 | # Name "TwoThread_RaceCondition - Win32 Release" 82 | # Name "TwoThread_RaceCondition - Win32 Debug" 83 | # Begin Group "Source Files" 84 | 85 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 86 | # Begin Source File 87 | 88 | SOURCE=.\main.c 89 | # End Source File 90 | # End Group 91 | # Begin Group "Header Files" 92 | 93 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 94 | # End Group 95 | # Begin Group "Resource Files" 96 | 97 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 98 | # End Group 99 | # End Target 100 | # End Project 101 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "TwoThread_RaceCondition"=".\TwoThread_RaceCondition.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.ncb -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.opt -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/TwoThread_RaceCondition.plg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
 4 | 

Build Log

5 |

6 | --------------------Configuration: TwoThread_RaceCondition - Win32 Debug-------------------- 7 |

8 |

Command Lines

9 | Creating temporary file "C:\Users\shuli\AppData\Local\Temp\RSP8111.tmp" with contents 10 | [ 11 | kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/TwoThread_RaceCondition.pdb" /debug /machine:I386 /out:"Debug/TwoThread_RaceCondition.exe" /pdbtype:sept 12 | ".\Debug\main.obj" 13 | ] 14 | Creating command line "link.exe @C:\Users\shuli\AppData\Local\Temp\RSP8111.tmp" 15 |

Output Window

16 | Linking... 17 | 18 | 19 | 20 |

Results

21 | TwoThread_RaceCondition.exe - 0 error(s), 0 warning(s) 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice1/TwoThread/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int count=0; 7 | 8 | void thread1(void* pvoid) 9 | { 10 | int i; 11 | for(i=1;i<1000000;i++) 12 | count ++; 13 | } 14 | 15 | void thread2(void* pvoid) 16 | { 17 | int j; 18 | for(j=1;j<1000000;j++) 19 | count ++; 20 | } 21 | 22 | int main() 23 | { 24 | 25 | _beginthread(thread1,0,NULL); 26 | _beginthread(thread2,0,NULL); 27 | 28 | _sleep(1000); 29 | printf("%d\n",count); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/Thread_Programming.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Thread Programming 4 | 5 | 6 |

 

7 | 8 |

9 |

Thread Programming

10 | 11 |

Getting started

12 | 13 |

You can get the code you need for this part of the lab here. This archive contains the 14 | following files:

15 | 16 |
17 |
RemoteServer.lib
18 |
The remote server library
19 |
tclient.exe
20 |
Your threaded client. Initially, this is identical to sclient.exe. 21 |
22 |
sclient.exe
23 |
The sequential client; just a compilation of the original 24 | code. You will be comparing the performance of your threaded 25 | tclient.exe to this naive sequential solution.
26 |
servers.h
27 |
Public interface to the remote server library
28 |
ThreadedClient.cpp
29 |
The source file for the threaded client. You will be 30 | modifying this file and handing it in.
31 |
ThreadedClient.dsw
32 |
The Visual C++ workspace for this project
33 |
ThreadedClient.dsp
34 |
The Visual C++ project file for this project
35 |
ThreadedClient.ncb
36 |
Visual C++ support file
37 |
ThreadedClient.opt
38 |
Visual C++ support file
39 |
40 | 41 |

Your Task

42 | 43 |

In this part of the lab, you're going to use threads to parallelize the 44 | operation of a very simple database client. This program has a very simple 45 | task: you provide it an account number, and it prints out the personal 46 | and account information of the client corresponding to that number.

47 | 48 |

The business for which you're writing this application has decided to 49 | split the account information into two separate databases: one to 50 | manage client's personal information (which is bulky, but mostly 51 | constant), and one to manage the client's account information (which 52 | is smaller, but changes a lot). The job of the program is to contact 53 | each database, access the information, and print it to the user.

54 | 55 |

Unfortunately, the databases are slow, and your connection to them 56 | isn't good. It can, therefore, take awhile to contact each database, 57 | so in order to make the program respond as quickly as possible, you 58 | have decided to use threaded programming, so that separate threads 59 | can contact the databases in parallel.

60 | 61 |

Your program should work as follows:

62 | 63 |
  1. The main thread retrieves the account number from the command 64 | line.
  2. 65 |
  3. The main thread creates two threads to access the 66 | databases and gives them the account number requested.
  4. 67 |
  5. The database threads contact the databases and get the 68 | results. When they have the results, they pass them to 69 | the main thread and terminate.
  6. 70 |
  7. The main thread waits for the database threads to terminate, 71 | then prints out the results and terminates.
  8. 72 |
73 | 74 |

When compiling this program, you may occasionally receive a linker warning 75 | about conflicts with LIBC. You may safely ignore this warning.

76 | 77 |

Details

78 | 79 |

An existing codebase exists which contacts each database 80 | sequentially and retrieves information from them. You should modify 81 | this program to use threads, but otherwise leave it alone -- the 82 | output should be in the same style, etc.

83 | 84 |

The code for contacting the databases is already written for you, in 85 | the two functions GetPersonalInformation() and 86 | GetAccountInformation(). These functions simulate contacting 87 | a real database server over a slow network connection. Your worker 88 | threads should simply call these functions.

89 | 90 |

To create a thread, use the _beginthread() Windows API 91 | call:

92 | 93 |

unsigned long _beginthread( void (*startpoint)( void * ), unsigned int stacksize, void *arguments )

94 | 95 |

The first argument is a pointer to the function that Windows will call at the 96 | beginning of the thread; when this function returns, the thread will terminate. 97 | This function takes a void * as an argument, and "returns" void; 98 | be sure to specify that it uses __cdecl calling conventions (see example). The 99 | stack size you should provide is 0; Windows interprets this as a special case 100 | meaning "inherit the stack size from the parent thread", which is fine for our 101 | purposes. The third argument is the argument that will be provided to the thread's 102 | main function. For example, if you declare:

103 | 104 |
105 |  /* our thread's starting function; be sure to explicitly
106 |     use __cdecl calling conventions */
107 |  void __cdecl threadfunc( void *args ) {
108 |     int *n = (int *) args;
109 |     cout << "Received %d\n" << *n << endl;
110 | }
111 | 
112 | int main( int argc, char **argv ) {
113 |     HANDLE thread;
114 |     int n = 7;
115 |     thread = (HANDLE) _beginthread( threadfunc, 0, &n );
116 |     if (thread == (HANDLE) -1L) {
117 | 	cerr << "Couldn't create thread!" << endl;
118 | 	exit(1);
119 |     }else {
120 |  	WaitForSingleObject( thread, INFINITE );
121 | 	cout << "Done!" << endl;
122 | 	exit(0);
123 |     }
124 | }
125 | 
126 | 127 |

_beginthread is prototyped to return an unsigned long. 128 | In fact, this unsigned long is equivalent to a handle, which is 129 | a Windows-specific abstraction. A handle represents some sort of 130 | operating-system object, like synchronization primitives and opened 131 | files; in this case, it's a thread handle. We can do all sorts 132 | of interesting things to threads using a thread handle, but here we 133 | just want to wait for the thread to end; we can achieve that using the 134 | WaitForSingleObject call. In the project, you'll want to 135 | wait for any of several handles; this is done using the 136 | WaitForMultipleObjects call:

137 | 138 |

DWORD WaitForMultipleObjects( DWORD count, CONST HANDLE *handles, BOOL wait_all, DWORD timeout )

139 | 140 |

handles points to an array of handles that you're 141 | interested in; the number of elements in the array must be (at least) 142 | count. If wait_all is TRUE, 143 | then WaitForMultipleObjects will wait for all of the 144 | handles to become signalled -- if they're thread handles, for all the 145 | threads to terminate. timeout specifies how long to 146 | wait, in milliseconds; the special value INFINITE means 147 | to wait for all the handles, no matter how long it takes.

148 | 149 |

You should always check your calls for completion. In particular, 150 | _beginthread() can return -1L to signal that it failed to 151 | create a thread. If you make any assumptions in your code, be sure 152 | to state them clearly.

153 | 154 |

Good luck!

155 | 156 |

Evaluation

157 | 158 |

You will be graded on this part of the assignment as follows:

159 | 160 |
  • 6 points for successfully and safely creating the threads.
  • 161 |
  • 6 points for successfully waiting for those threads to complete.
  • 162 |
  • 6 points for successfully passing information between the 163 | threads.
  • 164 |
  • 6 points for style and documentation.
165 | 166 |
167 |
168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/RemoteServer.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice2/handout/RemoteServer.lib -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ThreadedClient.cpp 3 | 4 | A threaded database client. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "servers.h" 10 | 11 | //#ifdef _MSC_VER 12 | #include 13 | #include 14 | #include 15 | typedef __int64 INT64_T; 16 | typedef unsigned __int64 UINT64_T; 17 | 18 | typedef LONGLONG time_ms_t; 19 | 20 | time_ms_t getTimeInMilliseconds() { 21 | SYSTEMTIME stime; 22 | 23 | GetSystemTime( &stime ); 24 | 25 | FILETIME ftime; 26 | LARGE_INTEGER time; 27 | 28 | SystemTimeToFileTime( &stime, &ftime ); /* if this fails... */ 29 | 30 | time.HighPart = ftime.dwHighDateTime; 31 | time.LowPart = ftime.dwLowDateTime; 32 | 33 | /* FileTime is in 100ns intervals since 1/1/1601 */ 34 | return time.QuadPart / 10000; 35 | } 36 | //#endif 37 | 38 | /* 39 | ostream &operator <<( ostream &out, string *str ) { 40 | 41 | Send a string to an output stream. 42 | */ 43 | ostream &operator<<(ostream &out, string *str) { 44 | if (str) 45 | return out << str->data(); 46 | else 47 | return out; 48 | } 49 | 50 | /* 51 | ostream & operator<< ( ostream &out, INT64_T num ) 52 | 53 | Print a 64-bit unsigned integer to the given output stream. 54 | */ 55 | ostream &operator<<( ostream &out, INT64_T snum ) { 56 | #define OSTR_LL_LEN 21 57 | if (snum) { 58 | char buffer[OSTR_LL_LEN]; 59 | int i = OSTR_LL_LEN - 1; 60 | UINT64_T num; 61 | if (snum < 0) num = -snum; else num = snum; 62 | 63 | buffer[i] = '\0'; 64 | while (num) { 65 | buffer[--i] = ('0' + (int) (num % 10)); 66 | num /= 10; 67 | } 68 | if (snum < 0) buffer[--i] = '-'; 69 | return out << buffer + i; 70 | }else return out << '0'; 71 | } 72 | 73 | /* 74 | int main( int argc, char *argv[] 75 | 76 | You should modify this function to use threads. 77 | */ 78 | void retrievePersonalInfo(int account, Personal** pers) { 79 | *pers = GetPersonalInformation(account); 80 | } 81 | 82 | void retrieveAccountInfo(int account, AccountInfo** acct) { 83 | *acct = GetAccountInformation(account); 84 | } 85 | int main( int argc, char *argv[] ) { 86 | if (argc != 2) { 87 | cerr << "usage: " << argv[0] << " [account_number]" << endl; 88 | exit(1); 89 | } 90 | int account = atoi(argv[1]); 91 | 92 | time_ms_t start = getTimeInMilliseconds(); 93 | cout << "Retrieving..."; 94 | cout.flush(); 95 | 96 | Personal* pers = nullptr; 97 | AccountInfo* acct = nullptr; 98 | 99 | std::thread t1(retrievePersonalInfo, account, &pers); 100 | std::thread t2(retrieveAccountInfo, account, &acct); 101 | 102 | t1.join(); 103 | t2.join(); 104 | 105 | time_ms_t end = getTimeInMilliseconds(); 106 | cout << "done (" << end - start << "ms)" << endl; 107 | 108 | if (pers) { 109 | cout << account << ": " << pers->FirstName << " " 110 | << pers->LastName << endl; 111 | cout << pers->Address << endl; 112 | cout << "Balance: " << acct->Balance << ", " << acct->Pending 113 | << " pending, " << acct->Share << " share" << endl; 114 | 115 | delete pers; 116 | delete acct; 117 | } else { 118 | cout << "No client matches that account number" << endl; 119 | } 120 | return 0; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="ThreadedClient" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=ThreadedClient - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "ThreadedClient.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "ThreadedClient.mak" CFG="ThreadedClient - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "ThreadedClient - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "ThreadedClient - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "ThreadedClient - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Ignore_Export_Lib 0 43 | # PROP Target_Dir "" 44 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 46 | # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 | # ADD RSC /l 0x409 /d "NDEBUG" 48 | BSC32=bscmake.exe 49 | # ADD BASE BSC32 /nologo 50 | # ADD BSC32 /nologo 51 | LINK32=link.exe 52 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"tclient.exe" 54 | 55 | !ELSEIF "$(CFG)" == "ThreadedClient - Win32 Debug" 56 | 57 | # PROP BASE Use_MFC 0 58 | # PROP BASE Use_Debug_Libraries 1 59 | # PROP BASE Output_Dir "Debug" 60 | # PROP BASE Intermediate_Dir "Debug" 61 | # PROP BASE Target_Dir "" 62 | # PROP Use_MFC 0 63 | # PROP Use_Debug_Libraries 1 64 | # PROP Output_Dir "Debug" 65 | # PROP Intermediate_Dir "Debug" 66 | # PROP Ignore_Export_Lib 0 67 | # PROP Target_Dir "" 68 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 69 | # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 70 | # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 | # ADD RSC /l 0x409 /d "_DEBUG" 72 | BSC32=bscmake.exe 73 | # ADD BASE BSC32 /nologo 74 | # ADD BSC32 /nologo 75 | LINK32=link.exe 76 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 77 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib RemoteServer.lib /nologo /subsystem:console /debug /machine:I386 /out:"tclient.exe" /pdbtype:sept 78 | 79 | !ENDIF 80 | 81 | # Begin Target 82 | 83 | # Name "ThreadedClient - Win32 Release" 84 | # Name "ThreadedClient - Win32 Debug" 85 | # Begin Group "Source Files" 86 | 87 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 88 | # Begin Source File 89 | 90 | SOURCE=.\ThreadedClient.cpp 91 | 92 | !IF "$(CFG)" == "ThreadedClient - Win32 Release" 93 | 94 | !ELSEIF "$(CFG)" == "ThreadedClient - Win32 Debug" 95 | 96 | # ADD CPP /MTd 97 | 98 | !ENDIF 99 | 100 | # End Source File 101 | # End Group 102 | # Begin Group "Header Files" 103 | 104 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 105 | # Begin Source File 106 | 107 | SOURCE=..\RemoteServer\servers.h 108 | # End Source File 109 | # End Group 110 | # Begin Group "Resource Files" 111 | 112 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 113 | # End Group 114 | # End Target 115 | # End Project 116 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "ThreadedClient"=".\ThreadedClient.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.ncb -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice2/handout/ThreadedClient.opt -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/sclient.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/15-Exception/slp-week15-lab/practice2/handout/sclient.exe -------------------------------------------------------------------------------- /15-Exception/slp-week15-lab/practice2/handout/servers.h: -------------------------------------------------------------------------------- 1 | /* 2 | servers.h 3 | 4 | Open a TCP/IP connection to a server, request the specified 5 | information, and return the information required in a struct. 6 | */ 7 | #include 8 | using namespace std; 9 | 10 | /* 11 | Personal 12 | 13 | Personal information about the owner of an account. 14 | */ 15 | struct Personal { 16 | Personal( int account, string *firstname, string *lastname, 17 | string *address ) { 18 | 19 | FirstName = firstname; 20 | LastName = lastname; 21 | Account = account; 22 | Address = address; 23 | } 24 | ~Personal() { 25 | delete FirstName; 26 | delete LastName; 27 | delete Address; 28 | } 29 | string *FirstName; 30 | string *LastName; 31 | string *Address; 32 | int Account; 33 | }; 34 | 35 | /* 36 | Personal *GetPersonalInformation( int account ) 37 | 38 | Retrieve personal information about the user of a certain account. 39 | Return NULL if there is no such account. 40 | */ 41 | Personal *GetPersonalInformation( int account ); 42 | 43 | /* 44 | AccountInfo 45 | 46 | A struct to hold account-related information. 47 | */ 48 | struct AccountInfo { 49 | AccountInfo( int account, int balance_in_cents, int share, int pending ) { 50 | Account = account; 51 | Balance = balance_in_cents; 52 | Share = share; 53 | Pending = pending; 54 | } 55 | int Account; 56 | int Balance; 57 | int Share; 58 | int Pending; 59 | }; 60 | 61 | AccountInfo *GetAccountInformation( int account ); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CMU-CSAPP-Lab 2 | 四川大学舒莉系统级编程课程配套实验 3 | 4 | ## 目的 5 | 舒莉的实验真的是又多又难,网上的资料也是良莠不齐,让人无从下手,所以我就自己整理了一份,仅供参考,如果能对你有些许帮助,不胜感激。 6 | 7 | ## 总结 8 | 终于完成这一学期的学习了,实验是真的很费时间也很难做,到后面就是各种在网上找答案,还找不到😓,这资料比我都老。有的实验根本就做不了,只能照抄别人的,也勉强交上去了。如果认认真真的从头做一遍,收获应该会很多,但是谁有那么多时间呢😊?这些作业的平均分在95左右,当然我自知其中的水分,许多仅仅是满足“能交”的要求,其中的许多纰漏、瑕疵,我并没有能力和时间去修改。所以说这份资料也是希望仅起到参考的作用,更高的要求还得靠你们来实现! 9 | 10 | 2023-12-20 21:02 11 | -------------------------------------------------------------------------------- /slp-week01.0-e-20230824.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week01.0-e-20230824.pptx -------------------------------------------------------------------------------- /slp-week01.1-e.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week01.1-e.ppt -------------------------------------------------------------------------------- /slp-week02-e.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week02-e.pptx -------------------------------------------------------------------------------- /slp-week03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week03.pdf -------------------------------------------------------------------------------- /slp-week04.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week04.pptx -------------------------------------------------------------------------------- /slp-week05.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week05.pptx -------------------------------------------------------------------------------- /slp-week06-231011.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week06-231011.pptx -------------------------------------------------------------------------------- /slp-week07.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week07.pdf -------------------------------------------------------------------------------- /slp-week08.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week08.pdf -------------------------------------------------------------------------------- /slp-week09.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week09.pdf -------------------------------------------------------------------------------- /slp-week10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week10.pdf -------------------------------------------------------------------------------- /slp-week11.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week11.ppt -------------------------------------------------------------------------------- /slp-week12.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week12.pptx -------------------------------------------------------------------------------- /slp-week13.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/slp-week13.ppt -------------------------------------------------------------------------------- /平时mq试题及答案/mq01.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq01.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq02.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq02.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq03.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq03.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq04.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq04.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq05.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq05.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq06.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq06.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq07.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq07.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq08.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq08.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq09.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq09.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq10.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq10.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq11.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq11.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq12.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq12.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq13.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq13.doc -------------------------------------------------------------------------------- /平时mq试题及答案/mq14.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/平时mq试题及答案/mq14.doc -------------------------------------------------------------------------------- /系统级编程选择题.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jzxcvbnm/CMU-CSAPP-Lab/9deb65ccdb076f27a074ee4c50d05f0f5e22397f/系统级编程选择题.pdf --------------------------------------------------------------------------------