6510 Assembly using CBM Studio - Page Boundary with Branching Errors

460 views Asked by At

I am getting the error page boundary crossed when I run my program. Nowhere in the CBM prg studio app for Windows 10 help does it explain how I can either increase this boundary, or what I need to do in order to avoid these errors.

It is happening on the same instruction based at Line 110 and Line 127 inside the labels E1cycle and E2cycle...


**Line 110:** BEQ space2reset     ; branch/jump if the result in A is 0

**Line 127:** BEQ space2reset     ; branch/jump if the result in A is 0

The errors...
**Line 110**:Page boundary crossed.   -   F:\C64\UltimateTests\test.asm

**Line 127**:Page boundary crossed.   -   F:\C64\UltimateTests\test.asm

[Error] Line 72:Invalid branch (200 bytes) "BEQ Name2    ; if we find it we branch using BEQ to name2 for msg2 "

[Error] Line 143:Invalid branch (-275 bytes) "BEQ StartBlackOut"

Also, as you can see above I am getting invalid branch errors with these strange (200 bytes) and (-275 bytes) -- here is the section of code...

getnameb
        jsr $FF9F   ;SCNKEY, place ASCII character into keyboard queue
        jsr $FFE4   ;GETIN, this places the ASCII value into the Accumulator 

        BEQ getnameb ;loop until keys are pressed. (Branch if equal to zero)
        
        JSR $FFD2    ; CHROUT, print it to the screen as it is being typed in.
        CMP #13      ; CMP looks for the carrige return
        BEQ Name2    ; if we find it we branch using BEQ to name2 for msg2 
        
        CMP #32         ; Looking for space bar. If true error 1 is returned
        BEQ ErrorInput1

        ldx $0900    ; load into x the value at $0900 - replace what was there from JSRs
        STA $0019,x  ; also store what is being typed in consecutively? 
        INX          ; X IS INCREASED BY 1.
        stx $0900    ; Store X back to $0900, avoid being molested by the above JSRs
                     ; The value at $0900 is the length of the string!
        
        LDA $0900        ; Load into A the current length of the string 
        CMP #08          ; Looking for max 8 chars. If true error 2 is returned
        BEQ ErrorInput2
        
        JMP getnameb     ; if we don't we loop! 


;PRINT ERRORS 1 OR 2

;-----1
ErrorInput1   
        LDX #00       ; load into the x registry zero


E1cycle  
        LDA E1msg,x    ; load into A the E1msg, the x sequence.
        CMP #00        ; compare memory and accumulator to the value 0?    
        BEQ space2reset     ; branch/jump if the result in A is 0
        STA 1424,x     ; where on the screen does E1msg start?
        INX            ; inc x to move the print along 1 space?
        
        JMP E1cycle    ; jump back to the beginning of cycle and do it all again.

E1msg   text 'ERROR: NO SPACES PERMITTED - SPACE TO RESET'
        byte 0
;-----2

ErrorInput2  
        LDX #00       ; load into the x registry zero


E2cycle  
        LDA E2msg,x    ; load into A the E1msg, the x sequence.
        CMP #00        ; compare memory and accumulator to the value 0?    
        BEQ space2reset     ; branch/jump if the result in A is 0
        STA 1424,x     ; where on the screen does E1msg start?
        INX            ; inc x to move the print along 1 space?
        
        JMP E2cycle    ; jump back to the beginning of cycle and do it all again.

E2msg   text 'ERROR: MAX 8 CHARACTERS PERMITTED - SPACE TO RESET'
        byte 0

space2reset    
        jsr $FF9F   ;SCNKEY, place ASCII character into keyboard queue
        jsr $FFE4   ;GETIN, this places the ASCII value into the Accumulator 

        BEQ space2reset ;loop until keys are pressed. (Branch if equal to zero)
        
        CMP #32
        BEQ StartBlackOut ; Go to the very beginning of the programming and reset the whole thing!       

I need this explained to me in very simple terms as I am still learning, and finding the jargon a bit difficult to understand at times. Thanks!

2

There are 2 answers

0
BagoZonde On

Each instruction takes some amount of bytes (check reference for each instruction to learn more about it). For example, LDA nnnn takes 3 bytes. So, in the case when relative branching is used (beq, bcs, bcc, etc.) instead of absolute jumps (jmp), a program counter (PC) can jump only within a page i.e. in a range from -128 to 127 bytes (from 128 bytes backward to 127 bytes forward).

To fix it, you might change this:

beq longShot
   ... // more than 127 bytes of code here...
longShot

into that:

bne +
    jmp longShot
+
   ... // more than 127 bytes of code here...
longShot

It is worth mentioning that some assembly compilers, e.g. 64tass supports long branching. It will automatically compile relative branching to absolute in case it's out of that range. I don't use this option though as I prefer to control it by myself.

0
Omar and Lorraine On

I am getting the error page boundary crossed when I run my program. Nowhere in the CBM prg studio app for Windows 10 help does it explain how I can either increase this boundary, or what I need to do in order to avoid these errors.

You may not increase the boundary, this is a hardware limitation. Instead, you should make sure that the target of your conditional branch (i.e., where it jumps to) is not too far away from the branch instruction itself. In other words, the branch instruction cannot jump to a destination that's too far away. (Too far means, 128 ish bytes apart or more).

The way to fix this could be to rearrange your code so that the targets are closer to the branch instructions. But failing that, you can do this:

    bne n
    jmp where_you_want_to_go
n:  ; label for the next instruction after the jump

instead of this

    beq where_you_want_to_go