Grevle Posted April 27, 2015 Share Posted April 27, 2015 There seems to be limit in Assembler how far away the target adress can be when jumping or using sub routines. My solution is to make sort of a "stepping stone" so that i first jump to this stepping stone that is located in between and then jump to the target from here avoid error messages like "target to far way.. out of bounds etc.." Is this the normal way of avoiding problems with adresses to far away ? Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted April 27, 2015 Share Posted April 27, 2015 Branching instructions (BNE, BMI, etc) are the ones with the range limit (127 bytes forward, 128 back). JSR and JMP suffer from no such range limit on the 6502. Sure you can use "chains" of branching instructions, but it can get out of hand. One way is to replace branches with jumps which use the opposite logic: BNE label becomes: BEQ label2 JMP label label2: It's also often possible to juggle your code around a bit so that those branch targets fall within range. 1 Quote Link to comment Share on other sites More sharing options...
Marius Posted April 27, 2015 Share Posted April 27, 2015 (edited) One way is to replace branches with jumps which use the opposite logic: I think that that is the straight forward logic, and the other way around feels for me as the opposite logic INIT LDX #$30 LOOP AN INCREDIBLE AMOUNT OF CODE DOING THE MOST AMAZING EFFECTS! DEX BEQ READY JMP LOOP READY RTS This is (For me) the common way of using branches. Edited April 27, 2015 by ProWizard Quote Link to comment Share on other sites More sharing options...
Creature XL Posted April 27, 2015 Share Posted April 27, 2015 (edited) Branching instructions (BNE, BMI, etc) are the ones with the range limit (127 bytes forward, 128 back). JSR and JMP suffer from no such range limit on the 6502. Sure you can use "chains" of branching instructions, but it can get out of hand. One way is to replace branches with jumps which use the opposite logic: BNE label becomes: BEQ label2 JMP label label2: It's also often possible to juggle your code around a bit so that those branch targets fall within range. That is exactly how it done. CA65 has a macro "jXX" for this. And I bet MADS or other assemblers have them too. If not shouldn't be hard to implement if the assembler supports anonymous labels. As soon as ca65 tells me a branch is too far away, I use the "j-version" aka longbranch. And later, short for the release of the prod I check all longbranches and try to optimize them away with code shuffling. Sidenote: what I mean by anonymous labels. You can do this in ca65 for example: beq + jmp far_away +: nop I would be surprised if the macro package "longbranch" implements it differently. Haven't checked it. Edited April 27, 2015 by Creature XL Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted April 27, 2015 Share Posted April 27, 2015 (edited) Yes: MADS has long-range branches built in (JNE, JPL, etc). Anonymous labels are handled as: LDA FLAG BNE @+ ... @ Edited April 27, 2015 by flashjazzcat 1 Quote Link to comment Share on other sites More sharing options...
Grevle Posted April 27, 2015 Author Share Posted April 27, 2015 Thank you . It helps to know that jmp and jsr don't have the same limitations as beq bne etc. This will help specialy on where to place certain pieces of code in my program. I use a text editor and compile with atasm. i prefer this way of writing assembler. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted April 27, 2015 Share Posted April 27, 2015 The assembler in CC65 has similar long branches but it has to be enabled with :- .macpack longbranch 1 Quote Link to comment Share on other sites More sharing options...
Grevle Posted April 27, 2015 Author Share Posted April 27, 2015 (edited) Heres a teaser. i hope to finish this game, sometime, but for the time being im busy with " Real life issues ". Edited April 27, 2015 by BioFreeze 1 Quote Link to comment Share on other sites More sharing options...
Joey Z Posted April 27, 2015 Share Posted April 27, 2015 I think that that is the straight forward logic, and the other way around feels for me as the opposite logic INIT LDX #$30 LOOP AN INCREDIBLE AMOUNT OF CODE DOING THE MOST AMAZING EFFECTS! DEX BEQ READY JMP LOOP READY RTS This is (For me) the common way of using branches. this takes some additional cycles over the other method though, so if it's a loop that is relatively small and runs for many iterations, it can make a difference that matters. Quote Link to comment Share on other sites More sharing options...
Creature XL Posted April 28, 2015 Share Posted April 28, 2015 The assembler in CC65 has similar long branches but it has to be enabled with :- .macpack longbranch What do you think what "ca65" is? But, I am thankful for your post as I omit the explicit use of the macpack. Thank you. Quote Link to comment Share on other sites More sharing options...
bugbiter Posted May 4, 2015 Share Posted May 4, 2015 If you want your code to be relocatable, you really have to use the 'stepping stone' method. I once did it with several step stones like this: ...regular code clc bcc skip ; jump over stepping stone code stepstone2 clc bcc stepstone1 ; which is further up skip continue regular code... .... .... bxx stepstone2 ; here I start branching back ..... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.