Assembly Anomaly, HS12 Code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Assembly Anomaly, HS12 Code

532件の閲覧回数
astro_goto
Contributor III

I am getting different results when transfering register a into register x with two seemingly equivalent code segments.

Consider the following code segment where ARRAY has 4 elements:

 

    ldx    #ARRAY    ;load register x with address of ARRAY
    ldaa    2,x          ;load register a with 3rd element of ARRAY
    tfr    a,x                ;x = [0:a] (maybe!) High byte of x is not 0

 

I find that register x will contain a different value than the seemingly equivalent code segment:

 

    ldx    #ARRAY    ;load register x with address of ARRAY
    ldab    2,x            ;load register b with 3rd element of ARRAY
    clra                      ;zero the high byte of register d
    tfr    d,x                ;x = [0:a] (Confirmed that high byte of x=0)

 

Perhaps I may have misinterpreted instruction (tfr r1,r2) when r1 is 8-bits and r2 is 16-bits.

ラベル(1)
0 件の賞賛
返信
1 返信

375件の閲覧回数
kef
Specialist I

TFR from 8bit reg to 16bit reg always performs sign extension. There's SEX instruction alias for TFR 8bitreg, 16bitreg. SEX should be used instead of TFR to better document what really happens.

 

If you want Xhi to be 0, you may use EXG   A,X, which will set X to 0:A, and A to Xlo.

0 件の賞賛
返信