sysprog2017
主講人: jserv / 課程討論區: 2017 年系統軟體課程
:mega: 返回「進階電腦系統理論與實作」課程進度表
$ git clone https://github.com/sysprog21/full-stack-hello.git
$ cd full-stack-hello
$ make
$ make check
預期得到以下輸出:
42
tests/halt.s pass
Hello World
tests/hello.s pass
42
50
150
tests/test.s pass
$ make test
python tests/run_tests.py
..
---------------------------------------------------------
Ran 4 tests in 0.002s
OK
$ ./as_exec -h
Usage: as_exec [-w] [-x] [-o <out_file>] <in_file>
-w Assemble <in_file> and write to an ELF file, see -o below
-o if -w is specifed, <out_file> is used to store the object code
-x Load <in_file> and execute it
<in_file> the file name to be used by commands above
tests/hello.s
檔案做示範
$ ./as_exec tests/hello.s
tests/hello.o
$ ./as_exec -w tests/hello.s
$ ./as_exec -o tests/temp.o -w tests/hello.s
$ ./as_exec -x tests/hello.o
$ objdump -x tests/hello.o
vm.c
用到 GCC computed goto 的機制#define OP(name) OP_##name
#define BEGIN_OPCODES \
const static void *labels[] = {OP_LABELS}; \
goto *labels[OPCODE.opcode]
#define DISPATCH \
do { \
++env->r.pc; \
goto *labels[OPCODE.opcode]; \
} while (0)
#define GOTO(n) \
do { \
env->r.from = env->r.pc; \
env->r.to = n; \
env->r.pc = n; \
goto *labels[OPCODE.opcode]; \
} while (0)
#define END_OPCODES
$ sudo apt-get install clang-format
tests/fib-recursive.s
和 tests/fib-iterative.s
vm.c
(和對應的原始程式碼),允許執行時期由使用者 (和 Makefile
) 帶入參數,如 --input
,這數值應該透過暫存器作為上述 Fibonacci 數列程式的 Fib(N)