Skip to content

branches to labels work, branches to absolute addresses do not #11

@nealcrook

Description

@nealcrook

Consider the input code:

thecode = """
                ORG  $1234
start:
                BPL loop
                LDA #$10
                LDX #$00
loop:
                STA $1000,x
                INX
                SBC #$01
                BPL loop
                BPL $1234 ; backwards
                BPL $1250 ; forwards
                RTS
"""

Generated assembly/code is:

1    0000 :                                
2    1234 :                  org $1234     
3    1234 : start:                         
4    1234 :         10 04    bpl loop      
5    1236 :         A9 10    lda #$10      
6    1238 :         A2 00    ldx #$00      
7    123A : loop:                          
8    123A :         9D 00 10 sta $1000,x   
9    123D :         E8       inx           
10   123E :         E9 01    sbc #$01      
11   1240 :         10 F8    bpl loop      
12   1242 :         10 34    bpl $1234     ; backwards BUG!!
13   1244 :         10 50    bpl $1250     ; forwards BUG!!
14   1246 :         60       rts           

Observe that the two branches to absolute addresses generate incorrect code: instead of an offset, the value is the l_ow byte of the target address_!!

thanks for sharing your code. Even if I end up fixing this bug myself it will still be quicker than starting from scratch..

Neal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions