Assembly Anomaly, HS12 Code

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Assembly Anomaly, HS12 Code

704 次查看
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 回复

547 次查看
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 项奖励
回复