Gilbert Gagne

Assembly Anomaly, HS12 Code

Discussion created by Gilbert Gagne on Nov 9, 2011
Latest reply on Nov 9, 2011 by kef

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.

Outcomes