datalab
#endif
//1
/*
- bitXor - x^y using only ~ and &
- Example: bitXor(4, 5) = 1
- Legal ops: ~ &
- Max ops: 14
- Rating: 1
/
int bitXor(int x, int y) {
return ~ ( ~ ( ~ x&y)&( ~ (x& ~y)));
}
/ - tmin - return minimum two’s complement integer
- Legal ops: ! ~ & ^ | + << >>
- Max ops: 4
- Rating: 1
*/
int tmin(void) {
return 0x1<<31;//0x8000
}
//2
/*
- isTmax - returns 1 if x is the maximum, two’s complement number,
- and 0 otherwise
- Legal ops: ! ~ & ^ | +
- Max ops: 10
- Rating: 1
*/
int isTmax(int x) {
int y=x+1;
int u=y^x;
int t=~u;
return !t;
}
/*
- allOddBits - return 1 if all odd-numbered bits in word set to 1
- where bits are numbered from 0 (least significant) to 31 (most significant)
- Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1
- Legal ops: ! ~ & ^ | + << >>
- Max ops: 12
- Rating: 2
/
int allOddBits(int x) {
int y = 0x5555;
int u=y&x;
int t=u^y;
return !t;
//构造出奇数位全1的数 y ,然后获取输入 x 值的奇数位,
//其他位清零(y&x),然后与y进行异或操作,相同结果为0,然后返回其值的逻辑非。
}
/ - negate - return -x
- Example: negate(1) = -1.
- Legal ops: ! ~ & ^ | + << >>
- Max ops: 5
- Rating: 2
/
int negate(int x) {
return ~x+1;
}
//3
/ - isAsciiDigit - return 1 if 0x30 <= x <= 0x39 (ASCII codes for characters ‘0’ to ‘9’)
- Example: isAsciiDigit(0x35) = 1.
- isAsciiDigit(0x3a) = 0.
- isAsciiDigit(0x05) = 0.
- Legal ops: ! ~ & ^ | + << >>
- Max ops: 15
- Rating: 3
*/
int isAsciiDigit(int x) {
int n = 0x1<<31;
int a = ~(n|0x39);
int b = ~0x30;
a = n&(a+x)>>31;
b = n&(b+1+x)>>31;
return !(a|b);
//两个数,一个数是加上比0x39大的数后符号由正变负,另一个数是加上比0x30小的值时是负数。
//加法之后获取其符号位判断即可
}
/*
- conditional - same as x ? y : z
- Example: conditional(2,4,5) = 4
- Legal ops: ! ~ & ^ | + << >>
- Max ops: 16
- Rating: 3
*/
int conditional(int x, int y, int z) {
x = !!x;
x = ~x+1;
return (x&y)|(~x&z);
/将 x 的布尔值转换为全0或全1,x!=0 时位表示是全1的。获取其布尔值0或1,求其补码,得到想要的结果。最后通过位运算获取最终值。/
}
bomblab
//—Border relations with Canada have never been better.直接查看地址x/s
//—1 2 4 8 16 32 汇编里面加倍,看语句是从1开始。
//—0 207 switch表,第一个就是对应0 207出来。
//—7 0 [rsp + c]不是0就爆,第二个数必须是0;
//func函数反汇编:
//if( arg3 >= arg1 ) t = (arg3 + arg1)/2; else t = (arg3 + arg1 + 1)/2; 14/2=7
// if(t > arg2)
// return 2 * func4(arg1, arg2, t-1);
// else if (t < arg2)
// return 2 * func4(t+1, arg2, arg3) + 1;
// else
// return 0;
//—IONEFG
//string_length 的返回值得是6,循环rax从0-6,ecx依次是读进来的六个字符。
// 0x0000000000401096 <+52>: and edx,0xf //edx只保留低四位
//movzbl (%rbx,%rax,1),%ecx 是取内存的这个位置的一个字节,然后零拓展到32位,存到%ecx寄存器里去。
//%rbx存放的是input的起始位置,phase_5需要六个字符组成的字符串,根据获得每个字符串二进制表示的低位,
//以此作为偏移量从0x4024b0处的字符串中获得对应的字母。与0x40245e处的字符串(flyers)比较,相等则成功。