❶ stm8s stvd 怎么看代码大小
下载一个小工具
1、把解开后的size.exe复制到COSMICCXSTM8文件夹,就是你的COSMIC编译工具里有cpstm8.exe的那个文件夹。
2、在SVTD的Project->settings中打开Post-Build选项卡,在commands的最后一行加入:size $(OutputPath)$(TargetSName).map
3、保存返回,编译试试,最后会出现如:Program Size: Code=12470 Eeprom=0 ZeroPage=227 Ram=180的结果。
思路:
打开map文件,统计各段的长度,然后输出。
主要代码:
static void Main(string[] args)
{
StreamReader sr = new StreamReader(args[0]);
string[] s;
char[] charSeparators = new char[] { ' ' };
int code_size = 0;
int zeropage_size = 0;
int ram_size = 0;
int eeprom_size = 0;
for (int i = 0; i < 8; i++)
{
string s1 = sr.ReadLine();
}
while (true)
{
string s1 = sr.ReadLine();
s = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
if(s.Length == 0)
{
break;
}
else if (s[7] == ".text" || s[7] == ".const" || s[7] == ".init")
{
code_size += int.Parse(s[5]);
}
else if (s[7] == ".eeprom")
{
eeprom_size += int.Parse(s[5]);
}
else if (s[7] == ".bsct," && s[8] == "initialized")
{
zeropage_size += int.Parse(s[5]);
}
else if (s[7] == ".ubsct" || s[7] == ".share")
{
zeropage_size += int.Parse(s[5]);
}
else if (s[7] == ".data," && s[8] == "initialized")
{
ram_size += int.Parse(s[5]);
}
else if (s[7] == ".bss")
{
ram_size += int.Parse(s[5]);
}
}
Console.WriteLine("");
//Program Size: Code=5056 RO-data=288 RW-data=68 ZI-data=1140
Console.WriteLine("Program Size: Code=" + code_size.ToString() + " Eeprom=" + eeprom_size.ToString() + " ZeroPage=" + zeropage_size.ToString() + " Ram=" + ram_size.ToString());
}