Skip to content

Commit

Permalink
add README
Browse files Browse the repository at this point in the history
  • Loading branch information
Exely committed Sep 25, 2017
1 parent 5a277a4 commit 5364550
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CS:APP Labs

最近在啃CSAPP,同时做了些配套的labs,这个项目给了一些labs的解答,都是我参考了Google一点点啃出来的T_T,还有一些是我写的笔记。
### 目录:
- labs: 包含从[Lab Assignments](http://csapp.cs.cmu.edu/3e/labs.html)下载来的实验文件,其中 bits.c 为题目列表和我写的解答;
- notes: 包含我写的笔记;


Binary file removed labs/datalab-handout.tar
Binary file not shown.
11 changes: 7 additions & 4 deletions labs/datalab-handout/bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ int getByte(int x, int n) {
* Rating: 3
*/
int logicalShift(int x, int n) {
int mask=((0x1<<(32+~n))+~0)|(0x1<<(32+~n));
return (x>>n)&mask;
/* int c=((0x1<<31>>31)^0x1)<<31;
return ((x>>n)^(c>>n)); it's wrong for 0x0>>0x1==0x0
*/
/*Bug: return ~((~x)>>n); it's wrong for ~x contains all 32 bits,
as ~(0x10000000)==(0x0000000001111111) in x86-64?
/*Bug: return ~((~x)>>n); it's wrong for ~x is postive while x is negative
*/
}
/*
Expand Down Expand Up @@ -212,7 +213,9 @@ int tmin(void) {
* Rating: 2
*/
int fitsBits(int x, int n) {
return 2;
int c=33+~n;
int t=(x<<c)>>c;
return !(x^t);
}
/*
* divpwr2 - Compute x/(2^n), for 0 <= n <= 30
Expand Down Expand Up @@ -264,7 +267,7 @@ int isLessOrEqual(int x, int y) {
* Rating: 4
*/
int ilog2(int x) {
return 2;
return !!(x)+!!(x>>1)+;
}
/*
* float_neg - Return bit-level equivalent of expression -f for
Expand Down
Binary file modified labs/datalab-handout/btest
Binary file not shown.
Empty file added notes/README.md
Empty file.

0 comments on commit 5364550

Please sign in to comment.