C Memory Management malloc 1 2 3 4 5 6 // with the help of a typecast and sizeof ptr = (int *) malloc(n * sizeof(int)); /* check if malloc was successful */ if (ptr == NULL) { /* handle error */ } 1 2 3 ptr = (int *) realloc(ptr, (n+1) * sizeof(int)); free(ptr); // realloc(ptr, 0) 不要踩坑!
An array name is not a variable. – K&R
when call &arr , just get the address of the first element of the array
Floating Point Introduction note that binary can directly calculate
we can use normal format to represent floating point numbers
eg: $1.xxxxx * 2_{two}^{yyyyy}$
“1.“默认,不需bit级别上考虑
underflow & IEEE 754 希望全是0的bit表示的是最小的数字,而不是+0或-0,引入bias
$bias = 2^{n-1} - 1$ 详见number representation的bias部分
真正的表示方法:
IEEE 754 🎉
Special Values infinity, NaN, zero
NaN (Not a Number) : 无效数值,如0/0, sqrt(-1) infinity : 无穷大,如1/0, 10^1000 zero : 零,如0/1, 1.0-1.0 gap数量级在800万左右,因为implicit one的出现
denormalized number : 规格化数值,指数部分为0(implicit 2^-126),小数部分不为0==> 从步长2^-149开始,exp加1,步长翻倍,同时从denorm到norm的时候步长不会发生变化! 总结
从0 11111110 111…11(23个) 加一,得到 0 11111111 000…00(23个)这就是无穷
RISC-V Introduction Instruction Set Architecture (ISA) Assembly Variables each statement is called an instruction
Registers where are registers ?
32 general purpose registers (GPRs) are available in RISC-V architecture.(x0 - x31)
word: 32 bits (can be 64 bits in RV64)
x0: always 0 # is the comment character
no type casting in RISC-V assembly language the registers have no type
add/sub instructions syntax of instructions 1 2 add rd, rs1, rs2 sub rd, rs1, rs2 # d(rd) = e(rs1) - f(rs2), 注意顺序 Immediate values(立即数) 1 addi rd, rs1, 10 没有subi ,加上相反数即可