Week#5 開發記錄

+Week#5 課程

  • "You know, throughout the years in bussiness, I found something, which I was always ask why you do things, and the answers you inevitably get are 'oh that's just the way it's done', nobody knows why they do, nobody thinks about things very deeply in bussiness, that's what I found."
  • Feeling: Impressive, attractive, passionate
GNU Toolchain:
  • arguments是呼叫函式傳遞的,parameters是被呼叫函式接收到的
組語在procedure call如何傳遞參數?AAPCS
  • eabi: embedded abi
  • the sizes, layout, and alignment of data types
  • the calling convention, which controls how functions' arguments are passed and return values retrieved; for example, whether all parameters are passed on the stack or some are passed in registers, which registers are used for which function parameters, and whether the first function parameter passed on the stack is pushed first or last onto the stack
  • how an application should make system calls to the operating system and, if the ABI specifies direct system calls rather than procedure calls to system call stubs, the system call numbers
  • and in the case of a complete operating system ABI, the binary format of object files, program libraries and so on.
+Target triple
  • hf: hard float,預設有FPU
  • armeb-linux-gnueabihf-*: Linaro ARMv7 big-endian Linux GNU EABI HF
  • Turing completeness:a system of data-manipulation rules can be used to simulate any single-taped Turing machine.
  • Interpreter:本身是一個可執行檔案,工作就是翻譯并執行輸入的程式碼
  • compiler:compile source code to native machine code(ISA, ABI)
  • 實作方式是將原始碼翻譯成backend對應的assembly然後打印出來通過stdout存到一個文件(compiler-XX.c),再用compiler編譯後執行(Makefile實現)
const char *const prologue = 
".global _main\n" 
"    pushq %rbp\n" 
"    movq %rsp, %rbp\n" 
"    pushq %r12\n" // store callee saved register 
"    subq $30008, %rsp\n" // allocate 30,008 B on stack, and realign 
"    leaq (%rsp), %rdi\n" // address of beginning of tape 
"    movl $0, %esi\n" // fill with 0's 
"    movq $30000, %rdx\n" // length 30,000 B 
"    call memset\n" // memset 
"    movq %rsp, %r12";
const char *const epilogue =
            "    addq $30008, %rsp\n" // clean up tape from stack.
            "    popq %r12\n" // restore callee saved register
            "    popq %rbp\n"
            "    ret\n";
  • X64 calling convention: