2025-05-18 09:11:15 +08:00

53 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# sdcc
---
## index
- [编译流程](#编译流程)
- [特殊语法](#特殊语法)
- [优化选项](#优化选项)
- [调试工具](#调试工具)
- [](#)
- [](#)
---
### **编译流程**
- **输出文件**
- `main.ihx`Intel Hex 格式的固件文件(可直接烧录)。
- `main.asm`:生成的汇编代码(便于调试)。
- `main.lk`:链接器脚本。
- `main.map`:内存映射和符号表。
- `main.rel` : 参与连接的文件
---
### **特殊语法**
针对8051单片机
- **内存类型修饰符**
- `__code` : 将变量存储在代码区 ROM
- `__data`:将变量存储在内部 RAM直接寻址区
- `__xdata`:将变量存储在外部 RAM扩展 XDATA 区)。
- `__bit`:定义位变量(仅限 8051 的位寻址区)。
---
### **优化选项**
- **常用编译选项**
- `--model-<model>`:指定内存模型(如 `--model-small``--model-large`)。
- `--opt-code-size`:优化代码大小。
- `--nogcse` : 按需选择,避免未使用的 函数/变量 占用空间
- `--stack-auto`:自动分配堆栈(适用于函数调用)。
- `--nooverlay`:禁用函数参数和局部变量的覆盖优化。
- `--verbose`:显示详细编译过程。
---
### **调试工具**
- **生成调试信息**
```bash
sdcc --debug main.c # 生成 .cdb 调试文件
```