【問題】(assembly)bit的顛倒


Recommended Posts

大家好,我想詢問的語言是assembly language。

我想請問的是教授給我們的這個範例檔:

;
; A machine program that reverses the bit pattern in R4
;
load R0, 00010001b ; Save loop termination condition in R0
load R1, 10001000b ; Initial bit mask for bit reversal
ror R4, 1 ; Shift two bits in R4 into the correct
; reversed positions
and R2, R4, R1 ; Saves those bits that are in correct reversed
; positions
;
Loop:
ror R4, 2 ; Shift two more bits into correct position
ror R1, 1 ; Shift the bit mask into correct position
and R3, R4, R1 ; Save the two correct bits
or R2, R2, R3 ; Sotred the temporary result in R2
jmpEQ R1=R0, Exit ; Check if we have reversed all the bits
jmpEQ R0=R0, Loop ; Go back and reverse two more bits
Exit:
and R4, R2, R2 ; Save the reversed bit-pattern into R4
halt

它的功用是將R4暫存器中的位元顛倒再儲存,

assembly language的基本概念與指令我已經懂得差不多了,

and or 這些bit的操作我也知道了,

現在我想問的主要問題是:

1.  R1, 10001000b ; Initial bit mask 這是什麼?遮罩?是用來做什麼的呢?

2.  為什麼要不斷的操作ror and 還有or,我不知道為何如上面的程式操作之後,bit就會顛倒過來。

謝謝大家的解答。

鏈接文章
分享到其他網站

請登入後來留意見

在登入之後,您才能留意見



立即登入