├── HIT-ICS2019大作业报告.doc ├── HIT-ICS2019大作业要求.ppt ├── README.md ├── exam ├── ics2017aa .doc ├── ics2018aa.docx ├── ics2021aa .doc ├── 计算机系统2019A参考答案 .doc └── 计算机系统样卷2017A无答案.pdf ├── final homework ├── 1183200123+ICS2019大作业.zip ├── ICS大作业论文.docx ├── hell1o1.elf ├── hello ├── hello.c ├── hello.elf ├── hello.i ├── hello.o ├── hello.s ├── hello1.s ├── hello2.s ├── 自媒体地址.txt └── 自媒体截图.jpg ├── homework ├── homework 2 │ ├── 2.55.c │ ├── 2.59.c │ ├── 2.63.c │ ├── 2.67.c │ ├── 2.71.c │ ├── 2.75.c │ ├── 2.79.c │ ├── 2.95.c │ └── homework2.doc ├── homework 3 │ └── 祁天-1183200123.doc ├── homework 4+5.doc ├── homework 6+7.doc └── homework 8+9 │ ├── homework 8+9.doc │ └── homework 8+9.pdf ├── lab ├── lab1 │ ├── cpuwordsize │ │ ├── cpuwordsize.c │ │ ├── cpuwordsize.exe │ │ └── cpuwordsize.o │ ├── datetype │ │ ├── datetype.c │ │ ├── datetype.exe │ │ └── datetype.o │ ├── float │ │ ├── float.c │ │ ├── float.exe │ │ └── float.o │ ├── hello.i │ ├── hello.o │ ├── hello.out │ ├── hello.s │ ├── hellolinux.c │ ├── hellowin.c │ ├── isLittleEndian │ │ ├── isLittleEndian.c │ │ ├── isLittleEndian.exe │ │ └── isLittleEndian.o │ ├── sum │ │ ├── sum.c │ │ ├── sum.exe │ │ └── sum.o │ └── 祁天 实验报告.doc ├── lab2 │ ├── C程序 │ │ ├── cs_atof.c │ │ ├── cs_atoi.c │ │ ├── cs_ftoa.c │ │ ├── cs_itoa.c │ │ ├── fib_dg.c │ │ ├── fib_loop.c │ │ ├── float0.c │ │ ├── floatx.c │ │ ├── utf8len.c │ │ └── 验证向偶数舍入.c │ └── 祁天-lab2实验报告.doc ├── lab3 │ ├── 祁天-1183200123-bomb ans.txt │ ├── 祁天-1183200123.doc │ └── 祁天-1183200123.pdf ├── lab4 │ ├── 1803003_1183200123_祁天.doc │ ├── 1803003_1183200123_祁天.pdf │ ├── bang_1183200123.txt │ ├── bang_1183200123_raw.txt │ ├── boom_1183200123.txt │ ├── boom_1183200123_raw.txt │ ├── fizz_1183200123.txt │ ├── fizz_1183200123_raw.txt │ ├── nitro_1183200123.txt │ ├── smoke_1183200123.txt │ └── smoke_1183200123_raw.txt ├── lab5 │ ├── main.o │ ├── phase1.o │ ├── phase2.o │ ├── phase3.o │ ├── phase3_patch.c │ ├── phase3_patch.o │ ├── phase4.o │ ├── phase5.o │ ├── 祁天-1183200123.doc │ └── 祁天-1183200123.pdf ├── lab6 │ ├── 1183200123-祁天.tar │ ├── 祁天-1183200123-lab6实验报告.doc │ └── 祁天-1183200123-lab6实验报告.pdf ├── lab7 │ ├── HITICS-Lab7-shell.pptx │ ├── lab7实验报告.doc │ ├── lab7实验报告.pdf │ └── tsh.c └── lab8 │ ├── mm.c │ ├── 实验报告.doc │ └── 实验报告.pdf ├── note ├── chapter 2.doc ├── chapter 3.doc ├── chapter 8.doc └── chapter 9.doc ├── pku └── 2016ICS期中.pdf ├── sjtu slides ├── 1-intro.ppt ├── 10-array.ppt ├── 11-x64.ppt ├── 12-fp.ppt ├── 13-round.ppt ├── 14-y86.ppt ├── 15-logical.ppt ├── 16-seq.ppt ├── 17-seq2.ppt ├── 18-seq3.ppt ├── 19-pipe.ppt ├── 2-bits.ppt ├── 20-dhazard.ppt ├── 21-chazard.ppt ├── 22-exception.ppt ├── 23-mio.ppt ├── 24-tuning.ppt ├── 25-opt.ppt ├── 26-ram.ppt ├── 27-locality.ppt ├── 28-cache.ppt ├── 29-misc.ppt ├── 3-bops.ppt ├── 4-encoding.ppt ├── 5-arith.ppt ├── 6-move.ppt ├── 7-cc.ppt ├── 8-control.ppt └── 9-call.ppt ├── slides ├── HIT-ICS第10章 系统级IO.ppt ├── HIT-ICS第1章 课程概述.pptx ├── HIT-ICS第2章 信息的表示和处理Ⅰ:位、整数.pptx ├── HIT-ICS第2章 信息的表示和处理Ⅱ:浮点数.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part01-s (2).pptx ├── HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part02.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part03.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅱ:控制.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅲ:过程.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅳ:数据.pptx ├── HIT-ICS第3章 程序的机器级表示Ⅴ:高级主题.pptx ├── HIT-ICS第4章 处理器体系结构-L1-指令集体系结构.pptx ├── HIT-ICS第4章 处理器体系结构-L2 逻辑设计.pptx ├── HIT-ICS第4章 处理器体系结构-L3-顺序执行的处理器 (1).pptx ├── HIT-ICS第4章 处理器体系结构-L4-流水线的实现基础.pptx ├── HIT-ICS第4章 处理器体系结构-L5-流水线实现的高级技术.pptx ├── HIT-ICS第5章-优化.pptx ├── HIT-ICS第6章- L1 存储器层级结构与局部性.pptx ├── HIT-ICS第6章- L2 高速缓冲器Cache.pptx ├── HIT-ICS第7章- 连接.pptx ├── HIT-ICS第8章 异常控制流 L1异常与进程.pptx ├── HIT-ICS第8章 异常控制流 L2信号与非本地跳转.pptx ├── HIT-ICS第9章 L1虚拟内存-概念.ppt ├── HIT-ICS第9章 L2虚拟内存-系统.pptx ├── HIT-ICS第9章 L3动态内存分配-基本概念.ppt └── HIT-ICS第9章 L4动态内存分配-高级概念.ppt ├── 共享指令.txt └── 深入理解Linux内核.pdf /HIT-ICS2019大作业报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/HIT-ICS2019大作业报告.doc -------------------------------------------------------------------------------- /HIT-ICS2019大作业要求.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/HIT-ICS2019大作业要求.ppt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ICS(Introduction to Computer System) 2 | 哈工大计算机系统课程资料汇总,包括slides、实验、大作业和期末试题,供学习参考。参考教材《深入理解计算机系统》(csapp) 3 | -------------------------------------------------------------------------------- /exam/ics2017aa .doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/exam/ics2017aa .doc -------------------------------------------------------------------------------- /exam/ics2018aa.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/exam/ics2018aa.docx -------------------------------------------------------------------------------- /exam/ics2021aa .doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/exam/ics2021aa .doc -------------------------------------------------------------------------------- /exam/计算机系统2019A参考答案 .doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/exam/计算机系统2019A参考答案 .doc -------------------------------------------------------------------------------- /exam/计算机系统样卷2017A无答案.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/exam/计算机系统样卷2017A无答案.pdf -------------------------------------------------------------------------------- /final homework/1183200123+ICS2019大作业.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/final homework/1183200123+ICS2019大作业.zip -------------------------------------------------------------------------------- /final homework/ICS大作业论文.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/final homework/ICS大作业论文.docx -------------------------------------------------------------------------------- /final homework/hell1o1.elf: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF64 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: REL (Relocatable file) 9 | Machine: Advanced Micro Devices X86-64 10 | Version: 0x1 11 | Entry point address: 0x0 12 | Start of program headers: 0 (bytes into file) 13 | Start of section headers: 1200 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 64 (bytes) 16 | Size of program headers: 0 (bytes) 17 | Number of program headers: 0 18 | Size of section headers: 64 (bytes) 19 | Number of section headers: 14 20 | Section header string table index: 13 21 | 22 | Section Headers: 23 | [Nr] Name Type Address Offset 24 | Size EntSize Flags Link Info Align 25 | [ 0] NULL 0000000000000000 00000000 26 | 0000000000000000 0000000000000000 0 0 0 27 | [ 1] .text PROGBITS 0000000000000000 00000040 28 | 000000000000007f 0000000000000000 AX 0 0 1 29 | [ 2] .rela.text RELA 0000000000000000 00000348 30 | 00000000000000d8 0000000000000018 I 11 1 8 31 | [ 3] .data PROGBITS 0000000000000000 000000bf 32 | 0000000000000000 0000000000000000 WA 0 0 1 33 | [ 4] .bss NOBITS 0000000000000000 000000bf 34 | 0000000000000000 0000000000000000 WA 0 0 1 35 | [ 5] .rodata.str1.8 PROGBITS 0000000000000000 000000c0 36 | 0000000000000026 0000000000000001 AMS 0 0 8 37 | [ 6] .rodata.str1.1 PROGBITS 0000000000000000 000000e6 38 | 000000000000000d 0000000000000001 AMS 0 0 1 39 | [ 7] .comment PROGBITS 0000000000000000 000000f3 40 | 0000000000000024 0000000000000001 MS 0 0 1 41 | [ 8] .note.GNU-stack PROGBITS 0000000000000000 00000117 42 | 0000000000000000 0000000000000000 0 0 1 43 | [ 9] .eh_frame PROGBITS 0000000000000000 00000118 44 | 0000000000000040 0000000000000000 A 0 0 8 45 | [10] .rela.eh_frame RELA 0000000000000000 00000420 46 | 0000000000000018 0000000000000018 I 11 9 8 47 | [11] .symtab SYMTAB 0000000000000000 00000158 48 | 00000000000001b0 0000000000000018 12 10 8 49 | [12] .strtab STRTAB 0000000000000000 00000308 50 | 000000000000003d 0000000000000000 0 0 1 51 | [13] .shstrtab STRTAB 0000000000000000 00000438 52 | 0000000000000077 0000000000000000 0 0 1 53 | Key to Flags: 54 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info), 55 | L (link order), O (extra OS processing required), G (group), T (TLS), 56 | C (compressed), x (unknown), o (OS specific), E (exclude), 57 | l (large), p (processor specific) 58 | 59 | There are no section groups in this file. 60 | 61 | There are no program headers in this file. 62 | 63 | There is no dynamic section in this file. 64 | 65 | Relocation section '.rela.text' at offset 0x348 contains 9 entries: 66 | Offset Info Type Sym. Value Sym. Name + Addend 67 | 000000000016 00050000000a R_X86_64_32 0000000000000000 .rodata.str1.8 + 0 68 | 00000000001b 000b00000004 R_X86_64_PLT32 0000000000000000 puts - 4 69 | 000000000025 000c00000004 R_X86_64_PLT32 0000000000000000 exit - 4 70 | 000000000032 00060000000a R_X86_64_32 0000000000000000 .rodata.str1.1 + 0 71 | 000000000041 000d00000004 R_X86_64_PLT32 0000000000000000 __printf_chk - 4 72 | 000000000054 000e00000004 R_X86_64_PLT32 0000000000000000 strtol - 4 73 | 00000000005b 000f00000004 R_X86_64_PLT32 0000000000000000 sleep - 4 74 | 00000000006a 001000000002 R_X86_64_PC32 0000000000000000 stdin - 4 75 | 00000000006f 001100000004 R_X86_64_PLT32 0000000000000000 getc - 4 76 | 77 | Relocation section '.rela.eh_frame' at offset 0x420 contains 1 entry: 78 | Offset Info Type Sym. Value Sym. Name + Addend 79 | 000000000020 000200000002 R_X86_64_PC32 0000000000000000 .text + 0 80 | 81 | The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported. 82 | 83 | Symbol table '.symtab' contains 18 entries: 84 | Num: Value Size Type Bind Vis Ndx Name 85 | 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 86 | 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c 87 | 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 88 | 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 89 | 4: 0000000000000000 0 SECTION LOCAL DEFAULT 4 90 | 5: 0000000000000000 0 SECTION LOCAL DEFAULT 5 91 | 6: 0000000000000000 0 SECTION LOCAL DEFAULT 6 92 | 7: 0000000000000000 0 SECTION LOCAL DEFAULT 8 93 | 8: 0000000000000000 0 SECTION LOCAL DEFAULT 9 94 | 9: 0000000000000000 0 SECTION LOCAL DEFAULT 7 95 | 10: 0000000000000000 127 FUNC GLOBAL DEFAULT 1 main 96 | 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts 97 | 12: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND exit 98 | 13: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __printf_chk 99 | 14: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND strtol 100 | 15: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND sleep 101 | 16: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND stdin 102 | 17: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND getc 103 | 104 | No version information found in this file. 105 | -------------------------------------------------------------------------------- /final homework/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/final homework/hello -------------------------------------------------------------------------------- /final homework/hello.c: -------------------------------------------------------------------------------- 1 | // 大作业的 hello.c 程序 2 | // gcc -m64 -Og -no-pie -fno-PIC hello.c -o hello 3 | // 程序运行过程中可以按键盘,如不停乱按,包括回车,Ctrl-Z,Ctrl-C等。 4 | // 可以 运行 ps jobs pstree fg 等命令 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc,char *argv[]){ 11 | int i; 12 | 13 | if(argc!=4){ 14 | printf("用法: Hello 学号 姓名 秒数!\n"); 15 | exit(1); 16 | } 17 | for(i=0;i<8;i++){ 18 | printf("Hello %s %s\n",argv[1],argv[2]); 19 | sleep(atoi(argv[3])); 20 | } 21 | getchar(); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /final homework/hello.elf: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF64 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: EXEC (Executable file) 9 | Machine: Advanced Micro Devices X86-64 10 | Version: 0x1 11 | Entry point address: 0x401090 12 | Start of program headers: 64 (bytes into file) 13 | Start of section headers: 14760 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 64 (bytes) 16 | Size of program headers: 56 (bytes) 17 | Number of program headers: 10 18 | Size of section headers: 64 (bytes) 19 | Number of section headers: 28 20 | Section header string table index: 27 21 | 22 | Section Headers: 23 | [Nr] Name Type Address Offset 24 | Size EntSize Flags Link Info Align 25 | [ 0] NULL 0000000000000000 00000000 26 | 0000000000000000 0000000000000000 0 0 0 27 | [ 1] .interp PROGBITS 0000000000400270 00000270 28 | 000000000000001c 0000000000000000 A 0 0 1 29 | [ 2] .note.ABI-tag NOTE 000000000040028c 0000028c 30 | 0000000000000020 0000000000000000 A 0 0 4 31 | [ 3] .hash HASH 00000000004002b0 000002b0 32 | 000000000000003c 0000000000000004 A 5 0 8 33 | [ 4] .gnu.hash GNU_HASH 00000000004002f0 000002f0 34 | 0000000000000024 0000000000000000 A 5 0 8 35 | [ 5] .dynsym DYNSYM 0000000000400318 00000318 36 | 00000000000000f0 0000000000000018 A 6 1 8 37 | [ 6] .dynstr STRTAB 0000000000400408 00000408 38 | 0000000000000073 0000000000000000 A 0 0 1 39 | [ 7] .gnu.version VERSYM 000000000040047c 0000047c 40 | 0000000000000014 0000000000000002 A 5 0 2 41 | [ 8] .gnu.version_r VERNEED 0000000000400490 00000490 42 | 0000000000000030 0000000000000000 A 6 1 8 43 | [ 9] .rela.dyn RELA 00000000004004c0 000004c0 44 | 0000000000000048 0000000000000018 A 5 0 8 45 | [10] .rela.plt RELA 0000000000400508 00000508 46 | 0000000000000090 0000000000000018 AI 5 21 8 47 | [11] .init PROGBITS 0000000000401000 00001000 48 | 0000000000000017 0000000000000000 AX 0 0 4 49 | [12] .plt PROGBITS 0000000000401020 00001020 50 | 0000000000000070 0000000000000010 AX 0 0 16 51 | [13] .text PROGBITS 0000000000401090 00001090 52 | 00000000000001d1 0000000000000000 AX 0 0 16 53 | [14] .fini PROGBITS 0000000000401264 00001264 54 | 0000000000000009 0000000000000000 AX 0 0 4 55 | [15] .rodata PROGBITS 0000000000402000 00002000 56 | 000000000000003d 0000000000000000 A 0 0 8 57 | [16] .eh_frame PROGBITS 0000000000402040 00002040 58 | 0000000000000104 0000000000000000 A 0 0 8 59 | [17] .init_array INIT_ARRAY 0000000000403e00 00002e00 60 | 0000000000000008 0000000000000008 WA 0 0 8 61 | [18] .fini_array FINI_ARRAY 0000000000403e08 00002e08 62 | 0000000000000008 0000000000000008 WA 0 0 8 63 | [19] .dynamic DYNAMIC 0000000000403e10 00002e10 64 | 00000000000001e0 0000000000000010 WA 6 0 8 65 | [20] .got PROGBITS 0000000000403ff0 00002ff0 66 | 0000000000000010 0000000000000008 WA 0 0 8 67 | [21] .got.plt PROGBITS 0000000000404000 00003000 68 | 0000000000000048 0000000000000008 WA 0 0 8 69 | [22] .data PROGBITS 0000000000404048 00003048 70 | 0000000000000010 0000000000000000 WA 0 0 8 71 | [23] .bss NOBITS 0000000000404060 00003058 72 | 0000000000000010 0000000000000000 WA 0 0 16 73 | [24] .comment PROGBITS 0000000000000000 00003058 74 | 0000000000000023 0000000000000001 MS 0 0 1 75 | [25] .symtab SYMTAB 0000000000000000 00003080 76 | 0000000000000618 0000000000000018 26 41 8 77 | [26] .strtab STRTAB 0000000000000000 00003698 78 | 000000000000022e 0000000000000000 0 0 1 79 | [27] .shstrtab STRTAB 0000000000000000 000038c6 80 | 00000000000000e2 0000000000000000 0 0 1 81 | Key to Flags: 82 | W (write), A (alloc), X (execute), M (merge), S (strings), I (info), 83 | L (link order), O (extra OS processing required), G (group), T (TLS), 84 | C (compressed), x (unknown), o (OS specific), E (exclude), 85 | l (large), p (processor specific) 86 | 87 | There are no section groups in this file. 88 | 89 | Program Headers: 90 | Type Offset VirtAddr PhysAddr 91 | FileSiz MemSiz Flags Align 92 | PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 93 | 0x0000000000000230 0x0000000000000230 R 0x8 94 | INTERP 0x0000000000000270 0x0000000000400270 0x0000000000400270 95 | 0x000000000000001c 0x000000000000001c R 0x1 96 | [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] 97 | LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 98 | 0x0000000000000598 0x0000000000000598 R 0x1000 99 | LOAD 0x0000000000001000 0x0000000000401000 0x0000000000401000 100 | 0x000000000000026d 0x000000000000026d R E 0x1000 101 | LOAD 0x0000000000002000 0x0000000000402000 0x0000000000402000 102 | 0x0000000000000144 0x0000000000000144 R 0x1000 103 | LOAD 0x0000000000002e00 0x0000000000403e00 0x0000000000403e00 104 | 0x0000000000000258 0x0000000000000270 RW 0x1000 105 | DYNAMIC 0x0000000000002e10 0x0000000000403e10 0x0000000000403e10 106 | 0x00000000000001e0 0x00000000000001e0 RW 0x8 107 | NOTE 0x000000000000028c 0x000000000040028c 0x000000000040028c 108 | 0x0000000000000020 0x0000000000000020 R 0x4 109 | GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 110 | 0x0000000000000000 0x0000000000000000 RW 0x10 111 | GNU_RELRO 0x0000000000002e00 0x0000000000403e00 0x0000000000403e00 112 | 0x0000000000000200 0x0000000000000200 R 0x1 113 | 114 | Section to Segment mapping: 115 | Segment Sections... 116 | 00 117 | 01 .interp 118 | 02 .interp .note.ABI-tag .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt 119 | 03 .init .plt .text .fini 120 | 04 .rodata .eh_frame 121 | 05 .init_array .fini_array .dynamic .got .got.plt .data .bss 122 | 06 .dynamic 123 | 07 .note.ABI-tag 124 | 08 125 | 09 .init_array .fini_array .dynamic .got 126 | 127 | Dynamic section at offset 0x2e10 contains 25 entries: 128 | Tag Type Name/Value 129 | 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 130 | 0x000000000000000c (INIT) 0x401000 131 | 0x000000000000000d (FINI) 0x401264 132 | 0x0000000000000019 (INIT_ARRAY) 0x403e00 133 | 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) 134 | 0x000000000000001a (FINI_ARRAY) 0x403e08 135 | 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) 136 | 0x0000000000000004 (HASH) 0x4002b0 137 | 0x000000006ffffef5 (GNU_HASH) 0x4002f0 138 | 0x0000000000000005 (STRTAB) 0x400408 139 | 0x0000000000000006 (SYMTAB) 0x400318 140 | 0x000000000000000a (STRSZ) 115 (bytes) 141 | 0x000000000000000b (SYMENT) 24 (bytes) 142 | 0x0000000000000015 (DEBUG) 0x0 143 | 0x0000000000000003 (PLTGOT) 0x404000 144 | 0x0000000000000002 (PLTRELSZ) 144 (bytes) 145 | 0x0000000000000014 (PLTREL) RELA 146 | 0x0000000000000017 (JMPREL) 0x400508 147 | 0x0000000000000007 (RELA) 0x4004c0 148 | 0x0000000000000008 (RELASZ) 72 (bytes) 149 | 0x0000000000000009 (RELAENT) 24 (bytes) 150 | 0x000000006ffffffe (VERNEED) 0x400490 151 | 0x000000006fffffff (VERNEEDNUM) 1 152 | 0x000000006ffffff0 (VERSYM) 0x40047c 153 | 0x0000000000000000 (NULL) 0x0 154 | 155 | Relocation section '.rela.dyn' at offset 0x4c0 contains 3 entries: 156 | Offset Info Type Sym. Value Sym. Name + Addend 157 | 000000403ff0 000200000006 R_X86_64_GLOB_DAT 0000000000000000 __libc_start_main@GLIBC_2.2.5 + 0 158 | 000000403ff8 000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 159 | 000000404060 000900000005 R_X86_64_COPY 0000000000404060 stdin@GLIBC_2.2.5 + 0 160 | 161 | Relocation section '.rela.plt' at offset 0x508 contains 6 entries: 162 | Offset Info Type Sym. Value Sym. Name + Addend 163 | 000000404018 000100000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0 164 | 000000404020 000400000007 R_X86_64_JUMP_SLO 0000000000000000 strtol@GLIBC_2.2.5 + 0 165 | 000000404028 000500000007 R_X86_64_JUMP_SLO 0000000000000000 __printf_chk@GLIBC_2.3.4 + 0 166 | 000000404030 000600000007 R_X86_64_JUMP_SLO 0000000000000000 exit@GLIBC_2.2.5 + 0 167 | 000000404038 000700000007 R_X86_64_JUMP_SLO 0000000000000000 sleep@GLIBC_2.2.5 + 0 168 | 000000404040 000800000007 R_X86_64_JUMP_SLO 0000000000000000 getc@GLIBC_2.2.5 + 0 169 | 170 | The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported. 171 | 172 | Symbol table '.dynsym' contains 10 entries: 173 | Num: Value Size Type Bind Vis Ndx Name 174 | 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 175 | 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2) 176 | 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2) 177 | 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 178 | 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strtol@GLIBC_2.2.5 (2) 179 | 5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __printf_chk@GLIBC_2.3.4 (3) 180 | 6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.2.5 (2) 181 | 7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sleep@GLIBC_2.2.5 (2) 182 | 8: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getc@GLIBC_2.2.5 (2) 183 | 9: 0000000000404060 8 OBJECT GLOBAL DEFAULT 23 stdin@GLIBC_2.2.5 (2) 184 | 185 | Symbol table '.symtab' contains 65 entries: 186 | Num: Value Size Type Bind Vis Ndx Name 187 | 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 188 | 1: 0000000000400270 0 SECTION LOCAL DEFAULT 1 189 | 2: 000000000040028c 0 SECTION LOCAL DEFAULT 2 190 | 3: 00000000004002b0 0 SECTION LOCAL DEFAULT 3 191 | 4: 00000000004002f0 0 SECTION LOCAL DEFAULT 4 192 | 5: 0000000000400318 0 SECTION LOCAL DEFAULT 5 193 | 6: 0000000000400408 0 SECTION LOCAL DEFAULT 6 194 | 7: 000000000040047c 0 SECTION LOCAL DEFAULT 7 195 | 8: 0000000000400490 0 SECTION LOCAL DEFAULT 8 196 | 9: 00000000004004c0 0 SECTION LOCAL DEFAULT 9 197 | 10: 0000000000400508 0 SECTION LOCAL DEFAULT 10 198 | 11: 0000000000401000 0 SECTION LOCAL DEFAULT 11 199 | 12: 0000000000401020 0 SECTION LOCAL DEFAULT 12 200 | 13: 0000000000401090 0 SECTION LOCAL DEFAULT 13 201 | 14: 0000000000401264 0 SECTION LOCAL DEFAULT 14 202 | 15: 0000000000402000 0 SECTION LOCAL DEFAULT 15 203 | 16: 0000000000402040 0 SECTION LOCAL DEFAULT 16 204 | 17: 0000000000403e00 0 SECTION LOCAL DEFAULT 17 205 | 18: 0000000000403e08 0 SECTION LOCAL DEFAULT 18 206 | 19: 0000000000403e10 0 SECTION LOCAL DEFAULT 19 207 | 20: 0000000000403ff0 0 SECTION LOCAL DEFAULT 20 208 | 21: 0000000000404000 0 SECTION LOCAL DEFAULT 21 209 | 22: 0000000000404048 0 SECTION LOCAL DEFAULT 22 210 | 23: 0000000000404060 0 SECTION LOCAL DEFAULT 23 211 | 24: 0000000000000000 0 SECTION LOCAL DEFAULT 24 212 | 25: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 213 | 26: 00000000004010d0 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones 214 | 27: 0000000000401100 0 FUNC LOCAL DEFAULT 13 register_tm_clones 215 | 28: 0000000000401140 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux 216 | 29: 0000000000404068 1 OBJECT LOCAL DEFAULT 23 completed.7963 217 | 30: 0000000000403e08 0 OBJECT LOCAL DEFAULT 18 __do_global_dtors_aux_fin 218 | 31: 0000000000401170 0 FUNC LOCAL DEFAULT 13 frame_dummy 219 | 32: 0000000000403e00 0 OBJECT LOCAL DEFAULT 17 __frame_dummy_init_array_ 220 | 33: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 221 | 34: 00000000004020c0 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__ 222 | 35: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c 223 | 36: 0000000000000000 0 FILE LOCAL DEFAULT ABS 224 | 37: 0000000000403e08 0 NOTYPE LOCAL DEFAULT 17 __init_array_end 225 | 38: 0000000000403e10 0 OBJECT LOCAL DEFAULT 19 _DYNAMIC 226 | 39: 0000000000403e00 0 NOTYPE LOCAL DEFAULT 17 __init_array_start 227 | 40: 0000000000404000 0 OBJECT LOCAL DEFAULT 21 _GLOBAL_OFFSET_TABLE_ 228 | 41: 0000000000401260 1 FUNC GLOBAL DEFAULT 13 __libc_csu_fini 229 | 42: 0000000000404048 0 NOTYPE WEAK DEFAULT 22 data_start 230 | 43: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5 231 | 44: 0000000000404060 8 OBJECT GLOBAL DEFAULT 23 stdin@@GLIBC_2.2.5 232 | 45: 0000000000404058 0 NOTYPE GLOBAL DEFAULT 22 _edata 233 | 46: 0000000000401264 0 FUNC GLOBAL HIDDEN 14 _fini 234 | 47: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ 235 | 48: 0000000000404048 0 NOTYPE GLOBAL DEFAULT 22 __data_start 236 | 49: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 237 | 50: 0000000000000000 0 FUNC GLOBAL DEFAULT UND strtol@@GLIBC_2.2.5 238 | 51: 0000000000404050 0 OBJECT GLOBAL HIDDEN 22 __dso_handle 239 | 52: 0000000000402000 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used 240 | 53: 0000000000401200 93 FUNC GLOBAL DEFAULT 13 __libc_csu_init 241 | 54: 0000000000404070 0 NOTYPE GLOBAL DEFAULT 23 _end 242 | 55: 00000000004010c0 1 FUNC GLOBAL HIDDEN 13 _dl_relocate_static_pie 243 | 56: 0000000000401090 43 FUNC GLOBAL DEFAULT 13 _start 244 | 57: 0000000000404058 0 NOTYPE GLOBAL DEFAULT 23 __bss_start 245 | 58: 0000000000401172 127 FUNC GLOBAL DEFAULT 13 main 246 | 59: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __printf_chk@@GLIBC_2.3.4 247 | 60: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@@GLIBC_2.2.5 248 | 61: 0000000000404058 0 OBJECT GLOBAL HIDDEN 22 __TMC_END__ 249 | 62: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sleep@@GLIBC_2.2.5 250 | 63: 0000000000401000 0 FUNC GLOBAL HIDDEN 11 _init 251 | 64: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getc@@GLIBC_2.2.5 252 | 253 | Histogram for bucket list length (total of 3 buckets): 254 | Length Number % of total Coverage 255 | 0 0 ( 0.0%) 256 | 1 0 ( 0.0%) 0.0% 257 | 2 0 ( 0.0%) 0.0% 258 | 3 3 (100.0%) 100.0% 259 | 260 | Histogram for `.gnu.hash' bucket list length (total of 2 buckets): 261 | Length Number % of total Coverage 262 | 0 1 ( 50.0%) 263 | 1 1 ( 50.0%) 100.0% 264 | 265 | Version symbols section '.gnu.version' contains 10 entries: 266 | Addr: 000000000040047c Offset: 0x00047c Link: 5 (.dynsym) 267 | 000: 0 (*local*) 2 (GLIBC_2.2.5) 2 (GLIBC_2.2.5) 0 (*local*) 268 | 004: 2 (GLIBC_2.2.5) 3 (GLIBC_2.3.4) 2 (GLIBC_2.2.5) 2 (GLIBC_2.2.5) 269 | 008: 2 (GLIBC_2.2.5) 2 (GLIBC_2.2.5) 270 | 271 | Version needs section '.gnu.version_r' contains 1 entry: 272 | Addr: 0x0000000000400490 Offset: 0x000490 Link: 6 (.dynstr) 273 | 000000: Version: 1 File: libc.so.6 Cnt: 2 274 | 0x0010: Name: GLIBC_2.3.4 Flags: none Version: 3 275 | 0x0020: Name: GLIBC_2.2.5 Flags: none Version: 2 276 | 277 | Displaying notes found in: .note.ABI-tag 278 | Owner Data size Description 279 | GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) 280 | OS: Linux, ABI: 3.2.0 281 | -------------------------------------------------------------------------------- /final homework/hello.i: -------------------------------------------------------------------------------- 1 | .file "hello.c" 2 | .text 3 | .section .rodata 4 | .align 8 5 | .LC0: 6 | .string "\347\224\250\346\263\225: Hello \345\255\246\345\217\267 \345\247\223\345\220\215 \347\247\222\346\225\260\357\274\201" 7 | .LC1: 8 | .string "Hello %s %s\n" 9 | .text 10 | .globl main 11 | .type main, @function 12 | main: 13 | .LFB6: 14 | .cfi_startproc 15 | pushq %rbp 16 | .cfi_def_cfa_offset 16 17 | .cfi_offset 6, -16 18 | movq %rsp, %rbp 19 | .cfi_def_cfa_register 6 20 | subq $32, %rsp 21 | movl %edi, -20(%rbp) 22 | movq %rsi, -32(%rbp) 23 | cmpl $4, -20(%rbp) 24 | je .L2 25 | leaq .LC0(%rip), %rdi 26 | call puts@PLT 27 | movl $1, %edi 28 | call exit@PLT 29 | .L2: 30 | movl $0, -4(%rbp) 31 | jmp .L3 32 | .L4: 33 | movq -32(%rbp), %rax 34 | addq $16, %rax 35 | movq (%rax), %rdx 36 | movq -32(%rbp), %rax 37 | addq $8, %rax 38 | movq (%rax), %rax 39 | movq %rax, %rsi 40 | leaq .LC1(%rip), %rdi 41 | movl $0, %eax 42 | call printf@PLT 43 | movq -32(%rbp), %rax 44 | addq $24, %rax 45 | movq (%rax), %rax 46 | movq %rax, %rdi 47 | call atoi@PLT 48 | movl %eax, %edi 49 | call sleep@PLT 50 | addl $1, -4(%rbp) 51 | .L3: 52 | cmpl $7, -4(%rbp) 53 | jle .L4 54 | call getchar@PLT 55 | movl $0, %eax 56 | leave 57 | .cfi_def_cfa 7, 8 58 | ret 59 | .cfi_endproc 60 | .LFE6: 61 | .size main, .-main 62 | .ident "GCC: (Ubuntu 8.3.0-6ubuntu1) 8.3.0" 63 | .section .note.GNU-stack,"",@progbits 64 | -------------------------------------------------------------------------------- /final homework/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/final homework/hello.o -------------------------------------------------------------------------------- /final homework/hello.s: -------------------------------------------------------------------------------- 1 | .file "hello.c" 2 | .text 3 | .section .rodata.str1.8,"aMS",@progbits,1 4 | .align 8 5 | .LC0: 6 | .string "\347\224\250\346\263\225: Hello \345\255\246\345\217\267 \345\247\223\345\220\215 \347\247\222\346\225\260\357\274\201" 7 | .section .rodata.str1.1,"aMS",@progbits,1 8 | .LC1: 9 | .string "Hello %s %s\n" 10 | .text 11 | .globl main 12 | .type main, @function 13 | main: 14 | .LFB50: 15 | .cfi_startproc 16 | pushq %rbp 17 | .cfi_def_cfa_offset 16 18 | .cfi_offset 6, -16 19 | pushq %rbx 20 | .cfi_def_cfa_offset 24 21 | .cfi_offset 3, -24 22 | subq $8, %rsp 23 | .cfi_def_cfa_offset 32 24 | cmpl $4, %edi 25 | jne .L6 26 | movq %rsi, %rbp 27 | movl $0, %ebx 28 | jmp .L2 29 | .L6: 30 | movl $.LC0, %edi 31 | call puts 32 | movl $1, %edi 33 | call exit 34 | .L3: 35 | movq 16(%rbp), %rcx 36 | movq 8(%rbp), %rdx 37 | movl $.LC1, %esi 38 | movl $1, %edi 39 | movl $0, %eax 40 | call __printf_chk 41 | movq 24(%rbp), %rdi 42 | movl $10, %edx 43 | movl $0, %esi 44 | call strtol 45 | movl %eax, %edi 46 | call sleep 47 | addl $1, %ebx 48 | .L2: 49 | cmpl $7, %ebx 50 | jle .L3 51 | movq stdin(%rip), %rdi 52 | call getc 53 | movl $0, %eax 54 | addq $8, %rsp 55 | .cfi_def_cfa_offset 24 56 | popq %rbx 57 | .cfi_def_cfa_offset 16 58 | popq %rbp 59 | .cfi_def_cfa_offset 8 60 | ret 61 | .cfi_endproc 62 | .LFE50: 63 | .size main, .-main 64 | .ident "GCC: (Ubuntu 8.3.0-6ubuntu1) 8.3.0" 65 | .section .note.GNU-stack,"",@progbits 66 | -------------------------------------------------------------------------------- /final homework/hello1.s: -------------------------------------------------------------------------------- 1 | 2 | hello.o: file format elf64-x86-64 3 | 4 | 5 | Disassembly of section .text: 6 | 7 | 0000000000000000
: 8 | 0: 55 push %rbp 9 | 1: 53 push %rbx 10 | 2: 48 83 ec 08 sub $0x8,%rsp 11 | 6: 83 ff 04 cmp $0x4,%edi 12 | 9: 75 0a jne 15 13 | b: 48 89 f5 mov %rsi,%rbp 14 | e: bb 00 00 00 00 mov $0x0,%ebx 15 | 13: eb 4d jmp 62 16 | 15: bf 00 00 00 00 mov $0x0,%edi 17 | 16: R_X86_64_32 .rodata.str1.8 18 | 1a: e8 00 00 00 00 callq 1f 19 | 1b: R_X86_64_PLT32 puts-0x4 20 | 1f: bf 01 00 00 00 mov $0x1,%edi 21 | 24: e8 00 00 00 00 callq 29 22 | 25: R_X86_64_PLT32 exit-0x4 23 | 29: 48 8b 4d 10 mov 0x10(%rbp),%rcx 24 | 2d: 48 8b 55 08 mov 0x8(%rbp),%rdx 25 | 31: be 00 00 00 00 mov $0x0,%esi 26 | 32: R_X86_64_32 .rodata.str1.1 27 | 36: bf 01 00 00 00 mov $0x1,%edi 28 | 3b: b8 00 00 00 00 mov $0x0,%eax 29 | 40: e8 00 00 00 00 callq 45 30 | 41: R_X86_64_PLT32 __printf_chk-0x4 31 | 45: 48 8b 7d 18 mov 0x18(%rbp),%rdi 32 | 49: ba 0a 00 00 00 mov $0xa,%edx 33 | 4e: be 00 00 00 00 mov $0x0,%esi 34 | 53: e8 00 00 00 00 callq 58 35 | 54: R_X86_64_PLT32 strtol-0x4 36 | 58: 89 c7 mov %eax,%edi 37 | 5a: e8 00 00 00 00 callq 5f 38 | 5b: R_X86_64_PLT32 sleep-0x4 39 | 5f: 83 c3 01 add $0x1,%ebx 40 | 62: 83 fb 07 cmp $0x7,%ebx 41 | 65: 7e c2 jle 29 42 | 67: 48 8b 3d 00 00 00 00 mov 0x0(%rip),%rdi # 6e 43 | 6a: R_X86_64_PC32 stdin-0x4 44 | 6e: e8 00 00 00 00 callq 73 45 | 6f: R_X86_64_PLT32 getc-0x4 46 | 73: b8 00 00 00 00 mov $0x0,%eax 47 | 78: 48 83 c4 08 add $0x8,%rsp 48 | 7c: 5b pop %rbx 49 | 7d: 5d pop %rbp 50 | 7e: c3 retq 51 | -------------------------------------------------------------------------------- /final homework/hello2.s: -------------------------------------------------------------------------------- 1 | 2 | hello: file format elf64-x86-64 3 | 4 | 5 | Disassembly of section .init: 6 | 7 | 0000000000401000 <_init>: 8 | 401000: 48 83 ec 08 sub $0x8,%rsp 9 | 401004: 48 8b 05 ed 2f 00 00 mov 0x2fed(%rip),%rax # 403ff8 <__gmon_start__> 10 | 40100b: 48 85 c0 test %rax,%rax 11 | 40100e: 74 02 je 401012 <_init+0x12> 12 | 401010: ff d0 callq *%rax 13 | 401012: 48 83 c4 08 add $0x8,%rsp 14 | 401016: c3 retq 15 | 16 | Disassembly of section .plt: 17 | 18 | 0000000000401020 <.plt>: 19 | 401020: ff 35 e2 2f 00 00 pushq 0x2fe2(%rip) # 404008 <_GLOBAL_OFFSET_TABLE_+0x8> 20 | 401026: ff 25 e4 2f 00 00 jmpq *0x2fe4(%rip) # 404010 <_GLOBAL_OFFSET_TABLE_+0x10> 21 | 40102c: 0f 1f 40 00 nopl 0x0(%rax) 22 | 23 | 0000000000401030 : 24 | 401030: ff 25 e2 2f 00 00 jmpq *0x2fe2(%rip) # 404018 25 | 401036: 68 00 00 00 00 pushq $0x0 26 | 40103b: e9 e0 ff ff ff jmpq 401020 <.plt> 27 | 28 | 0000000000401040 : 29 | 401040: ff 25 da 2f 00 00 jmpq *0x2fda(%rip) # 404020 30 | 401046: 68 01 00 00 00 pushq $0x1 31 | 40104b: e9 d0 ff ff ff jmpq 401020 <.plt> 32 | 33 | 0000000000401050 <__printf_chk@plt>: 34 | 401050: ff 25 d2 2f 00 00 jmpq *0x2fd2(%rip) # 404028 <__printf_chk@GLIBC_2.3.4> 35 | 401056: 68 02 00 00 00 pushq $0x2 36 | 40105b: e9 c0 ff ff ff jmpq 401020 <.plt> 37 | 38 | 0000000000401060 : 39 | 401060: ff 25 ca 2f 00 00 jmpq *0x2fca(%rip) # 404030 40 | 401066: 68 03 00 00 00 pushq $0x3 41 | 40106b: e9 b0 ff ff ff jmpq 401020 <.plt> 42 | 43 | 0000000000401070 : 44 | 401070: ff 25 c2 2f 00 00 jmpq *0x2fc2(%rip) # 404038 45 | 401076: 68 04 00 00 00 pushq $0x4 46 | 40107b: e9 a0 ff ff ff jmpq 401020 <.plt> 47 | 48 | 0000000000401080 : 49 | 401080: ff 25 ba 2f 00 00 jmpq *0x2fba(%rip) # 404040 50 | 401086: 68 05 00 00 00 pushq $0x5 51 | 40108b: e9 90 ff ff ff jmpq 401020 <.plt> 52 | 53 | Disassembly of section .text: 54 | 55 | 0000000000401090 <_start>: 56 | 401090: 31 ed xor %ebp,%ebp 57 | 401092: 49 89 d1 mov %rdx,%r9 58 | 401095: 5e pop %rsi 59 | 401096: 48 89 e2 mov %rsp,%rdx 60 | 401099: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp 61 | 40109d: 50 push %rax 62 | 40109e: 54 push %rsp 63 | 40109f: 49 c7 c0 60 12 40 00 mov $0x401260,%r8 64 | 4010a6: 48 c7 c1 00 12 40 00 mov $0x401200,%rcx 65 | 4010ad: 48 c7 c7 72 11 40 00 mov $0x401172,%rdi 66 | 4010b4: ff 15 36 2f 00 00 callq *0x2f36(%rip) # 403ff0 <__libc_start_main@GLIBC_2.2.5> 67 | 4010ba: f4 hlt 68 | 4010bb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 69 | 70 | 00000000004010c0 <_dl_relocate_static_pie>: 71 | 4010c0: c3 retq 72 | 4010c1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 73 | 4010c8: 00 00 00 74 | 4010cb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 75 | 76 | 00000000004010d0 : 77 | 4010d0: b8 58 40 40 00 mov $0x404058,%eax 78 | 4010d5: 48 3d 58 40 40 00 cmp $0x404058,%rax 79 | 4010db: 74 13 je 4010f0 80 | 4010dd: b8 00 00 00 00 mov $0x0,%eax 81 | 4010e2: 48 85 c0 test %rax,%rax 82 | 4010e5: 74 09 je 4010f0 83 | 4010e7: bf 58 40 40 00 mov $0x404058,%edi 84 | 4010ec: ff e0 jmpq *%rax 85 | 4010ee: 66 90 xchg %ax,%ax 86 | 4010f0: c3 retq 87 | 4010f1: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 88 | 4010f8: 00 00 00 00 89 | 4010fc: 0f 1f 40 00 nopl 0x0(%rax) 90 | 91 | 0000000000401100 : 92 | 401100: be 58 40 40 00 mov $0x404058,%esi 93 | 401105: 48 81 ee 58 40 40 00 sub $0x404058,%rsi 94 | 40110c: 48 c1 fe 03 sar $0x3,%rsi 95 | 401110: 48 89 f0 mov %rsi,%rax 96 | 401113: 48 c1 e8 3f shr $0x3f,%rax 97 | 401117: 48 01 c6 add %rax,%rsi 98 | 40111a: 48 d1 fe sar %rsi 99 | 40111d: 74 11 je 401130 100 | 40111f: b8 00 00 00 00 mov $0x0,%eax 101 | 401124: 48 85 c0 test %rax,%rax 102 | 401127: 74 07 je 401130 103 | 401129: bf 58 40 40 00 mov $0x404058,%edi 104 | 40112e: ff e0 jmpq *%rax 105 | 401130: c3 retq 106 | 401131: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 107 | 401138: 00 00 00 00 108 | 40113c: 0f 1f 40 00 nopl 0x0(%rax) 109 | 110 | 0000000000401140 <__do_global_dtors_aux>: 111 | 401140: 80 3d 21 2f 00 00 00 cmpb $0x0,0x2f21(%rip) # 404068 112 | 401147: 75 17 jne 401160 <__do_global_dtors_aux+0x20> 113 | 401149: 55 push %rbp 114 | 40114a: 48 89 e5 mov %rsp,%rbp 115 | 40114d: e8 7e ff ff ff callq 4010d0 116 | 401152: c6 05 0f 2f 00 00 01 movb $0x1,0x2f0f(%rip) # 404068 117 | 401159: 5d pop %rbp 118 | 40115a: c3 retq 119 | 40115b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 120 | 401160: c3 retq 121 | 401161: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 122 | 401168: 00 00 00 00 123 | 40116c: 0f 1f 40 00 nopl 0x0(%rax) 124 | 125 | 0000000000401170 : 126 | 401170: eb 8e jmp 401100 127 | 128 | 0000000000401172
: 129 | 401172: 55 push %rbp 130 | 401173: 53 push %rbx 131 | 401174: 48 83 ec 08 sub $0x8,%rsp 132 | 401178: 83 ff 04 cmp $0x4,%edi 133 | 40117b: 75 0a jne 401187 134 | 40117d: 48 89 f5 mov %rsi,%rbp 135 | 401180: bb 00 00 00 00 mov $0x0,%ebx 136 | 401185: eb 4d jmp 4011d4 137 | 401187: bf 08 20 40 00 mov $0x402008,%edi 138 | 40118c: e8 9f fe ff ff callq 401030 139 | 401191: bf 01 00 00 00 mov $0x1,%edi 140 | 401196: e8 c5 fe ff ff callq 401060 141 | 40119b: 48 8b 4d 10 mov 0x10(%rbp),%rcx 142 | 40119f: 48 8b 55 08 mov 0x8(%rbp),%rdx 143 | 4011a3: be 30 20 40 00 mov $0x402030,%esi 144 | 4011a8: bf 01 00 00 00 mov $0x1,%edi 145 | 4011ad: b8 00 00 00 00 mov $0x0,%eax 146 | 4011b2: e8 99 fe ff ff callq 401050 <__printf_chk@plt> 147 | 4011b7: 48 8b 7d 18 mov 0x18(%rbp),%rdi 148 | 4011bb: ba 0a 00 00 00 mov $0xa,%edx 149 | 4011c0: be 00 00 00 00 mov $0x0,%esi 150 | 4011c5: e8 76 fe ff ff callq 401040 151 | 4011ca: 89 c7 mov %eax,%edi 152 | 4011cc: e8 9f fe ff ff callq 401070 153 | 4011d1: 83 c3 01 add $0x1,%ebx 154 | 4011d4: 83 fb 07 cmp $0x7,%ebx 155 | 4011d7: 7e c2 jle 40119b 156 | 4011d9: 48 8b 3d 80 2e 00 00 mov 0x2e80(%rip),%rdi # 404060 157 | 4011e0: e8 9b fe ff ff callq 401080 158 | 4011e5: b8 00 00 00 00 mov $0x0,%eax 159 | 4011ea: 48 83 c4 08 add $0x8,%rsp 160 | 4011ee: 5b pop %rbx 161 | 4011ef: 5d pop %rbp 162 | 4011f0: c3 retq 163 | 4011f1: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 164 | 4011f8: 00 00 00 165 | 4011fb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 166 | 167 | 0000000000401200 <__libc_csu_init>: 168 | 401200: 41 57 push %r15 169 | 401202: 49 89 d7 mov %rdx,%r15 170 | 401205: 41 56 push %r14 171 | 401207: 49 89 f6 mov %rsi,%r14 172 | 40120a: 41 55 push %r13 173 | 40120c: 41 89 fd mov %edi,%r13d 174 | 40120f: 41 54 push %r12 175 | 401211: 4c 8d 25 e8 2b 00 00 lea 0x2be8(%rip),%r12 # 403e00 <__frame_dummy_init_array_entry> 176 | 401218: 55 push %rbp 177 | 401219: 48 8d 2d e8 2b 00 00 lea 0x2be8(%rip),%rbp # 403e08 <__init_array_end> 178 | 401220: 53 push %rbx 179 | 401221: 4c 29 e5 sub %r12,%rbp 180 | 401224: 48 83 ec 08 sub $0x8,%rsp 181 | 401228: e8 d3 fd ff ff callq 401000 <_init> 182 | 40122d: 48 c1 fd 03 sar $0x3,%rbp 183 | 401231: 74 1b je 40124e <__libc_csu_init+0x4e> 184 | 401233: 31 db xor %ebx,%ebx 185 | 401235: 0f 1f 00 nopl (%rax) 186 | 401238: 4c 89 fa mov %r15,%rdx 187 | 40123b: 4c 89 f6 mov %r14,%rsi 188 | 40123e: 44 89 ef mov %r13d,%edi 189 | 401241: 41 ff 14 dc callq *(%r12,%rbx,8) 190 | 401245: 48 83 c3 01 add $0x1,%rbx 191 | 401249: 48 39 dd cmp %rbx,%rbp 192 | 40124c: 75 ea jne 401238 <__libc_csu_init+0x38> 193 | 40124e: 48 83 c4 08 add $0x8,%rsp 194 | 401252: 5b pop %rbx 195 | 401253: 5d pop %rbp 196 | 401254: 41 5c pop %r12 197 | 401256: 41 5d pop %r13 198 | 401258: 41 5e pop %r14 199 | 40125a: 41 5f pop %r15 200 | 40125c: c3 retq 201 | 40125d: 0f 1f 00 nopl (%rax) 202 | 203 | 0000000000401260 <__libc_csu_fini>: 204 | 401260: c3 retq 205 | 206 | Disassembly of section .fini: 207 | 208 | 0000000000401264 <_fini>: 209 | 401264: 48 83 ec 08 sub $0x8,%rsp 210 | 401268: 48 83 c4 08 add $0x8,%rsp 211 | 40126c: c3 retq 212 | -------------------------------------------------------------------------------- /final homework/自媒体地址.txt: -------------------------------------------------------------------------------- 1 | https://blog.csdn.net/hitWeek/article/details/103849996 -------------------------------------------------------------------------------- /final homework/自媒体截图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/final homework/自媒体截图.jpg -------------------------------------------------------------------------------- /homework/homework 2/2.55.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef unsigned char* byte_pointer; 4 | 5 | void show_bytes(byte_pointer start,size_t len) 6 | { 7 | size_t i; 8 | for (i = 0;i < len;i++) 9 | { 10 | printf(" %.2x",start[i]); 11 | } 12 | printf("\n"); 13 | } 14 | 15 | int main() 16 | { 17 | int a; 18 | printf("Input a:"); 19 | scanf("%x",&a); 20 | show_bytes((byte_pointer)&a,sizeof(int)); 21 | } 22 | -------------------------------------------------------------------------------- /homework/homework 2/2.59.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int combine(int x, int y) 4 | { 5 | int a = (x & 0xff) + (y & 0xffffff00); 6 | return a; 7 | } 8 | 9 | int main() 10 | { 11 | int x,y,_combine; 12 | printf("Input x,y:\n"); 13 | scanf("%x%x",&x,&y); 14 | _combine = combine(x,y); 15 | printf("The combination is %x",_combine); 16 | } 17 | -------------------------------------------------------------------------------- /homework/homework 2/2.63.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | unsigned srl(unsigned x, int k) 4 | { 5 | unsigned xsra = (int) x >> k; 6 | return xsra & ~(~0 << (sizeof(int) * 8 - k)); 7 | } 8 | 9 | int sra(int x, int k) 10 | { 11 | int xsrl = (unsigned) x >> k; 12 | unsigned _sign = x & (0x1 << (sizeof(int) * 8 - 1)); 13 | return xsrl | (((!_sign) + ~0) << (sizeof(int) * 8 - k)); 14 | } 15 | 16 | int main() 17 | { 18 | int k; 19 | int x; 20 | printf("Input x,k:\n"); 21 | scanf("%x%d",&x,&k); 22 | x = sra(x,k); 23 | printf("%x",x); 24 | } 25 | 26 | /*int main() 27 | { 28 | int k; 29 | unsigned x; 30 | printf("Input x,k:\n"); 31 | scanf("%x%d",&x,&k); 32 | x = srl(x,k); 33 | printf("%x",x); 34 | }*/ 35 | 36 | -------------------------------------------------------------------------------- /homework/homework 2/2.67.c: -------------------------------------------------------------------------------- 1 | char int_32_size_is_32() 2 | { 3 | int set_msb = 1 << 31; 4 | int beyond_msb = (1 << 16) << 16; 5 | return set_msb && !beyond_msb; 6 | } 7 | 8 | char int_16_size_is_32() 9 | { 10 | int set_msb = (1 << 15)<<16; 11 | int beyond_msb = ((1 << 15) << 15)<<2; 12 | return set_msb && !beyond_msb; 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /homework/homework 2/2.71.c: -------------------------------------------------------------------------------- 1 | int xbyte(unsigned word, int bytenum) 2 | { 3 | int ret = word << ((3 - bytenum)<<3); 4 | return ret >> 24; 5 | } 6 | -------------------------------------------------------------------------------- /homework/homework 2/2.75.c: -------------------------------------------------------------------------------- 1 | unsigned unsigned_high_prod(unsigned x,unsigned y) 2 | { 3 | int w = sizeof(unsigned) << 3; 4 | int sx = (int)x; 5 | int sy = (int)y; 6 | int t = signed_high_prod(sx,sy); 7 | return t + ((sx>>(w-1))&1)*sy+((sy>>(w-1))&1)*sx; 8 | } 9 | -------------------------------------------------------------------------------- /homework/homework 2/2.79.c: -------------------------------------------------------------------------------- 1 | 2 | int mul3div4(int x) 3 | { 4 | x = (x << 1) + x; 5 | x = (x + ((1 << 2) - 1) * (x < 0)) >> 2; 6 | return x; 7 | } 8 | 9 | /*int main() 10 | { 11 | int x,result; 12 | printf("Input x:"); 13 | scanf("%d",&x); 14 | result = mul3div4(x); 15 | printf("%d",result); 16 | }*/ 17 | -------------------------------------------------------------------------------- /homework/homework 2/2.95.c: -------------------------------------------------------------------------------- 1 | 2 | float_bits float_half(float_bits f) 3 | { 4 | unsigned sig = f >> 31; 5 | unsigned rest = f & 0x7FFFFFFF; 6 | unsigned exp = f >> 23 & 0xFF; 7 | unsigned frac = f & 0x7FFFFF; 8 | int is_NAN_or_oo = (exp == 0xFF); 9 | if (is_NAN_or_oo) 10 | { 11 | return f; 12 | } 13 | int addition = (frac & 0x3) == 0x3; 14 | if (exp == 0) 15 | { 16 | frac >>= 1; 17 | frac += addition; 18 | } 19 | else if (exp == 1) 20 | { 21 | rest >>= 1; 22 | rest += addition; 23 | exp = rest >> 23 & 0xFF; 24 | frac = rest & 0x7FFFFF; 25 | } 26 | else 27 | { 28 | exp -= 1; 29 | } 30 | return sig << 31 | exp << 23 | frac; 31 | } 32 | -------------------------------------------------------------------------------- /homework/homework 2/homework2.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 2/homework2.doc -------------------------------------------------------------------------------- /homework/homework 3/祁天-1183200123.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 3/祁天-1183200123.doc -------------------------------------------------------------------------------- /homework/homework 4+5.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 4+5.doc -------------------------------------------------------------------------------- /homework/homework 6+7.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 6+7.doc -------------------------------------------------------------------------------- /homework/homework 8+9/homework 8+9.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 8+9/homework 8+9.doc -------------------------------------------------------------------------------- /homework/homework 8+9/homework 8+9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/homework/homework 8+9/homework 8+9.pdf -------------------------------------------------------------------------------- /lab/lab1/cpuwordsize/cpuwordsize.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int cpuWordSize() 4 | { 5 | int size; 6 | int a=1; 7 | int *p=&a; 8 | size = 8*sizeof(p); 9 | return size; 10 | } 11 | 12 | int main() 13 | { 14 | int size; 15 | size = cpuWordSize(); 16 | printf("CPU word size is %d bits\n",size); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /lab/lab1/cpuwordsize/cpuwordsize.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/cpuwordsize/cpuwordsize.exe -------------------------------------------------------------------------------- /lab/lab1/cpuwordsize/cpuwordsize.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/cpuwordsize/cpuwordsize.o -------------------------------------------------------------------------------- /lab/lab1/datetype/datetype.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/datetype/datetype.c -------------------------------------------------------------------------------- /lab/lab1/datetype/datetype.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/datetype/datetype.exe -------------------------------------------------------------------------------- /lab/lab1/datetype/datetype.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/datetype/datetype.o -------------------------------------------------------------------------------- /lab/lab1/float/float.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/float/float.c -------------------------------------------------------------------------------- /lab/lab1/float/float.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/float/float.exe -------------------------------------------------------------------------------- /lab/lab1/float/float.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/float/float.o -------------------------------------------------------------------------------- /lab/lab1/hello.i: -------------------------------------------------------------------------------- 1 | # 1 "hellolinux.c" 2 | # 1 "" 3 | # 1 "" 4 | # 31 "" 5 | # 1 "/usr/include/stdc-predef.h" 1 3 4 6 | # 32 "" 2 7 | # 1 "hellolinux.c" 8 | # 1 "/usr/include/stdio.h" 1 3 4 9 | # 27 "/usr/include/stdio.h" 3 4 10 | # 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 11 | # 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4 12 | # 1 "/usr/include/features.h" 1 3 4 13 | # 446 "/usr/include/features.h" 3 4 14 | # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 15 | # 452 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 16 | # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 17 | # 453 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 18 | # 1 "/usr/include/x86_64-linux-gnu/bits/long-double.h" 1 3 4 19 | # 454 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 20 | # 447 "/usr/include/features.h" 2 3 4 21 | # 470 "/usr/include/features.h" 3 4 22 | # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4 23 | # 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4 24 | # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4 25 | # 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4 26 | # 471 "/usr/include/features.h" 2 3 4 27 | # 34 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 2 3 4 28 | # 28 "/usr/include/stdio.h" 2 3 4 29 | 30 | 31 | 32 | 33 | 34 | # 1 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 1 3 4 35 | # 216 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 3 4 36 | 37 | # 216 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 3 4 38 | typedef long unsigned int size_t; 39 | # 34 "/usr/include/stdio.h" 2 3 4 40 | 41 | 42 | # 1 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h" 1 3 4 43 | # 40 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h" 3 4 44 | typedef __builtin_va_list __gnuc_va_list; 45 | # 37 "/usr/include/stdio.h" 2 3 4 46 | 47 | # 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4 48 | # 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 49 | # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 50 | # 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 51 | # 1 "/usr/include/x86_64-linux-gnu/bits/timesize.h" 1 3 4 52 | # 29 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 53 | 54 | 55 | typedef unsigned char __u_char; 56 | typedef unsigned short int __u_short; 57 | typedef unsigned int __u_int; 58 | typedef unsigned long int __u_long; 59 | 60 | 61 | typedef signed char __int8_t; 62 | typedef unsigned char __uint8_t; 63 | typedef signed short int __int16_t; 64 | typedef unsigned short int __uint16_t; 65 | typedef signed int __int32_t; 66 | typedef unsigned int __uint32_t; 67 | 68 | typedef signed long int __int64_t; 69 | typedef unsigned long int __uint64_t; 70 | 71 | 72 | 73 | 74 | 75 | 76 | typedef __int8_t __int_least8_t; 77 | typedef __uint8_t __uint_least8_t; 78 | typedef __int16_t __int_least16_t; 79 | typedef __uint16_t __uint_least16_t; 80 | typedef __int32_t __int_least32_t; 81 | typedef __uint32_t __uint_least32_t; 82 | typedef __int64_t __int_least64_t; 83 | typedef __uint64_t __uint_least64_t; 84 | 85 | 86 | 87 | typedef long int __quad_t; 88 | typedef unsigned long int __u_quad_t; 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | typedef long int __intmax_t; 97 | typedef unsigned long int __uintmax_t; 98 | # 141 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 99 | # 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4 100 | # 142 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 101 | # 1 "/usr/include/x86_64-linux-gnu/bits/time64.h" 1 3 4 102 | # 143 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 103 | 104 | 105 | typedef unsigned long int __dev_t; 106 | typedef unsigned int __uid_t; 107 | typedef unsigned int __gid_t; 108 | typedef unsigned long int __ino_t; 109 | typedef unsigned long int __ino64_t; 110 | typedef unsigned int __mode_t; 111 | typedef unsigned long int __nlink_t; 112 | typedef long int __off_t; 113 | typedef long int __off64_t; 114 | typedef int __pid_t; 115 | typedef struct { int __val[2]; } __fsid_t; 116 | typedef long int __clock_t; 117 | typedef unsigned long int __rlim_t; 118 | typedef unsigned long int __rlim64_t; 119 | typedef unsigned int __id_t; 120 | typedef long int __time_t; 121 | typedef unsigned int __useconds_t; 122 | typedef long int __suseconds_t; 123 | 124 | typedef int __daddr_t; 125 | typedef int __key_t; 126 | 127 | 128 | typedef int __clockid_t; 129 | 130 | 131 | typedef void * __timer_t; 132 | 133 | 134 | typedef long int __blksize_t; 135 | 136 | 137 | 138 | 139 | typedef long int __blkcnt_t; 140 | typedef long int __blkcnt64_t; 141 | 142 | 143 | typedef unsigned long int __fsblkcnt_t; 144 | typedef unsigned long int __fsblkcnt64_t; 145 | 146 | 147 | typedef unsigned long int __fsfilcnt_t; 148 | typedef unsigned long int __fsfilcnt64_t; 149 | 150 | 151 | typedef long int __fsword_t; 152 | 153 | typedef long int __ssize_t; 154 | 155 | 156 | typedef long int __syscall_slong_t; 157 | 158 | typedef unsigned long int __syscall_ulong_t; 159 | 160 | 161 | 162 | typedef __off64_t __loff_t; 163 | typedef char *__caddr_t; 164 | 165 | 166 | typedef long int __intptr_t; 167 | 168 | 169 | typedef unsigned int __socklen_t; 170 | 171 | 172 | 173 | 174 | typedef int __sig_atomic_t; 175 | # 39 "/usr/include/stdio.h" 2 3 4 176 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 1 3 4 177 | 178 | 179 | 180 | 181 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 1 3 4 182 | # 13 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 3 4 183 | typedef struct 184 | { 185 | int __count; 186 | union 187 | { 188 | unsigned int __wch; 189 | char __wchb[4]; 190 | } __value; 191 | } __mbstate_t; 192 | # 6 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 2 3 4 193 | 194 | 195 | 196 | 197 | typedef struct _G_fpos_t 198 | { 199 | __off_t __pos; 200 | __mbstate_t __state; 201 | } __fpos_t; 202 | # 40 "/usr/include/stdio.h" 2 3 4 203 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 1 3 4 204 | # 10 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 3 4 205 | typedef struct _G_fpos64_t 206 | { 207 | __off64_t __pos; 208 | __mbstate_t __state; 209 | } __fpos64_t; 210 | # 41 "/usr/include/stdio.h" 2 3 4 211 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/__FILE.h" 1 3 4 212 | 213 | 214 | 215 | struct _IO_FILE; 216 | typedef struct _IO_FILE __FILE; 217 | # 42 "/usr/include/stdio.h" 2 3 4 218 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/FILE.h" 1 3 4 219 | 220 | 221 | 222 | struct _IO_FILE; 223 | 224 | 225 | typedef struct _IO_FILE FILE; 226 | # 43 "/usr/include/stdio.h" 2 3 4 227 | # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 1 3 4 228 | # 35 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 3 4 229 | struct _IO_FILE; 230 | struct _IO_marker; 231 | struct _IO_codecvt; 232 | struct _IO_wide_data; 233 | 234 | 235 | 236 | 237 | typedef void _IO_lock_t; 238 | 239 | 240 | 241 | 242 | 243 | struct _IO_FILE 244 | { 245 | int _flags; 246 | 247 | 248 | char *_IO_read_ptr; 249 | char *_IO_read_end; 250 | char *_IO_read_base; 251 | char *_IO_write_base; 252 | char *_IO_write_ptr; 253 | char *_IO_write_end; 254 | char *_IO_buf_base; 255 | char *_IO_buf_end; 256 | 257 | 258 | char *_IO_save_base; 259 | char *_IO_backup_base; 260 | char *_IO_save_end; 261 | 262 | struct _IO_marker *_markers; 263 | 264 | struct _IO_FILE *_chain; 265 | 266 | int _fileno; 267 | int _flags2; 268 | __off_t _old_offset; 269 | 270 | 271 | unsigned short _cur_column; 272 | signed char _vtable_offset; 273 | char _shortbuf[1]; 274 | 275 | _IO_lock_t *_lock; 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | __off64_t _offset; 284 | 285 | struct _IO_codecvt *_codecvt; 286 | struct _IO_wide_data *_wide_data; 287 | struct _IO_FILE *_freeres_list; 288 | void *_freeres_buf; 289 | size_t __pad5; 290 | int _mode; 291 | 292 | char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; 293 | }; 294 | # 44 "/usr/include/stdio.h" 2 3 4 295 | # 52 "/usr/include/stdio.h" 3 4 296 | typedef __gnuc_va_list va_list; 297 | # 63 "/usr/include/stdio.h" 3 4 298 | typedef __off_t off_t; 299 | # 77 "/usr/include/stdio.h" 3 4 300 | typedef __ssize_t ssize_t; 301 | 302 | 303 | 304 | 305 | 306 | 307 | typedef __fpos_t fpos_t; 308 | # 133 "/usr/include/stdio.h" 3 4 309 | # 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4 310 | # 134 "/usr/include/stdio.h" 2 3 4 311 | 312 | 313 | 314 | extern FILE *stdin; 315 | extern FILE *stdout; 316 | extern FILE *stderr; 317 | 318 | 319 | 320 | 321 | 322 | 323 | extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); 324 | 325 | extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 326 | 327 | 328 | 329 | extern int renameat (int __oldfd, const char *__old, int __newfd, 330 | const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 331 | # 173 "/usr/include/stdio.h" 3 4 332 | extern FILE *tmpfile (void) ; 333 | # 187 "/usr/include/stdio.h" 3 4 334 | extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 335 | 336 | 337 | 338 | 339 | extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 340 | # 204 "/usr/include/stdio.h" 3 4 341 | extern char *tempnam (const char *__dir, const char *__pfx) 342 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | extern int fclose (FILE *__stream); 351 | 352 | 353 | 354 | 355 | extern int fflush (FILE *__stream); 356 | # 227 "/usr/include/stdio.h" 3 4 357 | extern int fflush_unlocked (FILE *__stream); 358 | # 246 "/usr/include/stdio.h" 3 4 359 | extern FILE *fopen (const char *__restrict __filename, 360 | const char *__restrict __modes) ; 361 | 362 | 363 | 364 | 365 | extern FILE *freopen (const char *__restrict __filename, 366 | const char *__restrict __modes, 367 | FILE *__restrict __stream) ; 368 | # 279 "/usr/include/stdio.h" 3 4 369 | extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; 370 | # 292 "/usr/include/stdio.h" 3 4 371 | extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) 372 | __attribute__ ((__nothrow__ , __leaf__)) ; 373 | 374 | 375 | 376 | 377 | extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; 378 | 379 | 380 | 381 | 382 | 383 | extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); 384 | 385 | 386 | 387 | extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, 388 | int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); 389 | 390 | 391 | 392 | 393 | extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, 394 | size_t __size) __attribute__ ((__nothrow__ , __leaf__)); 395 | 396 | 397 | extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | extern int fprintf (FILE *__restrict __stream, 406 | const char *__restrict __format, ...); 407 | 408 | 409 | 410 | 411 | extern int printf (const char *__restrict __format, ...); 412 | 413 | extern int sprintf (char *__restrict __s, 414 | const char *__restrict __format, ...) __attribute__ ((__nothrow__)); 415 | 416 | 417 | 418 | 419 | 420 | extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, 421 | __gnuc_va_list __arg); 422 | 423 | 424 | 425 | 426 | extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); 427 | 428 | extern int vsprintf (char *__restrict __s, const char *__restrict __format, 429 | __gnuc_va_list __arg) __attribute__ ((__nothrow__)); 430 | 431 | 432 | 433 | extern int snprintf (char *__restrict __s, size_t __maxlen, 434 | const char *__restrict __format, ...) 435 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); 436 | 437 | extern int vsnprintf (char *__restrict __s, size_t __maxlen, 438 | const char *__restrict __format, __gnuc_va_list __arg) 439 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); 440 | # 379 "/usr/include/stdio.h" 3 4 441 | extern int vdprintf (int __fd, const char *__restrict __fmt, 442 | __gnuc_va_list __arg) 443 | __attribute__ ((__format__ (__printf__, 2, 0))); 444 | extern int dprintf (int __fd, const char *__restrict __fmt, ...) 445 | __attribute__ ((__format__ (__printf__, 2, 3))); 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | extern int fscanf (FILE *__restrict __stream, 454 | const char *__restrict __format, ...) ; 455 | 456 | 457 | 458 | 459 | extern int scanf (const char *__restrict __format, ...) ; 460 | 461 | extern int sscanf (const char *__restrict __s, 462 | const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); 463 | 464 | 465 | 466 | 467 | 468 | 469 | extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") 470 | 471 | ; 472 | extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") 473 | ; 474 | extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)) 475 | 476 | ; 477 | # 432 "/usr/include/stdio.h" 3 4 478 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, 479 | __gnuc_va_list __arg) 480 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 481 | 482 | 483 | 484 | 485 | 486 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) 487 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 488 | 489 | 490 | extern int vsscanf (const char *__restrict __s, 491 | const char *__restrict __format, __gnuc_va_list __arg) 492 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); 493 | 494 | 495 | 496 | 497 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") 498 | 499 | 500 | 501 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 502 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") 503 | 504 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 505 | extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) 506 | 507 | 508 | 509 | __attribute__ ((__format__ (__scanf__, 2, 0))); 510 | # 485 "/usr/include/stdio.h" 3 4 511 | extern int fgetc (FILE *__stream); 512 | extern int getc (FILE *__stream); 513 | 514 | 515 | 516 | 517 | 518 | extern int getchar (void); 519 | 520 | 521 | 522 | 523 | 524 | 525 | extern int getc_unlocked (FILE *__stream); 526 | extern int getchar_unlocked (void); 527 | # 510 "/usr/include/stdio.h" 3 4 528 | extern int fgetc_unlocked (FILE *__stream); 529 | # 521 "/usr/include/stdio.h" 3 4 530 | extern int fputc (int __c, FILE *__stream); 531 | extern int putc (int __c, FILE *__stream); 532 | 533 | 534 | 535 | 536 | 537 | extern int putchar (int __c); 538 | # 537 "/usr/include/stdio.h" 3 4 539 | extern int fputc_unlocked (int __c, FILE *__stream); 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | extern int putc_unlocked (int __c, FILE *__stream); 548 | extern int putchar_unlocked (int __c); 549 | 550 | 551 | 552 | 553 | 554 | 555 | extern int getw (FILE *__stream); 556 | 557 | 558 | extern int putw (int __w, FILE *__stream); 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) 567 | ; 568 | # 603 "/usr/include/stdio.h" 3 4 569 | extern __ssize_t __getdelim (char **__restrict __lineptr, 570 | size_t *__restrict __n, int __delimiter, 571 | FILE *__restrict __stream) ; 572 | extern __ssize_t getdelim (char **__restrict __lineptr, 573 | size_t *__restrict __n, int __delimiter, 574 | FILE *__restrict __stream) ; 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | extern __ssize_t getline (char **__restrict __lineptr, 583 | size_t *__restrict __n, 584 | FILE *__restrict __stream) ; 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | extern int fputs (const char *__restrict __s, FILE *__restrict __stream); 593 | 594 | 595 | 596 | 597 | 598 | extern int puts (const char *__s); 599 | 600 | 601 | 602 | 603 | 604 | 605 | extern int ungetc (int __c, FILE *__stream); 606 | 607 | 608 | 609 | 610 | 611 | 612 | extern size_t fread (void *__restrict __ptr, size_t __size, 613 | size_t __n, FILE *__restrict __stream) ; 614 | 615 | 616 | 617 | 618 | extern size_t fwrite (const void *__restrict __ptr, size_t __size, 619 | size_t __n, FILE *__restrict __s); 620 | # 673 "/usr/include/stdio.h" 3 4 621 | extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, 622 | size_t __n, FILE *__restrict __stream) ; 623 | extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, 624 | size_t __n, FILE *__restrict __stream); 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | extern int fseek (FILE *__stream, long int __off, int __whence); 633 | 634 | 635 | 636 | 637 | extern long int ftell (FILE *__stream) ; 638 | 639 | 640 | 641 | 642 | extern void rewind (FILE *__stream); 643 | # 707 "/usr/include/stdio.h" 3 4 644 | extern int fseeko (FILE *__stream, __off_t __off, int __whence); 645 | 646 | 647 | 648 | 649 | extern __off_t ftello (FILE *__stream) ; 650 | # 731 "/usr/include/stdio.h" 3 4 651 | extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); 652 | 653 | 654 | 655 | 656 | extern int fsetpos (FILE *__stream, const fpos_t *__pos); 657 | # 757 "/usr/include/stdio.h" 3 4 658 | extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 659 | 660 | extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 661 | 662 | extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 663 | 664 | 665 | 666 | extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 667 | extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 668 | extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | extern void perror (const char *__s); 677 | 678 | 679 | 680 | 681 | 682 | # 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4 683 | # 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4 684 | extern int sys_nerr; 685 | extern const char *const sys_errlist[]; 686 | # 782 "/usr/include/stdio.h" 2 3 4 687 | 688 | 689 | 690 | 691 | extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 692 | 693 | 694 | 695 | 696 | extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 697 | # 800 "/usr/include/stdio.h" 3 4 698 | extern FILE *popen (const char *__command, const char *__modes) ; 699 | 700 | 701 | 702 | 703 | 704 | extern int pclose (FILE *__stream); 705 | 706 | 707 | 708 | 709 | 710 | extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); 711 | # 840 "/usr/include/stdio.h" 3 4 712 | extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 713 | 714 | 715 | 716 | extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 717 | 718 | 719 | extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 720 | # 858 "/usr/include/stdio.h" 3 4 721 | extern int __uflow (FILE *); 722 | extern int __overflow (FILE *, int); 723 | # 873 "/usr/include/stdio.h" 3 4 724 | 725 | # 2 "hellolinux.c" 2 726 | 727 | 728 | # 3 "hellolinux.c" 729 | int main() 730 | { 731 | printf("Hello 1183200123 祁天\n"); 732 | return 0; 733 | } 734 | -------------------------------------------------------------------------------- /lab/lab1/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/hello.o -------------------------------------------------------------------------------- /lab/lab1/hello.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/hello.out -------------------------------------------------------------------------------- /lab/lab1/hello.s: -------------------------------------------------------------------------------- 1 | .file "hellolinux.c" 2 | .text 3 | .section .rodata 4 | .LC0: 5 | .string "Hello 1183200123 \347\245\201\345\244\251" 6 | .text 7 | .globl main 8 | .type main, @function 9 | main: 10 | .LFB0: 11 | .cfi_startproc 12 | pushq %rbp 13 | .cfi_def_cfa_offset 16 14 | .cfi_offset 6, -16 15 | movq %rsp, %rbp 16 | .cfi_def_cfa_register 6 17 | leaq .LC0(%rip), %rdi 18 | call puts@PLT 19 | movl $0, %eax 20 | popq %rbp 21 | .cfi_def_cfa 7, 8 22 | ret 23 | .cfi_endproc 24 | .LFE0: 25 | .size main, .-main 26 | .ident "GCC: (Ubuntu 8.3.0-6ubuntu1) 8.3.0" 27 | .section .note.GNU-stack,"",@progbits 28 | -------------------------------------------------------------------------------- /lab/lab1/hellolinux.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello 1183200123 祁天\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /lab/lab1/hellowin.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/hellowin.c -------------------------------------------------------------------------------- /lab/lab1/isLittleEndian/isLittleEndian.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int BOOL; 4 | #define TRUE 1 5 | #define FALSE 0 6 | 7 | BOOL isLittleEndian() 8 | { 9 | short x = 0x2019; 10 | char x1,x2; 11 | x1 = *((char *)&x); 12 | x2 = *(((char *)&x)+1); 13 | if(x1==0x20 && x2==0x19) 14 | return 0; 15 | if(x2==0x20 && x1==0x19) 16 | return 1; 17 | } 18 | 19 | int main() 20 | { 21 | BOOL a = isLittleEndian(); 22 | if (a == 1) 23 | printf("It is Little Endian"); 24 | else printf("It is Big Endian"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /lab/lab1/isLittleEndian/isLittleEndian.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/isLittleEndian/isLittleEndian.exe -------------------------------------------------------------------------------- /lab/lab1/isLittleEndian/isLittleEndian.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/isLittleEndian/isLittleEndian.o -------------------------------------------------------------------------------- /lab/lab1/sum/sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 0 3 | int sum(int a[],int len) 4 | { 5 | int i,sum = 0; 6 | for (i = 0; i <= len-1; i++) 7 | sum += a[i]; 8 | return sum; 9 | } 10 | 11 | int main() 12 | { 13 | int a[N]; 14 | int i,b; 15 | for(i = 0; i < N; i++) 16 | { 17 | a[i] = i+1; 18 | } 19 | b = sum(a,N); 20 | printf("sum = %d",b); 21 | } 22 | -------------------------------------------------------------------------------- /lab/lab1/sum/sum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/sum/sum.exe -------------------------------------------------------------------------------- /lab/lab1/sum/sum.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/sum/sum.o -------------------------------------------------------------------------------- /lab/lab1/祁天 实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab1/祁天 实验报告.doc -------------------------------------------------------------------------------- /lab/lab2/C程序/cs_atof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float cs_atof(char *str) 4 | { 5 | int flag; 6 | int x = 0; 7 | if(*str == '-') 8 | { 9 | flag = 1; 10 | str++; 11 | } 12 | else flag = 0; 13 | do{ 14 | x = 10*x + *str - '0'; 15 | }while(*++str != '.' && *str != '\0'); 16 | float f = (float)x; 17 | if(*str == '\0') 18 | { 19 | if(flag) 20 | f = -f; 21 | return f; 22 | } 23 | float pow = 0.1; 24 | str++; 25 | do{ 26 | f += (*str-'0')*pow; 27 | pow *= 0.1; 28 | }while(*++str != '\0'); 29 | if(flag) 30 | f = -f; 31 | return f; 32 | } 33 | 34 | int main() 35 | { 36 | char str[100]; 37 | float f; 38 | printf("Input a string:"); 39 | scanf("%s",str); 40 | f = cs_atof(str); 41 | printf("The float is:%f",f); 42 | } 43 | -------------------------------------------------------------------------------- /lab/lab2/C程序/cs_atoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int cs_atoi(char* str) 4 | { 5 | int x = 0; 6 | int y = 1; 7 | int i,j,p,q; 8 | for(j = 0;*str!= '\0';str++) 9 | { 10 | j++; 11 | } 12 | for(i = 0;i < j && *--str != '-';i++) 13 | { 14 | p = *str -'0'; 15 | for(q = 0;q < i;q++) 16 | { 17 | y *= 10; 18 | } 19 | x = x + p*y; 20 | y = 1; 21 | } 22 | if(*str == '-') 23 | { 24 | x = -x; 25 | } 26 | return x; 27 | } 28 | 29 | int main() 30 | { 31 | char str[99]; 32 | int x; 33 | printf("Input a string:"); 34 | scanf("%s",str); 35 | x = cs_atoi(str); 36 | printf("The integer is %d\n",x); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /lab/lab2/C程序/cs_ftoa.c: -------------------------------------------------------------------------------- 1 | #include 2 | void cs_itoa(int i, char *str); 3 | void cs_ftoa(float f, char *str) 4 | { 5 | int x = (int)f; 6 | cs_itoa(x,str); 7 | do 8 | { 9 | str++; 10 | }while(*str != '.'); 11 | while(f - (float)x > 0.00000001) 12 | { 13 | f = (f - (float)x)*10; 14 | x = (int) f; 15 | *++str = x + '0'; 16 | } 17 | *str = '\0'; 18 | } 19 | 20 | int main() 21 | { 22 | float f; 23 | printf("Input a float:"); 24 | scanf("%f",&f); 25 | char str[99]; 26 | cs_ftoa(f,str); 27 | printf("The string is:%s\n",str); 28 | return 0; 29 | } 30 | 31 | void cs_itoa(int i, char *str) 32 | { 33 | if(i < 0) 34 | { 35 | *str++= '-'; 36 | i = -i; 37 | } 38 | int power,j; 39 | j=i; 40 | for( power=1;j>10;j/=10) 41 | power*=10; 42 | for(;power>0;power/=10) 43 | { 44 | *str++='0'+i/power; 45 | i%=power; 46 | } 47 | *str++ = '.'; 48 | } 49 | -------------------------------------------------------------------------------- /lab/lab2/C程序/cs_itoa.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void cs_itoa(int i, char *string) 5 | { 6 | if(i < 0) 7 | { 8 | *string++= '-'; 9 | i = -i; 10 | } 11 | int power,j; 12 | j=i; 13 | for( power=1;j>10;j/=10) 14 | power*=10; 15 | 16 | for(;power>0;power/=10) 17 | { 18 | *string++='0'+i/power; 19 | i%=power; 20 | } 21 | *string='\0'; 22 | } 23 | 24 | int main() 25 | { 26 | int x; 27 | char str[99]; 28 | printf("Input an integer:"); 29 | scanf("%d",&x); 30 | cs_itoa(x,str); 31 | printf("The string is:%s\n",str); 32 | } 33 | -------------------------------------------------------------------------------- /lab/lab2/C程序/fib_dg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib_int_dg(int n) 4 | { 5 | if (n == 1) 6 | { 7 | return 0; 8 | } 9 | if (n == 2) 10 | { 11 | return 1; 12 | } 13 | return fib_int_dg(n - 1) + fib_int_dg(n - 2); 14 | } 15 | 16 | long fib_long_dg(int n) 17 | { 18 | if (n == 1) 19 | { 20 | return 0; 21 | } 22 | if (n == 2) 23 | { 24 | return 1; 25 | } 26 | return fib_long_dg(n - 1) + fib_long_dg(n - 2); 27 | } 28 | 29 | unsigned fib_unsigned_dg(int n) 30 | { 31 | if (n == 1) 32 | { 33 | return 0; 34 | } 35 | if (n == 2) 36 | { 37 | return 1; 38 | } 39 | return fib_unsigned_dg(n - 1) + fib_unsigned_dg(n - 2); 40 | } 41 | 42 | unsigned long fib_unsigned_long_dg(int n) 43 | { 44 | if (n == 1) 45 | { 46 | return 0; 47 | } 48 | if (n == 2) 49 | { 50 | return 1; 51 | } 52 | return fib_unsigned_long_dg(n - 1) + fib_unsigned_long_dg(n - 2); 53 | } 54 | 55 | int main() 56 | { 57 | int n; 58 | printf("Input a number:"); 59 | scanf("%d",&n); 60 | printf("int:%d\n",fib_int_dg(n)); 61 | printf("long:%ld\n",fib_long_dg(n)); 62 | printf("unsigned:%u\n",fib_unsigned_dg(n)); 63 | printf("unsigned long:%lu\n",fib_unsigned_long_dg(n)); 64 | } 65 | -------------------------------------------------------------------------------- /lab/lab2/C程序/fib_loop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib_int_loop(int n) 4 | { 5 | if (n == 1) 6 | { 7 | return 0; 8 | } 9 | if (n == 2) 10 | { 11 | return 1; 12 | } 13 | int f1 = 0; 14 | int f2 = 1; 15 | int c = 0; 16 | for (int i = 3; i <= n; i++) 17 | { 18 | c = f1 + f2; 19 | f1 = f2; 20 | f2 = c; 21 | } 22 | 23 | return c; 24 | } 25 | 26 | long fib_long_loop(int n) 27 | { 28 | if (n == 1) 29 | { 30 | return 0; 31 | } 32 | if (n == 2) 33 | { 34 | return 1; 35 | } 36 | long f1 = 0; 37 | long f2 = 1; 38 | long c = 0; 39 | for (int i = 3; i <= n; i++) 40 | { 41 | c = f1 + f2; 42 | f1 = f2; 43 | f2 = c; 44 | } 45 | 46 | return c; 47 | } 48 | 49 | unsigned fib_unsigned_loop(int n) 50 | { 51 | if (n == 1) 52 | { 53 | return 0; 54 | } 55 | if (n == 2) 56 | { 57 | return 1; 58 | } 59 | unsigned f1 = 0; 60 | unsigned f2 = 1; 61 | unsigned c = 0; 62 | for (int i = 3; i <= n; i++) 63 | { 64 | c = f1 + f2; 65 | f1 = f2; 66 | f2 = c; 67 | } 68 | 69 | return c; 70 | } 71 | 72 | unsigned long fib_unsigned_long_loop(int n) 73 | { 74 | if (n == 1) 75 | { 76 | return 0; 77 | } 78 | if (n == 2) 79 | { 80 | return 1; 81 | } 82 | unsigned long f1 = 0; 83 | unsigned long f2 = 1; 84 | unsigned long c = 0; 85 | for (int i = 3; i <= n; i++) 86 | { 87 | c = f1 + f2; 88 | f1 = f2; 89 | f2 = c; 90 | } 91 | 92 | return c; 93 | } 94 | 95 | int main() 96 | { 97 | int n; 98 | printf("Input a number:"); 99 | scanf("%d",&n); 100 | printf("int:%d\n",fib_int_loop(n)); 101 | printf("long:%ld\n",fib_long_loop(n)); 102 | printf("unsigned:%u\n",fib_unsigned_loop(n)); 103 | printf("unsigned long:%lu\n",fib_unsigned_long_loop(n)); 104 | } 105 | -------------------------------------------------------------------------------- /lab/lab2/C程序/float0.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 1; 6 | printf("1/0 = %d\n",x/0); 7 | } 8 | -------------------------------------------------------------------------------- /lab/lab2/C程序/floatx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab2/C程序/floatx.c -------------------------------------------------------------------------------- /lab/lab2/C程序/utf8len.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int show_and_count_bytes(unsigned char *s) 5 | { 6 | int i; 7 | int t = 0; 8 | for(i = 0;i < strlen(s);i++) 9 | { 10 | //printf("%.2x ",s[i]); 11 | if(s[i] >= 0xc0 || s[i] < 0x80) 12 | { 13 | t++; 14 | } 15 | } 16 | return t; 17 | } 18 | 19 | int main() 20 | { 21 | unsigned char s[50]; 22 | printf("Please input a sentence:\n"); 23 | scanf("%s",s); 24 | printf("Lenth in strlen is:%d\n",strlen(s)); 25 | int t = show_and_count_bytes(s); 26 | printf("The real lenth is:%d\n",t); 27 | } 28 | -------------------------------------------------------------------------------- /lab/lab2/C程序/验证向偶数舍入.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float f1 = 1.234567500; 6 | float f2 = 1.234568500; 7 | printf("f1 = %f\n",f1); 8 | printf("f2 = %f\n",f2); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lab/lab2/祁天-lab2实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab2/祁天-lab2实验报告.doc -------------------------------------------------------------------------------- /lab/lab3/祁天-1183200123-bomb ans.txt: -------------------------------------------------------------------------------- 1 | I am just a renegade hockey mom. 2 | 1 2 4 6 8 16 32 3 | 0 240 4 | 2 108 5 | beldog 6 | 1 5 4 6 3 2 -------------------------------------------------------------------------------- /lab/lab3/祁天-1183200123.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab3/祁天-1183200123.doc -------------------------------------------------------------------------------- /lab/lab3/祁天-1183200123.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab3/祁天-1183200123.pdf -------------------------------------------------------------------------------- /lab/lab4/1803003_1183200123_祁天.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/1803003_1183200123_祁天.doc -------------------------------------------------------------------------------- /lab/lab4/1803003_1183200123_祁天.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/1803003_1183200123_祁天.pdf -------------------------------------------------------------------------------- /lab/lab4/bang_1183200123.txt: -------------------------------------------------------------------------------- 1 | c7 05 60 e1 04 08 21 5c 68 77 68 39 8c 04 08 c3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 98 33 68 55 2 | -------------------------------------------------------------------------------- /lab/lab4/bang_1183200123_raw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/bang_1183200123_raw.txt -------------------------------------------------------------------------------- /lab/lab4/boom_1183200123.txt: -------------------------------------------------------------------------------- 1 | b8 21 5c 68 77 68 a7 8c 04 08 c3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e0 33 68 55 98 33 68 55 2 | -------------------------------------------------------------------------------- /lab/lab4/boom_1183200123_raw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/boom_1183200123_raw.txt -------------------------------------------------------------------------------- /lab/lab4/fizz_1183200123.txt: -------------------------------------------------------------------------------- 1 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e8 8b 04 08 00 00 00 00 21 5c 68 77 2 | -------------------------------------------------------------------------------- /lab/lab4/fizz_1183200123_raw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/fizz_1183200123_raw.txt -------------------------------------------------------------------------------- /lab/lab4/nitro_1183200123.txt: -------------------------------------------------------------------------------- 1 | 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 b8 21 5c 68 77 8d 6c 24 18 83 ec 04 c7 04 24 21 8d 04 08 c3 08 32 68 55 2 | -------------------------------------------------------------------------------- /lab/lab4/smoke_1183200123.txt: -------------------------------------------------------------------------------- 1 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 bb 8b 04 08 2 | -------------------------------------------------------------------------------- /lab/lab4/smoke_1183200123_raw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab4/smoke_1183200123_raw.txt -------------------------------------------------------------------------------- /lab/lab5/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/main.o -------------------------------------------------------------------------------- /lab/lab5/phase1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase1.o -------------------------------------------------------------------------------- /lab/lab5/phase2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase2.o -------------------------------------------------------------------------------- /lab/lab5/phase3.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase3.o -------------------------------------------------------------------------------- /lab/lab5/phase3_patch.c: -------------------------------------------------------------------------------- 1 | char SDFyFKcKmx[256] = { 2 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 3 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 4 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 5 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 6 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 7 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 8 | '0','0','8','0','0','0','0','0','0','0','0','0','0','3','0','2', 9 | '1','1','0','0','0','2','0','1','0','0','3','0','0','0','0','0', 10 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 11 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 12 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 13 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 14 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 15 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 16 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 17 | '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', 18 | }; 19 | -------------------------------------------------------------------------------- /lab/lab5/phase3_patch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase3_patch.o -------------------------------------------------------------------------------- /lab/lab5/phase4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase4.o -------------------------------------------------------------------------------- /lab/lab5/phase5.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/phase5.o -------------------------------------------------------------------------------- /lab/lab5/祁天-1183200123.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/祁天-1183200123.doc -------------------------------------------------------------------------------- /lab/lab5/祁天-1183200123.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab5/祁天-1183200123.pdf -------------------------------------------------------------------------------- /lab/lab6/1183200123-祁天.tar: -------------------------------------------------------------------------------- 1 | csim.c0000777000175000017500000001515613572470613012010 0ustar qt1183200123qt1183200123#include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "cachelab.h" 11 | 12 | //#define DEBUG_ON 13 | #define ADDRESS_LENGTH 64 14 | 15 | /* Type: Memory address */ 16 | typedef unsigned long long int mem_addr_t; 17 | 18 | /* Type: Cache line 19 | LRU is a counter used to implement LRU replacement policy */ 20 | typedef struct cache_line { 21 | char valid; 22 | mem_addr_t tag; //64位 23 | unsigned long long int lru; //最近访问次数 24 | } cache_line_t; 25 | 26 | typedef cache_line_t* cache_set_t; //cache组 27 | typedef cache_set_t* cache_t; //cache 28 | 29 | /* Globals set by command line args */ 30 | int verbosity = 0; /* print trace if set */ 31 | int s = 0; /* set index bits */ 32 | int b = 0; /* block offset bits */ 33 | int E = 0; /* associativity */ 34 | char* trace_file = NULL; 35 | 36 | /* Derived from command line args */ 37 | int S; /* number of sets */ 38 | int B; /* block size (bytes) */ 39 | 40 | /* Counters used to record cache statistics */ 41 | int miss_count = 0; 42 | int hit_count = 0; 43 | int eviction_count = 0; 44 | unsigned long long int lru_counter = 1; 45 | 46 | /* The cache we are simulating */ 47 | cache_t cache; 48 | mem_addr_t set_index_mask; 49 | 50 | /* 51 | * initCache - Allocate memory, write 0's for valid and tag and LRU 52 | * also computes the set_index_mask 53 | */ 54 | void initCache() 55 | { 56 | cache = (cache_t)calloc(S, sizeof(cache_set_t)); 57 | for (int i = 0; i < S; i++) 58 | cache[i] = (cache_set_t)calloc(E, sizeof(cache_line_t)); 59 | } 60 | 61 | /* 62 | * freeCache - free allocated memory 63 | */ 64 | void freeCache() 65 | { 66 | for (int i = 0; i < S; i++) 67 | free(cache[i]); 68 | free(cache); 69 | } 70 | 71 | /* 72 | * accessData - Access data at memory address addr. 73 | * If it is already in cache, increast hit_count 74 | * If it is not in cache, bring it in cache, increase miss count. 75 | * Also increase eviction_count if a line is evicted. 76 | */ 77 | void accessData(mem_addr_t addr) 78 | { 79 | // long block_bits; 80 | long set_bits; 81 | long tag_bits; 82 | int i; 83 | cache_set_t chosen_set; 84 | int empty_line_index; 85 | 86 | // block_bits = addr & ((1 << b) - 1); 87 | addr >>= b; 88 | set_bits = addr & ((1 << s) - 1); 89 | addr >>= s; 90 | tag_bits = addr; 91 | chosen_set = cache[set_bits]; 92 | 93 | empty_line_index = -1; 94 | //find 95 | for (i = 0; i < E; i++) 96 | { 97 | if (chosen_set[i].tag == tag_bits && chosen_set[i].valid == 1) 98 | { 99 | chosen_set[i].lru = lru_counter; 100 | hit_count++; //hit 101 | break; 102 | } 103 | if (chosen_set[i].valid == 0) 104 | { 105 | empty_line_index = i; 106 | } 107 | } 108 | 109 | if (i == E) //not hit 110 | { 111 | miss_count++; 112 | if (empty_line_index != -1) //exist empty 113 | { 114 | chosen_set[empty_line_index].tag = tag_bits; 115 | chosen_set[empty_line_index].valid = 1; 116 | chosen_set[empty_line_index].lru = lru_counter; 117 | } 118 | else //need evict 119 | { 120 | unsigned long long int min_lru; 121 | int min_lru_index; 122 | 123 | eviction_count++; 124 | 125 | min_lru = chosen_set[0].lru; 126 | min_lru_index = 0; 127 | for (i = 1; i < E; i++) 128 | { 129 | if (chosen_set[i].lru < min_lru) 130 | { 131 | min_lru = chosen_set[i].lru; 132 | min_lru_index = i; 133 | } 134 | } 135 | chosen_set[min_lru_index].tag = tag_bits; 136 | chosen_set[min_lru_index].valid = 1; 137 | chosen_set[min_lru_index].lru = lru_counter; 138 | } 139 | } 140 | lru_counter++; 141 | } 142 | 143 | 144 | /* 145 | * replayTrace - replays the given trace file against the cache 146 | */ 147 | void replayTrace(char* trace_fn) 148 | { 149 | char buf[1000]; 150 | mem_addr_t addr=0; 151 | unsigned int len=0; 152 | FILE* trace_fp = fopen(trace_fn, "r"); 153 | 154 | if(!trace_fp){ 155 | fprintf(stderr, "%s: %s\n", trace_fn, strerror(errno)); 156 | exit(1); 157 | } 158 | 159 | while( fgets(buf, 1000, trace_fp) != NULL) { 160 | if(buf[1]=='S' || buf[1]=='L' || buf[1]=='M') { 161 | sscanf(buf+3, "%llx,%u", &addr, &len); 162 | 163 | if(verbosity) 164 | printf("%c %llx,%u ", buf[1], addr, len); 165 | 166 | accessData(addr); 167 | 168 | /* If the instruction is R/W then access again */ 169 | if(buf[1]=='M') 170 | accessData(addr); 171 | 172 | if (verbosity) 173 | printf("\n"); 174 | } 175 | } 176 | 177 | fclose(trace_fp); 178 | } 179 | 180 | /* 181 | * printUsage - Print usage info 182 | */ 183 | void printUsage(char* argv[]) 184 | { 185 | printf("Usage: %s [-hv] -s -E -b -t \n", argv[0]); //argv[0]指向输入的程序路径及名称 186 | printf("Options:\n"); 187 | printf(" -h Print this help message.\n"); 188 | printf(" -v Optional verbose flag.\n"); 189 | printf(" -s Number of set index bits.\n"); 190 | printf(" -E Number of lines per set.\n"); 191 | printf(" -b Number of block offset bits.\n"); 192 | printf(" -t Trace file.\n"); 193 | printf("\nExamples:\n"); 194 | printf(" linux> %s -s 4 -E 1 -b 4 -t traces/yi.trace\n", argv[0]); 195 | printf(" linux> %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0]); 196 | exit(0); 197 | } 198 | 199 | /* 200 | * main - Main routine 201 | */ 202 | int main(int argc, char* argv[]) 203 | { 204 | char c; 205 | 206 | while( (c=getopt(argc,argv,"s:E:b:t:vh")) != -1){ 207 | switch(c){ 208 | case 's': 209 | s = atoi(optarg); 210 | break; 211 | case 'E': 212 | E = atoi(optarg); 213 | break; 214 | case 'b': 215 | b = atoi(optarg); 216 | break; 217 | case 't': 218 | trace_file = optarg; 219 | break; 220 | case 'v': 221 | verbosity = 1; 222 | break; 223 | case 'h': 224 | printUsage(argv); 225 | exit(0); 226 | default: 227 | printUsage(argv); 228 | exit(1); 229 | } 230 | } 231 | 232 | /* Make sure that all required command line args were specified */ 233 | if (s == 0 || E == 0 || b == 0 || trace_file == NULL) { 234 | printf("%s: Missing required command line argument\n", argv[0]); 235 | printUsage(argv); 236 | exit(1); 237 | } 238 | 239 | /* Compute S, E and B from command line args */ 240 | S = 1< 272 | #include "cachelab.h" 273 | 274 | int is_transpose(int M, int N, int A[N][M], int B[M][N]); 275 | 276 | /* 277 | * transpose_submit - This is the solution transpose function that you 278 | * will be graded on for Part B of the assignment. Do not change 279 | * the description string "Transpose submission", as the driver 280 | * searches for that string to identify the transpose function to 281 | * be graded. 282 | trans._submit——这是您将针对作业B部分进行评分的解决方案transpose函数 283 | 不要更改描述字符串“Transpose submission”, 284 | 因为驱动程序搜索该字符串以标识要分级的转置函数。 285 | */ 286 | char transpose_submit_desc[] = "Transpose submission"; 287 | void transpose_submit(int M, int N, int A[N][M], int B[M][N]) 288 | { 289 | int i,j,k,p,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8; 290 | if(M==32&&N==32) 291 | { 292 | for(i=0;i 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* Misc manifest constants */ 17 | #define MAXLINE 1024 /* max line size */ 18 | #define MAXARGS 128 /* max args on a command line */ 19 | #define MAXJOBS 16 /* max jobs at any point in time */ 20 | #define MAXJID 1 << 16 /* max job ID */ 21 | 22 | /* Job states */ 23 | #define UNDEF 0 /* undefined */ 24 | #define FG 1 /* running in foreground */ 25 | #define BG 2 /* running in background */ 26 | #define ST 3 /* stopped */ 27 | 28 | /* 29 | * Jobs states: FG (foreground), BG (background), ST (stopped) 30 | * Job state transitions and enabling actions: 31 | * FG -> ST : ctrl-z 32 | * ST -> FG : fg command 33 | * ST -> BG : bg command 34 | * BG -> FG : fg command 35 | * At most 1 job can be in the FG state. 36 | */ 37 | 38 | /* Global variables */ 39 | extern char **environ; /* defined in libc */ 40 | char prompt[] = "tsh> "; /* command line prompt (DO NOT CHANGE) */ 41 | int verbose = 0; /* if true, print additional output */ 42 | int nextjid = 1; /* next job ID to allocate */ 43 | char sbuf[MAXLINE]; /* for composing sprintf messages */ 44 | 45 | struct job_t 46 | { /* The job struct */ 47 | pid_t pid; /* job PID */ 48 | int jid; /* job ID [1, 2, ...] */ 49 | int state; /* UNDEF, BG, FG, or ST */ 50 | char cmdline[MAXLINE]; /* command line */ 51 | }; 52 | struct job_t jobs[MAXJOBS]; /* The job list */ 53 | /* End global variables */ 54 | 55 | /* Function prototypes */ 56 | 57 | /* Here are the functions that you will implement */ 58 | void eval(char *cmdline); 59 | int builtin_cmd(char **argv); 60 | void do_bgfg(char **argv); 61 | void waitfg(pid_t pid); 62 | 63 | void sigchld_handler(int sig); 64 | void sigtstp_handler(int sig); 65 | void sigint_handler(int sig); 66 | 67 | /* Here are helper routines that we've provided for you */ 68 | int parseline(const char *cmdline, char **argv); 69 | void sigquit_handler(int sig); 70 | 71 | void clearjob(struct job_t *job); 72 | void initjobs(struct job_t *jobs); 73 | int maxjid(struct job_t *jobs); 74 | int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline); 75 | int deletejob(struct job_t *jobs, pid_t pid); 76 | pid_t fgpid(struct job_t *jobs); 77 | struct job_t *getjobpid(struct job_t *jobs, pid_t pid); 78 | struct job_t *getjobjid(struct job_t *jobs, int jid); 79 | int pid2jid(pid_t pid); 80 | void listjobs(struct job_t *jobs); 81 | 82 | void usage(void); 83 | void unix_error(char *msg); 84 | void app_error(char *msg); 85 | typedef void handler_t(int); 86 | handler_t *Signal(int signum, handler_t *handler); 87 | 88 | /* 89 | * main - The shell's main routine 90 | */ 91 | int main(int argc, char **argv) 92 | { 93 | char c; 94 | char cmdline[MAXLINE]; 95 | int emit_prompt = 1; /* emit prompt (default) */ 96 | 97 | /* Redirect stderr to stdout (so that driver will get all output 98 | * on the pipe connected to stdout) */ 99 | dup2(1, 2); 100 | 101 | /* Parse the command line */ 102 | while ((c = getopt(argc, argv, "hvp")) != EOF) 103 | { 104 | switch (c) 105 | { 106 | case 'h': /* print help message */ 107 | usage(); 108 | break; 109 | case 'v': /* emit additional diagnostic info */ 110 | verbose = 1; 111 | break; 112 | case 'p': /* don't print a prompt */ 113 | emit_prompt = 0; /* handy for automatic testing */ 114 | break; 115 | default: 116 | usage(); 117 | } 118 | } 119 | 120 | /* Install the signal handlers */ 121 | 122 | /* These are the ones you will need to implement */ 123 | Signal(SIGINT, sigint_handler); /* ctrl-c */ 124 | Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */ 125 | Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */ 126 | 127 | /* This one provides a clean way to kill the shell */ 128 | Signal(SIGQUIT, sigquit_handler); 129 | 130 | /* Initialize the job list */ 131 | initjobs(jobs); 132 | 133 | /* Execute the shell's read/eval loop */ 134 | while (1) 135 | { 136 | 137 | /* Read command line */ 138 | if (emit_prompt) 139 | { 140 | printf("%s", prompt); 141 | fflush(stdout); 142 | } 143 | if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)) 144 | app_error("fgets error"); 145 | if (feof(stdin)) 146 | { /* End of file (ctrl-d) */ 147 | fflush(stdout); 148 | exit(0); 149 | } 150 | 151 | /* Evaluate the command line */ 152 | eval(cmdline); 153 | fflush(stdout); 154 | fflush(stdout); 155 | } 156 | 157 | exit(0); /* control never reaches here */ 158 | } 159 | 160 | /* 161 | * eval - Evaluate the command line that the user has just typed in 162 | * 163 | * If the user has requested a built-in command (quit, jobs, bg or fg) 164 | * then execute it immediately. Otherwise, fork a child process and 165 | * run the job in the context of the child. If the job is running in 166 | * the foreground, wait for it to terminate and then return. Note: 167 | * each child process must have a unique process group ID so that our 168 | * background children don't receive SIGINT (SIGTSTP) from the kernel 169 | * when we type ctrl-c (ctrl-z) at the keyboard. 170 | */ 171 | void eval(char *cmdline) 172 | { 173 | /* $begin handout */ 174 | char *argv[MAXARGS]; /* argv for execve() */ 175 | int bg; /* should the job run in bg or fg? */ 176 | pid_t pid; /* process id */ 177 | sigset_t mask; /* signal mask */ 178 | 179 | /* Parse command line */ 180 | bg = parseline(cmdline, argv); 181 | if (argv[0] == NULL) 182 | return; /* ignore empty lines */ 183 | 184 | if (!builtin_cmd(argv)) 185 | { 186 | 187 | /* 188 | * This is a little tricky. Block SIGCHLD, SIGINT, and SIGTSTP 189 | * signals until we can add the job to the job list. This 190 | * eliminates some nasty races between adding a job to the job 191 | * list and the arrival of SIGCHLD, SIGINT, and SIGTSTP signals. 192 | */ 193 | 194 | if (sigemptyset(&mask) < 0) 195 | unix_error("sigemptyset error"); 196 | if (sigaddset(&mask, SIGCHLD)) 197 | unix_error("sigaddset error"); 198 | if (sigaddset(&mask, SIGINT)) 199 | unix_error("sigaddset error"); 200 | if (sigaddset(&mask, SIGTSTP)) 201 | unix_error("sigaddset error"); 202 | if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) 203 | unix_error("sigprocmask error"); 204 | 205 | /* Create a child process */ 206 | if ((pid = fork()) < 0) 207 | unix_error("fork error"); 208 | 209 | /* 210 | * Child process 211 | */ 212 | 213 | if (pid == 0) 214 | { 215 | /* Child unblocks signals */ 216 | sigprocmask(SIG_UNBLOCK, &mask, NULL); 217 | 218 | /* Each new job must get a new process group ID 219 | so that the kernel doesn't send ctrl-c and ctrl-z 220 | signals to all of the shell's jobs */ 221 | if (setpgid(0, 0) < 0) 222 | unix_error("setpgid error"); 223 | 224 | /* Now load and run the program in the new job */ 225 | if (execve(argv[0], argv, environ) < 0) 226 | { 227 | printf("%s: Command not found\n", argv[0]); 228 | exit(0); 229 | } 230 | } 231 | 232 | /* 233 | * Parent process 234 | */ 235 | 236 | /* Parent adds the job, and then unblocks signals so that 237 | the signals handlers can run again */ 238 | addjob(jobs, pid, (bg == 1 ? BG : FG), cmdline); 239 | sigprocmask(SIG_UNBLOCK, &mask, NULL); 240 | 241 | if (!bg) 242 | waitfg(pid); 243 | else 244 | printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline); 245 | } 246 | /* $end handout */ 247 | return; 248 | } 249 | 250 | /* 251 | * parseline - Parse the command line and build the argv array. 252 | * 253 | * Characters enclosed in single quotes are treated as a single 254 | * argument. Return true if the user has requested a BG job, false if 255 | * the user has requested a FG job. 256 | */ 257 | int parseline(const char *cmdline, char **argv) 258 | { 259 | static char array[MAXLINE]; /* holds local copy of command line */ 260 | char *buf = array; /* ptr that traverses command line */ 261 | char *delim; /* points to first space delimiter */ 262 | int argc; /* number of args */ 263 | int bg; /* background job? */ 264 | 265 | strcpy(buf, cmdline); 266 | buf[strlen(buf) - 1] = ' '; /* replace trailing '\n' with space */ 267 | while (*buf && (*buf == ' ')) /* ignore leading spaces */ 268 | buf++; 269 | 270 | /* Build the argv list */ 271 | argc = 0; 272 | if (*buf == '\'') 273 | { 274 | buf++; 275 | delim = strchr(buf, '\''); 276 | } 277 | else 278 | { 279 | delim = strchr(buf, ' '); 280 | } 281 | 282 | while (delim) 283 | { 284 | argv[argc++] = buf; 285 | *delim = '\0'; 286 | buf = delim + 1; 287 | while (*buf && (*buf == ' ')) /* ignore spaces */ 288 | buf++; 289 | 290 | if (*buf == '\'') 291 | { 292 | buf++; 293 | delim = strchr(buf, '\''); 294 | } 295 | else 296 | { 297 | delim = strchr(buf, ' '); 298 | } 299 | } 300 | argv[argc] = NULL; 301 | 302 | if (argc == 0) /* ignore blank line */ 303 | return 1; 304 | 305 | /* should the job run in the background? */ 306 | if ((bg = (*argv[argc - 1] == '&')) != 0) 307 | { 308 | argv[--argc] = NULL; 309 | } 310 | return bg; 311 | } 312 | 313 | /* 314 | * builtin_cmd - If the user has typed a built-in command then execute 315 | * it immediately. 316 | */ 317 | int builtin_cmd(char **argv) 318 | { 319 | sigset_t mask, prev_mask; 320 | if (!strcmp(argv[0], "quit")) //若第一个参数为quit 321 | { 322 | 323 | sigfillset(&mask); 324 | sigprocmask(SIG_BLOCK, &mask, &prev_mask); //暂时阻隔所有信号,以保护对全局变量的访问 325 | 326 | for (int i = 0; i < MAXJOBS; i++) 327 | { 328 | if (jobs[i].state != UNDEF) //杀死所有后台运行、挂起的进程组 329 | { 330 | kill(-(jobs[i].pid), SIGKILL); 331 | deletejob(jobs, jobs[i].pid); 332 | } 333 | } 334 | sigprocmask(SIG_SETMASK, &prev_mask, NULL); //解除阻隔 335 | 336 | exit(0); 337 | } 338 | else if (!strcmp(argv[0], "fg") || !strcmp(argv[0], "bg")) //若第一个参数为fg或bg 339 | { 340 | do_bgfg(argv); 341 | return 1; //返回:“是” 内部参数 342 | } 343 | else if (!strcmp(argv[0], "jobs")) 344 | { 345 | listjobs(jobs); 346 | return 1; //返回:“是” 内部参数 347 | } 348 | else 349 | return 0; //返回:“不是” 内部参数 350 | } 351 | 352 | /* 353 | * do_bgfg - Execute the builtin bg and fg commands 354 | */ 355 | void do_bgfg(char **argv) 356 | { 357 | /* $begin handout */ 358 | struct job_t *jobp = NULL; 359 | 360 | /* Ignore command if no argument */ 361 | if (argv[1] == NULL) 362 | { 363 | printf("%s command requires PID or %%jobid argument\n", argv[0]); 364 | return; 365 | } 366 | 367 | /* Parse the required PID or %JID arg */ 368 | if (isdigit(argv[1][0])) 369 | { 370 | pid_t pid = atoi(argv[1]); 371 | if (!(jobp = getjobpid(jobs, pid))) 372 | { 373 | printf("(%d): No such process\n", pid); 374 | return; 375 | } 376 | } 377 | else if (argv[1][0] == '%') 378 | { 379 | int jid = atoi(&argv[1][1]); 380 | if (!(jobp = getjobjid(jobs, jid))) 381 | { 382 | printf("%s: No such job\n", argv[1]); 383 | return; 384 | } 385 | } 386 | else 387 | { 388 | printf("%s: argument must be a PID or %%jobid\n", argv[0]); 389 | return; 390 | } 391 | 392 | /* bg command */ 393 | if (!strcmp(argv[0], "bg")) 394 | { 395 | if (kill(-(jobp->pid), SIGCONT) < 0) 396 | unix_error("kill (bg) error"); 397 | jobp->state = BG; 398 | printf("[%d] (%d) %s", jobp->jid, jobp->pid, jobp->cmdline); 399 | } 400 | 401 | /* fg command */ 402 | else if (!strcmp(argv[0], "fg")) 403 | { 404 | if (kill(-(jobp->pid), SIGCONT) < 0) 405 | unix_error("kill (fg) error"); 406 | jobp->state = FG; 407 | waitfg(jobp->pid); 408 | } 409 | else 410 | { 411 | printf("do_bgfg: Internal error\n"); 412 | exit(0); 413 | } 414 | /* $end handout */ 415 | return; 416 | } 417 | 418 | /* 419 | * waitfg - Block until process pid is no longer the foreground process 420 | */ 421 | void waitfg(pid_t pid) 422 | { 423 | struct job_t *jobp = NULL; 424 | 425 | jobp = getjobpid(jobs, pid); //获取指向等待进程的指针 426 | while (jobp->state == FG) //当该进程不再是前台进程时,跳出循环 427 | { 428 | sleep(1); 429 | } 430 | 431 | return; 432 | } 433 | 434 | /***************** 435 | * Signal handlers 436 | *****************/ 437 | 438 | /* 439 | * sigchld_handler - The kernel sends a SIGCHLD to the shell whenever 440 | * a child job terminates (becomes a zombie), or stops because it 441 | * received a SIGSTOP or SIGTSTP signal. The handler reaps all 442 | * available zombie children, but doesn't wait for any other 443 | * currently running children to terminate. 444 | */ 445 | 446 | /*当有子进程挂起或终止时, 447 | *进入此信号处理函数。 448 | */ 449 | void sigchld_handler(int sig) 450 | { 451 | int olderrno = errno; //保存errno 452 | int status; 453 | int pid; 454 | 455 | /*回收当前每一个僵死进程 或 处理每个挂起的进程*/ 456 | while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) 457 | { 458 | if (WIFEXITED(status)) //若子进程是通过exit或return正常退出 459 | deletejob(jobs, pid); 460 | else if (WIFSIGNALED(status)) //若子进程是收到信号而终止 461 | { 462 | if (WTERMSIG(status) != SIGKILL) 463 | { 464 | printf("Job [%d] (%d) terminated by signal %d\n", 465 | pid2jid(pid), pid, WTERMSIG(status)); //打印提示 466 | } 467 | deletejob(jobs, pid); //将此进程从进程列表中删除 468 | } 469 | else if (WIFSTOPPED(status)) //若子进程是收到信号而挂起 470 | { 471 | printf("Job [%d] (%d) stopped by signal %d\n", 472 | pid2jid(pid), pid, WSTOPSIG(status)); //打印提示 473 | getjobpid(jobs, pid)->state = ST; //将此进程标记为挂起的进程 474 | } 475 | } 476 | 477 | errno = olderrno; //恢复errno 478 | return; 479 | } 480 | 481 | /* 482 | * sigint_handler - The kernel sends a SIGINT to the shell whenver the 483 | * user types ctrl-c at the keyboard. Catch it and send it along 484 | * to the foreground job. 485 | */ 486 | void sigint_handler(int sig) 487 | { 488 | sigset_t mask, prev_mask; 489 | int olderrno = errno; //保存errno 490 | 491 | sigfillset(&mask); 492 | sigprocmask(SIG_BLOCK, &mask, &prev_mask); //暂时阻隔所有信号,以保护对全局变量的访问 493 | 494 | for (int i = 0; i < MAXJOBS; i++) 495 | { 496 | if (jobs[i].pid != 0) 497 | { 498 | if (jobs[i].state == FG) //找到前台进程,并发送信号将其杀死 499 | { 500 | if (kill(-(jobs[i].pid), SIGINT) < 0) 501 | unix_error("kill error\n"); 502 | } 503 | } 504 | } 505 | 506 | sigprocmask(SIG_SETMASK, &prev_mask, NULL); //解除阻隔 507 | errno = olderrno; //恢复errno 508 | return; 509 | } 510 | 511 | /* 512 | * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever 513 | * the user types ctrl-z at the keyboard. Catch it and suspend the 514 | * foreground job by sending it a SIGTSTP. 515 | */ 516 | void sigtstp_handler(int sig) 517 | { 518 | sigset_t mask, prev_mask; 519 | int olderrno = errno; //保存errno 520 | 521 | sigfillset(&mask); 522 | sigprocmask(SIG_BLOCK, &mask, &prev_mask); //暂时阻隔所有信号,以保护对全局变量的访问 523 | 524 | for (int i = 0; i < MAXJOBS; i++) 525 | { 526 | if (jobs[i].pid != 0) 527 | { 528 | if (jobs[i].state == FG) 529 | { 530 | if (kill(-(jobs[i].pid), SIGTSTP) < 0) //找到前台进程,并发送信号将其停止 531 | unix_error("kill error\n"); 532 | } 533 | } 534 | } 535 | 536 | sigprocmask(SIG_SETMASK, &prev_mask, NULL); //解除阻隔 537 | errno = olderrno; //恢复errno 538 | return; 539 | } 540 | 541 | /********************* 542 | * End signal handlers 543 | *********************/ 544 | 545 | /*********************************************** 546 | * Helper routines that manipulate the job list 547 | **********************************************/ 548 | 549 | /* clearjob - Clear the entries in a job struct */ 550 | void clearjob(struct job_t *job) 551 | { 552 | job->pid = 0; 553 | job->jid = 0; 554 | job->state = UNDEF; 555 | job->cmdline[0] = '\0'; 556 | } 557 | 558 | /* initjobs - Initialize the job list */ 559 | void initjobs(struct job_t *jobs) 560 | { 561 | int i; 562 | 563 | for (i = 0; i < MAXJOBS; i++) 564 | clearjob(&jobs[i]); 565 | } 566 | 567 | /* maxjid - Returns largest allocated job ID */ 568 | int maxjid(struct job_t *jobs) 569 | { 570 | int i, max = 0; 571 | 572 | for (i = 0; i < MAXJOBS; i++) 573 | if (jobs[i].jid > max) 574 | max = jobs[i].jid; 575 | return max; 576 | } 577 | 578 | /* addjob - Add a job to the job list */ 579 | int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline) 580 | { 581 | int i; 582 | 583 | if (pid < 1) 584 | return 0; 585 | 586 | for (i = 0; i < MAXJOBS; i++) 587 | { 588 | if (jobs[i].pid == 0) 589 | { 590 | jobs[i].pid = pid; 591 | jobs[i].state = state; 592 | jobs[i].jid = nextjid++; 593 | if (nextjid > MAXJOBS) 594 | nextjid = 1; 595 | strcpy(jobs[i].cmdline, cmdline); 596 | if (verbose) 597 | { 598 | printf("Added job [%d] %d %s\n", jobs[i].jid, jobs[i].pid, jobs[i].cmdline); 599 | } 600 | return 1; 601 | } 602 | } 603 | printf("Tried to create too many jobs\n"); 604 | return 0; 605 | } 606 | 607 | /* deletejob - Delete a job whose PID=pid from the job list */ 608 | int deletejob(struct job_t *jobs, pid_t pid) 609 | { 610 | int i; 611 | 612 | if (pid < 1) 613 | return 0; 614 | 615 | for (i = 0; i < MAXJOBS; i++) 616 | { 617 | if (jobs[i].pid == pid) 618 | { 619 | clearjob(&jobs[i]); 620 | nextjid = maxjid(jobs) + 1; 621 | return 1; 622 | } 623 | } 624 | return 0; 625 | } 626 | 627 | /* fgpid - Return PID of current foreground job, 0 if no such job */ 628 | pid_t fgpid(struct job_t *jobs) 629 | { 630 | int i; 631 | 632 | for (i = 0; i < MAXJOBS; i++) 633 | if (jobs[i].state == FG) 634 | return jobs[i].pid; 635 | return 0; 636 | } 637 | 638 | /* getjobpid - Find a job (by PID) on the job list */ 639 | struct job_t *getjobpid(struct job_t *jobs, pid_t pid) 640 | { 641 | int i; 642 | 643 | if (pid < 1) 644 | return NULL; 645 | for (i = 0; i < MAXJOBS; i++) 646 | if (jobs[i].pid == pid) 647 | return &jobs[i]; 648 | return NULL; 649 | } 650 | 651 | /* getjobjid - Find a job (by JID) on the job list */ 652 | struct job_t *getjobjid(struct job_t *jobs, int jid) 653 | { 654 | int i; 655 | 656 | if (jid < 1) 657 | return NULL; 658 | for (i = 0; i < MAXJOBS; i++) 659 | if (jobs[i].jid == jid) 660 | return &jobs[i]; 661 | return NULL; 662 | } 663 | 664 | /* pid2jid - Map process ID to job ID */ 665 | int pid2jid(pid_t pid) 666 | { 667 | int i; 668 | 669 | if (pid < 1) 670 | return 0; 671 | for (i = 0; i < MAXJOBS; i++) 672 | if (jobs[i].pid == pid) 673 | { 674 | return jobs[i].jid; 675 | } 676 | return 0; 677 | } 678 | 679 | /* listjobs - Print the job list */ 680 | void listjobs(struct job_t *jobs) 681 | { 682 | int i; 683 | 684 | for (i = 0; i < MAXJOBS; i++) 685 | { 686 | if (jobs[i].pid != 0) 687 | { 688 | printf("[%d] (%d) ", jobs[i].jid, jobs[i].pid); 689 | switch (jobs[i].state) 690 | { 691 | case BG: 692 | printf("Running "); 693 | break; 694 | case FG: 695 | printf("Foreground "); 696 | break; 697 | case ST: 698 | printf("Stopped "); 699 | break; 700 | default: 701 | printf("listjobs: Internal error: job[%d].state=%d ", 702 | i, jobs[i].state); 703 | } 704 | printf("%s", jobs[i].cmdline); 705 | } 706 | } 707 | } 708 | /****************************** 709 | * end job list helper routines 710 | ******************************/ 711 | 712 | /*********************** 713 | * Other helper routines 714 | ***********************/ 715 | 716 | /* 717 | * usage - print a help message 718 | */ 719 | void usage(void) 720 | { 721 | printf("Usage: shell [-hvp]\n"); 722 | printf(" -h print this message\n"); 723 | printf(" -v print additional diagnostic information\n"); 724 | printf(" -p do not emit a command prompt\n"); 725 | exit(1); 726 | } 727 | 728 | /* 729 | * unix_error - unix-style error routine 730 | */ 731 | void unix_error(char *msg) 732 | { 733 | fprintf(stdout, "%s: %s\n", msg, strerror(errno)); 734 | exit(1); 735 | } 736 | 737 | /* 738 | * app_error - application-style error routine 739 | */ 740 | void app_error(char *msg) 741 | { 742 | fprintf(stdout, "%s\n", msg); 743 | exit(1); 744 | } 745 | 746 | /* 747 | * Signal - wrapper for the sigaction function 748 | */ 749 | handler_t *Signal(int signum, handler_t *handler) 750 | { 751 | struct sigaction action, old_action; 752 | 753 | action.sa_handler = handler; 754 | sigemptyset(&action.sa_mask); /* block sigs of type being handled */ 755 | action.sa_flags = SA_RESTART; /* restart syscalls if possible */ 756 | 757 | if (sigaction(signum, &action, &old_action) < 0) 758 | unix_error("Signal error"); 759 | return (old_action.sa_handler); 760 | } 761 | 762 | /* 763 | * sigquit_handler - The driver program can gracefully terminate the 764 | * child shell by sending it a SIGQUIT signal. 765 | */ 766 | void sigquit_handler(int sig) 767 | { 768 | printf("Terminating after receipt of SIGQUIT signal\n"); 769 | exit(1); 770 | } 771 | -------------------------------------------------------------------------------- /lab/lab8/mm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mm-naive.c - The fastest, least memory-efficient malloc package. 3 | * 4 | * In this naive approach, a block is allocated by simply incrementing 5 | * the brk pointer. A block is pure payload. There are no headers or 6 | * footers. Blocks are never coalesced or reused. Realloc is 7 | * implemented directly using mm_malloc and mm_free. 8 | * 9 | * NOTE TO STUDENTS: Replace this header comment with your own header 10 | * comment that gives a high level description of your solution. 11 | */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "mm.h" 19 | #include "memlib.h" 20 | 21 | /********************************************************* 22 | * NOTE TO STUDENTS: Before you do anything else, please 23 | * provide your team information in the following struct. 24 | ********************************************************/ 25 | team_t team = { 26 | /* Team name */ 27 | "ateam", 28 | /* First member's full name */ 29 | "Qi Tian", 30 | /* First member's email address */ 31 | "1183200123@stu.hit.edu.cn", 32 | /* Second member's full name (leave blank if none) */ 33 | "", 34 | /* Second member's email address (leave blank if none) */ 35 | "" 36 | }; 37 | 38 | 39 | /* Basic constants and macros */ 40 | #define ALIGN(size) ((((size) + (DSIZE-1)) / (DSIZE)) * (DSIZE)) //对齐 41 | #define WSIZE 4 42 | #define DSIZE 8 43 | #define INITCHUNKSIZE (1<<6) 44 | #define CHUNKSIZE (1<<12) 45 | #define MAX_LEN 16 46 | 47 | #define MAX(x, y) ((x) > (y) ? (x) : (y)) 48 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) 49 | 50 | #define PACK(size, alloc) ((size) | (alloc)) 51 | 52 | /* Read and write a word at address p */ 53 | #define GET(p) (*(size_t *)(p)) 54 | #define PUT(p, val) (*(size_t *)(p) = (val)) 55 | 56 | /* Read the size and allocated fields from address p */ 57 | #define GET_SIZE(p) (GET(p) & ~0x7) 58 | #define GET_ALLOC(p) (GET(p) & 0x1) 59 | 60 | /* Given block ptr bp, compute address of its header and footer */ 61 | #define HDRP(bp) ((char *)(bp) - WSIZE) 62 | #define FTRP(bp) ((char *)(bp) + GET_SIZE(HDRP(bp)) - DSIZE) 63 | 64 | /* Given block ptr bp, compute address of next and previous blocks */ 65 | #define NEXT_BLKP(bp) ((char *)(bp) + GET_SIZE(((char *)(bp) - WSIZE))) 66 | #define PREV_BLKP(bp) ((char *)(bp) - GET_SIZE(((char *)(bp) - DSIZE))) 67 | 68 | #define SET_PTR(p, bp) (*(unsigned int *)(p) = (unsigned int)(bp)) 69 | 70 | #define PRED_PTR(bp) ((char *)(bp)) 71 | #define SUCC_PTR(bp) ((char *)(bp) + WSIZE) 72 | 73 | #define PRED(bp) (*(char **)(bp)) 74 | #define SUCC(bp) (*(char **)(SUCC_PTR(bp))) 75 | 76 | /* Global variables */ 77 | static char *heap_listp; /* pointer to first block */ 78 | void *Lists[MAX_LEN]; /* 分离空闲链表 */ 79 | 80 | static void *extend_heap(size_t size); 81 | static void *coalesce(void *bp); 82 | static void *place(void *bp, size_t size); 83 | static void printblock(void *bp); 84 | static void checkblock(void *bp); 85 | static void InsertNode(void *bp, size_t size); //插入到空闲链表 86 | static void DeleteNode(void *bp); //删除 87 | 88 | /*初始化内存分配器*/ 89 | int mm_init(void) 90 | { 91 | int i; 92 | /* 初始化分离空闲链表 */ 93 | for (i = 0; i < MAX_LEN; i++) 94 | { 95 | Lists[i] = NULL; 96 | } 97 | /*建立一个空堆*/ 98 | if ((heap_listp = mem_sbrk(4*WSIZE)) == NULL) 99 | return -1; 100 | PUT(heap_listp, 0); //对齐填充 101 | PUT(heap_listp + (1 * WSIZE), PACK(DSIZE, 1)); //序言块头部 102 | PUT(heap_listp + (2 * WSIZE), PACK(DSIZE, 1)); //序言块脚部 103 | PUT(heap_listp + (3 * WSIZE), PACK(0, 1)); //结尾块 104 | 105 | /* 将堆拓展INITCHUNKSIZE bytes字节 */ 106 | if (extend_heap(INITCHUNKSIZE) == NULL) 107 | return -1; 108 | return 0; 109 | } 110 | 111 | /*mm_free - Free a block*/ 112 | void mm_free(void *bp) 113 | { 114 | size_t size = GET_SIZE(HDRP(bp)); 115 | 116 | PUT(HDRP(bp), PACK(size, 0)); 117 | PUT(FTRP(bp), PACK(size, 0)); 118 | InsertNode(bp, size); 119 | coalesce(bp); 120 | } 121 | 122 | /*用一个新的空闲块扩展堆*/ 123 | static void *extend_heap(size_t size) 124 | { 125 | char *bp; 126 | /* Allocate an even number of words to maintain alignment */ 127 | size = ALIGN(size); 128 | if ((bp = mem_sbrk(size)) == (void *)-1) 129 | return NULL; 130 | /* Initialize free block header/footer and the epilogue header */ 131 | PUT(HDRP(bp), PACK(size, 0)); 132 | PUT(FTRP(bp), PACK(size, 0)); 133 | PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); 134 | /*插入到分离空闲表中 */ 135 | InsertNode(bp, size); 136 | /* Coalesce if the previous block was free */ 137 | return coalesce(bp); 138 | } 139 | 140 | /*插入到空闲链表*/ 141 | static void InsertNode(void *bp, size_t size) 142 | { 143 | int i = 0; 144 | void *search_bp = NULL; 145 | void *insert_bp = NULL; 146 | 147 | while((i1)) // 根据size的大小找到对应的分离空闲链表 148 | { 149 | size >>= 1; 150 | i++; 151 | } 152 | /* 找到分离空闲链表,在该链中寻找对应的插入位置,并且保持链中块由小到大分布 */ 153 | search_bp = Lists[i]; 154 | while ((search_bp != NULL) && (size > GET_SIZE(HDRP(search_bp)))) 155 | { 156 | insert_bp = search_bp; 157 | search_bp = PRED(search_bp); 158 | } 159 | 160 | /* 四种情况 */ 161 | if (search_bp != NULL) 162 | { 163 | /* 在中间插入*/ 164 | if (insert_bp != NULL) 165 | { 166 | SET_PTR(PRED_PTR(bp), search_bp); 167 | SET_PTR(SUCC_PTR(search_bp), bp); 168 | SET_PTR(SUCC_PTR(bp), insert_bp); 169 | SET_PTR(PRED_PTR(insert_bp), bp); 170 | } 171 | /* 2. 在开头插入*/ 172 | else 173 | { 174 | SET_PTR(PRED_PTR(bp), search_bp); 175 | SET_PTR(SUCC_PTR(search_bp), bp); 176 | SET_PTR(SUCC_PTR(bp), NULL); 177 | Lists[i] = bp; 178 | } 179 | } 180 | else 181 | { 182 | if (insert_bp != NULL) 183 | { /*在结尾插入*/ 184 | SET_PTR(PRED_PTR(bp), NULL); 185 | SET_PTR(SUCC_PTR(bp), insert_bp); 186 | SET_PTR(PRED_PTR(insert_bp), bp); 187 | } 188 | else 189 | { /*第一次插入 */ 190 | SET_PTR(PRED_PTR(bp), NULL); 191 | SET_PTR(SUCC_PTR(bp), NULL); 192 | Lists[i] = bp; 193 | } 194 | } 195 | } 196 | 197 | /*从空闲链表中删除*/ 198 | static void DeleteNode(void *bp) 199 | { 200 | int i = 0; 201 | size_t size = GET_SIZE(HDRP(bp)); 202 | 203 | // 根据size的大小找到对应的分离空闲链表 204 | while ((i < MAX_LEN - 1) && (size > 1)) 205 | { 206 | size >>= 1; 207 | i++; 208 | } 209 | /* 四种可能性 */ 210 | if (PRED(bp) != NULL) 211 | { 212 | /* 中间删除 */ 213 | if (SUCC(bp) != NULL) 214 | { 215 | SET_PTR(SUCC_PTR(PRED(bp)), SUCC(bp)); 216 | SET_PTR(PRED_PTR(SUCC(bp)), PRED(bp)); 217 | } 218 | /* 表头删除,后面有块*/ 219 | else 220 | { 221 | SET_PTR(SUCC_PTR(PRED(bp)), NULL); 222 | Lists[i] = PRED(bp); 223 | } 224 | } 225 | else 226 | { 227 | /* 3. 结尾删除*/ 228 | if (SUCC(bp) != NULL) 229 | { 230 | SET_PTR(PRED_PTR(SUCC(bp)), NULL); 231 | } 232 | /* 4. 第一次删除*/ 233 | else 234 | { 235 | Lists[i] = NULL; 236 | } 237 | } 238 | } 239 | 240 | /*合并块*/ 241 | static void *coalesce(void *bp) 242 | { 243 | size_t prev_alloc = GET_ALLOC(HDRP(PREV_BLKP(bp))); 244 | size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); 245 | size_t size = GET_SIZE(HDRP(bp)); 246 | /*四种情况*/ 247 | if (prev_alloc && next_alloc) /*case1*/ 248 | { 249 | return bp; 250 | } 251 | 252 | else if (prev_alloc && !next_alloc) /*case2*/ 253 | { 254 | DeleteNode(bp); 255 | DeleteNode(NEXT_BLKP(bp)); 256 | size += GET_SIZE(HDRP(NEXT_BLKP(bp))); 257 | PUT(HDRP(bp), PACK(size, 0)); 258 | PUT(FTRP(bp), PACK(size, 0)); 259 | } 260 | 261 | else if (!prev_alloc && next_alloc) /*case3*/ 262 | { 263 | DeleteNode(bp); 264 | DeleteNode(PREV_BLKP(bp)); 265 | size += GET_SIZE(HDRP(PREV_BLKP(bp))); 266 | PUT(FTRP(bp), PACK(size, 0)); 267 | PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); 268 | bp = PREV_BLKP(bp); 269 | } 270 | 271 | else /*case4*/ 272 | { 273 | DeleteNode(bp); 274 | DeleteNode(PREV_BLKP(bp)); 275 | DeleteNode(NEXT_BLKP(bp)); 276 | size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(HDRP(NEXT_BLKP(bp))); 277 | PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); 278 | PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0)); 279 | bp = PREV_BLKP(bp); 280 | } 281 | /* 合并后的free块插入到空闲链接表中 */ 282 | InsertNode(bp, size); 283 | 284 | return bp; 285 | } 286 | 287 | /*分配块*/ 288 | void *mm_malloc(size_t size) 289 | { 290 | char *bp = NULL; 291 | int i = 0; 292 | if (size == 0) 293 | return NULL; 294 | 295 | if (size <= DSIZE) 296 | size = 2*DSIZE; 297 | else 298 | size = ALIGN(size+DSIZE); //内存对齐 299 | 300 | size_t asize = size; 301 | 302 | while (i < MAX_LEN) 303 | { 304 | /* 先找合适的空闲链表 */ 305 | if (((asize <= 1) && (Lists[i] != NULL))) 306 | { 307 | bp = Lists[i]; 308 | /* 找到链表,在该链寻找大小合适的未分配块 */ 309 | while ((bp != NULL) && ((size > GET_SIZE(HDRP(bp))))) 310 | bp = PRED(bp); 311 | 312 | /* 找到对应的未分配的块 */ 313 | if (bp != NULL) 314 | break; 315 | } 316 | asize >>= 1; 317 | i++; 318 | } 319 | 320 | /* 没有找到合适的未分配块,则扩展堆 */ 321 | if (bp == NULL){ 322 | if ((bp = extend_heap(MAX(size, CHUNKSIZE))) == NULL) 323 | return NULL; 324 | } 325 | /* 在未分配块中allocate size大小的块 */ 326 | bp = place(bp, size); 327 | 328 | return bp; 329 | } 330 | 331 | /*将大小字节的块放在空闲块bp的开始处,并且如果余数至少是最小块大小则拆分*/ 332 | static void *place(void *bp, size_t asize) 333 | { 334 | size_t csize = GET_SIZE(HDRP(bp)); 335 | size_t remaining = csize - asize; /* allocate size大小的空间后剩余的大小 */ 336 | 337 | DeleteNode(bp); 338 | 339 | /* 如果剩余的大小小于最小块,则不分离原块 */ 340 | if (remaining < DSIZE * 2) 341 | { 342 | PUT(HDRP(bp), PACK(csize, 1)); 343 | PUT(FTRP(bp), PACK(csize, 1)); 344 | } 345 | 346 | else if (asize >= 96) 347 | { 348 | PUT(HDRP(bp), PACK(remaining, 0)); 349 | PUT(FTRP(bp), PACK(remaining, 0)); 350 | PUT(HDRP(NEXT_BLKP(bp)), PACK(asize, 1)); 351 | PUT(FTRP(NEXT_BLKP(bp)), PACK(asize, 1)); 352 | InsertNode(bp, remaining); 353 | return NEXT_BLKP(bp); 354 | } 355 | 356 | else 357 | { 358 | PUT(HDRP(bp), PACK(asize, 1)); 359 | PUT(FTRP(bp), PACK(asize, 1)); 360 | PUT(HDRP(NEXT_BLKP(bp)), PACK(remaining, 0)); 361 | PUT(FTRP(NEXT_BLKP(bp)), PACK(remaining, 0)); 362 | InsertNode(NEXT_BLKP(bp), remaining); 363 | } 364 | return bp; 365 | } 366 | 367 | /*改进后的重新分配函数*/ 368 | void *mm_realloc(void *bp, size_t size) 369 | { 370 | void *new_p = bp; 371 | int remaining; 372 | /*Ingore spurious requests*/ 373 | if (size == 0) 374 | return NULL; 375 | 376 | if (size <= DSIZE) 377 | size = 2 * DSIZE; 378 | else 379 | size = ALIGN(size + DSIZE); //内存对齐 380 | 381 | /* 如果size小于原来块的大小,直接返回原来的块 */ 382 | if ((remaining = GET_SIZE(HDRP(bp)) - size) >= 0) 383 | return bp; 384 | 385 | /* 否则先检查地址连续下一个块是否为未分配块或者该块是堆的结束块 */ 386 | else if (!GET_ALLOC(HDRP(NEXT_BLKP(bp))) || !GET_SIZE(HDRP(NEXT_BLKP(bp)))) 387 | { 388 | /* 如果加上后面连续地址上的未分配块空间也不够,那么需要扩展块 */ 389 | if ((remaining =GET_SIZE(HDRP(bp))+GET_SIZE(HDRP(NEXT_BLKP(bp)))-size)<0) 390 | { 391 | if (extend_heap(MAX(-remaining, CHUNKSIZE)) == NULL) 392 | return NULL; 393 | remaining +=MAX(-remaining,CHUNKSIZE); 394 | } 395 | 396 | /* 从分离空闲链表中删除刚刚利用的未分配块并设置新块的头尾 */ 397 | DeleteNode(NEXT_BLKP(bp)); 398 | PUT(HDRP(bp), PACK(size + remaining, 1)); 399 | PUT(FTRP(bp), PACK(size + remaining, 1)); 400 | } 401 | /* 如果没有可以利用的连续未分配块,只能申请新的不连续的未分配块 */ 402 | else 403 | { 404 | new_p = mm_malloc(size); 405 | memcpy(new_p, bp, GET_SIZE(HDRP(bp))); 406 | mm_free(bp); 407 | } 408 | return new_p; 409 | } 410 | 411 | /*检查堆的一致性*/ 412 | void mm_checkheap(int verbose) 413 | { 414 | char *bp = heap_listp; 415 | 416 | if (verbose) 417 | printf("Heap (%p):\n", heap_listp); 418 | 419 | if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp))) 420 | printf("Bad prologue header\n"); 421 | checkblock(heap_listp); 422 | 423 | for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) { 424 | if (verbose) 425 | printblock(bp); 426 | checkblock(bp); 427 | } 428 | 429 | if (verbose) 430 | printblock(bp); 431 | if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))) 432 | printf("Bad epilogue header\n"); 433 | } 434 | 435 | static void printblock(void *bp) 436 | { 437 | size_t hsize, halloc, fsize, falloc; 438 | 439 | hsize = GET_SIZE(HDRP(bp)); 440 | halloc = GET_ALLOC(HDRP(bp)); 441 | fsize = GET_SIZE(FTRP(bp)); 442 | falloc = GET_ALLOC(FTRP(bp)); 443 | 444 | if (hsize == 0) { 445 | printf("%p: EOL\n", bp); 446 | return; 447 | } 448 | 449 | printf("%p: header: [%d:%c] footer: [%d:%c]\n", bp, 450 | hsize, (halloc ? 'a' : 'f'), 451 | fsize, (falloc ? 'a' : 'f')); 452 | } 453 | 454 | static void checkblock(void *bp) 455 | { 456 | if ((size_t)bp % 8) 457 | printf("Error: %p is not doubleword aligned\n", bp); 458 | if (GET(HDRP(bp)) != GET(FTRP(bp))) 459 | printf("Error: header does not match footer\n"); 460 | } 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | -------------------------------------------------------------------------------- /lab/lab8/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab8/实验报告.doc -------------------------------------------------------------------------------- /lab/lab8/实验报告.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/lab/lab8/实验报告.pdf -------------------------------------------------------------------------------- /note/chapter 2.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/note/chapter 2.doc -------------------------------------------------------------------------------- /note/chapter 3.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/note/chapter 3.doc -------------------------------------------------------------------------------- /note/chapter 8.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/note/chapter 8.doc -------------------------------------------------------------------------------- /note/chapter 9.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/note/chapter 9.doc -------------------------------------------------------------------------------- /pku/2016ICS期中.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/pku/2016ICS期中.pdf -------------------------------------------------------------------------------- /sjtu slides/1-intro.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/1-intro.ppt -------------------------------------------------------------------------------- /sjtu slides/10-array.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/10-array.ppt -------------------------------------------------------------------------------- /sjtu slides/11-x64.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/11-x64.ppt -------------------------------------------------------------------------------- /sjtu slides/12-fp.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/12-fp.ppt -------------------------------------------------------------------------------- /sjtu slides/13-round.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/13-round.ppt -------------------------------------------------------------------------------- /sjtu slides/14-y86.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/14-y86.ppt -------------------------------------------------------------------------------- /sjtu slides/15-logical.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/15-logical.ppt -------------------------------------------------------------------------------- /sjtu slides/16-seq.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/16-seq.ppt -------------------------------------------------------------------------------- /sjtu slides/17-seq2.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/17-seq2.ppt -------------------------------------------------------------------------------- /sjtu slides/18-seq3.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/18-seq3.ppt -------------------------------------------------------------------------------- /sjtu slides/19-pipe.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/19-pipe.ppt -------------------------------------------------------------------------------- /sjtu slides/2-bits.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/2-bits.ppt -------------------------------------------------------------------------------- /sjtu slides/20-dhazard.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/20-dhazard.ppt -------------------------------------------------------------------------------- /sjtu slides/21-chazard.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/21-chazard.ppt -------------------------------------------------------------------------------- /sjtu slides/22-exception.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/22-exception.ppt -------------------------------------------------------------------------------- /sjtu slides/23-mio.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/23-mio.ppt -------------------------------------------------------------------------------- /sjtu slides/24-tuning.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/24-tuning.ppt -------------------------------------------------------------------------------- /sjtu slides/25-opt.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/25-opt.ppt -------------------------------------------------------------------------------- /sjtu slides/26-ram.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/26-ram.ppt -------------------------------------------------------------------------------- /sjtu slides/27-locality.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/27-locality.ppt -------------------------------------------------------------------------------- /sjtu slides/28-cache.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/28-cache.ppt -------------------------------------------------------------------------------- /sjtu slides/29-misc.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/29-misc.ppt -------------------------------------------------------------------------------- /sjtu slides/3-bops.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/3-bops.ppt -------------------------------------------------------------------------------- /sjtu slides/4-encoding.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/4-encoding.ppt -------------------------------------------------------------------------------- /sjtu slides/5-arith.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/5-arith.ppt -------------------------------------------------------------------------------- /sjtu slides/6-move.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/6-move.ppt -------------------------------------------------------------------------------- /sjtu slides/7-cc.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/7-cc.ppt -------------------------------------------------------------------------------- /sjtu slides/8-control.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/8-control.ppt -------------------------------------------------------------------------------- /sjtu slides/9-call.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/sjtu slides/9-call.ppt -------------------------------------------------------------------------------- /slides/HIT-ICS第10章 系统级IO.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第10章 系统级IO.ppt -------------------------------------------------------------------------------- /slides/HIT-ICS第1章 课程概述.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第1章 课程概述.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第2章 信息的表示和处理Ⅰ:位、整数.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第2章 信息的表示和处理Ⅰ:位、整数.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第2章 信息的表示和处理Ⅱ:浮点数.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第2章 信息的表示和处理Ⅱ:浮点数.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part01-s (2).pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part01-s (2).pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part02.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part02.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part03.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅰ:基础-part03.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅱ:控制.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅱ:控制.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅲ:过程.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅲ:过程.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅳ:数据.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅳ:数据.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第3章 程序的机器级表示Ⅴ:高级主题.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第3章 程序的机器级表示Ⅴ:高级主题.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第4章 处理器体系结构-L1-指令集体系结构.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第4章 处理器体系结构-L1-指令集体系结构.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第4章 处理器体系结构-L2 逻辑设计.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第4章 处理器体系结构-L2 逻辑设计.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第4章 处理器体系结构-L3-顺序执行的处理器 (1).pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第4章 处理器体系结构-L3-顺序执行的处理器 (1).pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第4章 处理器体系结构-L4-流水线的实现基础.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第4章 处理器体系结构-L4-流水线的实现基础.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第4章 处理器体系结构-L5-流水线实现的高级技术.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第4章 处理器体系结构-L5-流水线实现的高级技术.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第5章-优化.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第5章-优化.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第6章- L1 存储器层级结构与局部性.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第6章- L1 存储器层级结构与局部性.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第6章- L2 高速缓冲器Cache.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第6章- L2 高速缓冲器Cache.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第7章- 连接.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第7章- 连接.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第8章 异常控制流 L1异常与进程.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第8章 异常控制流 L1异常与进程.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第8章 异常控制流 L2信号与非本地跳转.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第8章 异常控制流 L2信号与非本地跳转.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第9章 L1虚拟内存-概念.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第9章 L1虚拟内存-概念.ppt -------------------------------------------------------------------------------- /slides/HIT-ICS第9章 L2虚拟内存-系统.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第9章 L2虚拟内存-系统.pptx -------------------------------------------------------------------------------- /slides/HIT-ICS第9章 L3动态内存分配-基本概念.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第9章 L3动态内存分配-基本概念.ppt -------------------------------------------------------------------------------- /slides/HIT-ICS第9章 L4动态内存分配-高级概念.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/slides/HIT-ICS第9章 L4动态内存分配-高级概念.ppt -------------------------------------------------------------------------------- /共享指令.txt: -------------------------------------------------------------------------------- 1 | 挂载命令: 2 | 3 | view sourceprint? 4 | 1 5 | 正确的是: 6 | 2 7 | 使用命令: sudo mount -t fuse.vmhgfs-fuse .host:/hitics /mnt/hgfs -o allow_other(如果卸载,就把mount -t换成umount -a) 8 | 3 9 | 或sudo vmhgfs-fuse .host:/VM_Shared /mnt/hgfs 10 | 4 11 | (其中.host:/Documents是共享名,只需把Documents换成使用vmware-hgfsclient 命令得到的目录,/mnt/hgfs是挂载点。) 12 | 5 13 | 14 | 6 15 | 如果每次重启之后想让系统自动挂载 #vi /etc/fstab: 16 | 7 17 | 在最后添加一行: 18 | 8 19 | .host:/VM_Shared /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0 20 | -------------------------------------------------------------------------------- /深入理解Linux内核.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Week0327/ICS/37bb4b86c08f9037065d199da0706ba637376ba2/深入理解Linux内核.pdf --------------------------------------------------------------------------------