Keil C51

Swapping Nibbles in Keil C51

今天寫程式的時候,有個地方需要 swap 某個 byte 的兩個 nibbles。其實 8051 原本就有一個 instruction 專門做這件事。若是直接寫組語的話,只要 3 行就搞定了:

    MOV     A,tmp       ; 先將原本的值搬進 accumulator
    SWAP    A           ; swap nibbles
    MOV     tmp,A       ; 先將原本的值搬進 accumulator

問題我是用 C 在寫 code 的,所以我就開始研究是不是有辦法讓 Keil C 幫我產生這樣的 code。

Read More