Skip to Main Content
建立嵌入式系統--傑出軟體的設計模式
book

建立嵌入式系統--傑出軟體的設計模式

by Elecia White
October 2012
Intermediate to advanced content levelIntermediate to advanced
328 pages
7h 19m
Chinese
GoTop Information, Inc.
Content preview from 建立嵌入式系統--傑出軟體的設計模式
耗費更少成果更多
|
235
buffer++;
遞增暫存器緩衝區
i++;
遞增暫存器 i
這並沒有做任何重大的改變,只是提供編譯器一些能加快程式速度的提示,(某些比較
聰明的編譯器能夠自行剖析程式碼做出相同的改善。)
這讓我們學到儘可能使用指標運算(
buffer++
)而非陣列與索引,指標運算使用較少的
RAM 同時也提供編譯器最佳化較明確的途徑。更重要的是瞭解程式碼會轉譯成機械語
言,儘可能讓編譯器更容易最佳化程式執行速度。
減少迴圈中的計算
接下來呢?理想上希望儘可以減少迴圈中的運算,移位與位元 AND 相對便宜,但如果
每個循環裡都計算,加總起來也很可觀。如果緩衝區是字組緩衝區而非位元緩衝區就可
以避免這種狀況:
void LcdWriteBuffer(uint16_t *buffer, uint16_t bufLength)
{
uint8_t *byteBuffer = (uint8_t *) buffer;
// buffer is not a buffer of bytes
// This works only if your endian-ness matches what the hardware expects
bufLength = bufLength*2;
IoClear(LCD_SELECT_N); // select the chip
while (bufLength) {
IoWriteBusByte(LCD_BUS, *byteBuffer);
bufLength--; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

HBASE技術手冊

HBASE技術手冊

Lars George
ANGULARJS建置與執行

ANGULARJS建置與執行

Shyam Seshadri, Brad Green
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9789862765784