❶ 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());
}