stable 重构文件结构
抽象出Machine Code
This commit is contained in:
41
src/ccompiler/backend/riscv32/README.md
Normal file
41
src/ccompiler/backend/riscv32/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# 后端代码生成
|
||||
|
||||
## riscv32i
|
||||
|
||||
> 仿照ripes的syscall,实现了rv32-vm
|
||||
|
||||
### syscall ecall 系统调用
|
||||
|
||||
```c
|
||||
// ecall 系统调用函数实现
|
||||
#define ECALL_PNT_INT(num) \
|
||||
ADDI(REG_A0, REG_X0, num), \
|
||||
ADDI(REG_A7, REG_X0, 0x1), \
|
||||
ECALL(),
|
||||
|
||||
#define ECALL_PNT_STR(str) \
|
||||
ADDI(REG_A0, REG_X0, str), \
|
||||
ADDI(REG_A7, REG_X0, 0x4), \
|
||||
ECALL(),
|
||||
|
||||
#define ECALL_EXIT(errno) \
|
||||
ADDI(REG_A0, REG_X0, errno), \
|
||||
ADDI(REG_A7, REG_X0, 10), \
|
||||
ECALL(),
|
||||
|
||||
#define ECALL_SCAN_INT(int) \
|
||||
ADDI(REG_A7, (1025 + 4)), \
|
||||
ECALL(),
|
||||
|
||||
#define ECALL_SCAN_STR(str) \
|
||||
ADDI(REG_A0, REG_X0, str), \
|
||||
ADDI(REG_A7, REG_X0, (1025 + 5)), \
|
||||
ECALL(),
|
||||
|
||||
// 函数声明
|
||||
void ecall_pnt_int(int num);
|
||||
void ecall_pnt_str(char *str);
|
||||
void ecall_exit(int errno);
|
||||
int ecall_scani();
|
||||
void ecall_scans(char *str);
|
||||
```
|
||||
Reference in New Issue
Block a user