Assembly Anomaly, HS12 Code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assembly Anomaly, HS12 Code

485 Views
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.

Labels (1)
0 Kudos
1 Reply

328 Views
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 Kudos