跳到主要内容

CS61C

C

  • printf:
    • %s means print a string
    • %d means print a decimal number
    • %X means print a hexadecimal number
  • ^ bitwise XOR
  • 取反最低位 X^1 注意不是 ~X
  • C Macro: "Find and replace"
  • typedef A B def B as A
  • int32_t means 32 bits, and 4 bytes
  • Endianness and Alignment
    • Endianness: little endian
    • Alignment
  • Address Space
    • passing pointers caller to callee is ok, but never callee to caller.
  • realloc(void* ptr, size_t size) returns new address of block.(in heap)
    • realloc(NULL, size); behaves like malloc
    • realloc(ptr,0); behaves like free
**
//Safer
TYPE *tmp = realloc(ptr, NEW_SIZE);
if (tmp) { ptr = tmp; }
  • valgrind
  • Function Pointers
  • dereference: access the data/value in the memory.
  • Generic Pointers
  • void *end = (char *) arr + (nelems-1) * nbytes, (char *) means that convert arr from void*(have defined that) to char*
  • dereference a variable that is not a pointer--C will treat theat variable's underlying bits as if they were a pointer
  • 字符串使用双引号而不是单引号。

RISC-V

  • R-TYPE
  • I-TYPE I*(shift instructions)
  • S-TYPE
  • U-TYPE
  • B-TYPE
  • J-TYPE n
注意
  • load 是 load 某寄存器中存储的对应的地址(中的值)类似,而add是处理存储器中存储的值。
  • jal 保存返回值,j 不保存返回值。

Compiler,Assembler,Linker,Loader

  • Compilation: what it actually means (and discovered it's just the first step in a very long process)
  • Assembly: how human-readable parts of assembly code get swapped out for more machine-readable features
  • Linking: how different files and libraries make their way into the final product
  • Loading: how a system processes our code to run

数电