#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    9
    Rep Power
    0

    Machine code relative offsets


    I am trying to understand how assembly is translated into machine language. I understand how to get the machine coding formats but I'm not sure how to calculate 'rr' in all cases. For the example example bra is 20 rr or 20 03, I know that the relative offset is 03 to get to the iny instruction. But I'm not sure why the rr = F3 for the dbne instruction, how does that relative offset get me to Again? A quick answer would be appreciated, I have a test tomorrow.

    Solution to sample problem:
    Code:
            org $600   
                        ldy  #Array        ;CD B6 15
                        ldaa  #N            ;86 07
                        clr      7,y           ;69 47
    Again             brclr   0,y %11110000, Not_gtr  ;0F 40 F0 02
                        bra    Update     ;20 03
    Not_gtr          inc     Count       ;72 B6 1C
    Update           iny                      ;02
                        dbne  a,Again    ;04 30 F3
                        swi                     ;             
    Array             fdb   8,7,2                           
    N                  equ   7
    Count            rmb   1
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Location
    Hampshire, UK
    Posts
    11
    Rep Power
    0
    The data is a 2s complement of the difference between the addresses. When the DBNE is executed the PC will already be at the byte beyond the F3. Now, count back bytes from there to the label 'Again'. That's 13 bytes, but -13 bytes = 00001101. 1s Complement = 11110010. 2s Complement = 1s complement+1 so that gives us 11110011 = F3

IMN logo majestic logo threadwatch logo seochat tools logo