branch is out of range?

Discussion in 'Discussion and Q&A Archive' started by warr1or2, Aug 15, 2012.

Thread Status:
Not open for further replies.
  1. warr1or2

    warr1or2 I AM CLG Member

    Joined:
    Apr 7, 2008
    Messages:
    416
    Location:
    Town Creek, AL
    sonic.asm(25476) error: Branch (32768 bytes) is out of range


    this even happened with the backups i made and i only save the backup on every good build in case a major messup.


    hadn't messed with the 2 in a few days and now it done this. everything seems ok but when i build, this happens.


    keep in mind this is s1hacking studio 2 disassembly pack which is a modded hivebrain asm
     
    Last edited by a moderator: Aug 15, 2012
  2. SuperEgg

    SuperEgg I'm a guy that knows that you know that I know Member

    Joined:
    Oct 17, 2009
    Messages:
    Location:
    THE BEST GOD DAMN STATE OF TEXAS
    Do you mind sharing what the piece of code is? It's nice to know the error, but without seeing what the code is, there is no telling what it is.


    Here is quick little trick to remember....


    bsr.s->bsr.w->jsr


    bra.s->bra.w->jmp


    I think I've mentioned this before in another thread you've created, but I'll post it right there for simplicity.
     
  3. warr1or2

    warr1or2 I AM CLG Member

    Joined:
    Apr 7, 2008
    Messages:
    416
    Location:
    Town Creek, AL
    yes i know this much already, and about the piece of code...


    strange, thought i attached the whole sonic.asm file cause i don't know what code is causing this, like i said

     
  4. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    sonic.asm(25476)


    Goto line number 25476 in "sonic.asm".
     
  5. warr1or2

    warr1or2 I AM CLG Member

    Joined:
    Apr 7, 2008
    Messages:
    416
    Location:
    Town Creek, AL
    that's the kill sonic code which i NEVER messed with, but that was the problem.


    i was always using notepad for this, guess from now on i should use eseasmedit.


    thanks marky
     
  6. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    It doesn't matter if you haven't touched it or not. Some places can suddenly come out of range.


    If you edit/add code between the "Kill Sonic" routine and the routine it's trying to branch to, it can obviously grow in time; eventually not able to reach anymore. Every now and then, you will get this, and it's just a matter of going to that branch and making it jump further.
     
  7. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    Sonic 1 contains lots of unused data another way to fix branch errors is to remove unused code this will only work for so long you will run out of unused stuff to remove then you will have to fix branches in this case you are 1 byte away from not getting this error so I recommend you remove unused code here is a hint. Goto the line the branch error occurres (Press CTRL+G to goto line) and then run a search in the up direction for unused you should find this:



    Code:
    
    ; ---------------------------------------------------------------------------
    
    ; Unused floor/wall subroutine - logs something	to do with collision
    
    ; ---------------------------------------------------------------------------
    
    
    
    ; ||||||||||||||| S U B	R O U T	I N E |||||||||||||||||||||||||||||||||||||||
    
    
    
    
    
    ;FloorLog_Unk:				; XREF: Level
    
    ;		rts	
    
    ;
    
    ;		lea	(CollArray1).l,a1
    
    ;		lea	(CollArray1).l,a2
    
    ;		move.w	#$FF,d3
    
    
    
    ;loc_14C5E:
    
    ;		moveq	#$10,d5
    
    ;		move.w	#$F,d2
    
    
    
    ;loc_14C64:
    
    ;		moveq	#0,d4
    
    ;		move.w	#$F,d1
    
    ;
    
    ;loc_14C6A:
    
    ;		move.w	(a1)+,d0
    
    ;		lsr.l	d5,d0
    
    ;		addx.w	d4,d4
    
    ;		dbf	d1,loc_14C6A
    
    ;
    
    ;		move.w	d4,(a2)+
    
    ;		suba.w	#$20,a1
    
    ;		subq.w	#1,d5
    
    ;		dbf	d2,loc_14C64
    
    ;
    
    ;		adda.w	#$20,a1
    
    ;		dbf	d3,loc_14C5E
    
    ;
    
    ;		lea	(CollArray1).l,a1
    
    ;		lea	(CollArray2).l,a2
    
    ;		bsr.s	FloorLog_Unk2
    
    ;		lea	(CollArray1).l,a1
    
    ;		lea	(CollArray1).l,a2
    
    ;
    
    ; End of function FloorLog_Unk
    
    
    
    ; ||||||||||||||| S U B	R O U T	I N E |||||||||||||||||||||||||||||||||||||||
    
    
    
    
    
    ;FloorLog_Unk2:				; XREF: FloorLog_Unk
    
    ;		move.w	#$FFF,d3
    
    ;
    
    ;loc_14CA6:
    
    ;		moveq	#0,d2
    
    ;		move.w	#$F,d1
    
    ;		move.w	(a1)+,d0
    
    ;		beq.s	loc_14CD4
    
    ;		bmi.s	loc_14CBE
    
    ;
    
    ;loc_14CB2:
    
    ;		lsr.w	#1,d0
    
    ;		bcc.s	loc_14CB8
    
    ;		addq.b	#1,d2
    
    ;
    
    ;loc_14CB8:
    
    ;		dbf	d1,loc_14CB2
    
    ;
    
    ;		bra.s	loc_14CD6
    
    ;; ===========================================================================
    
    ;
    
    ;loc_14CBE:
    
    ;		cmpi.w	#-1,d0
    
    ;		beq.s	loc_14CD0
    
    ;
    
    ;loc_14CC4:
    
    ;		lsl.w	#1,d0
    
    ;		bcc.s	loc_14CCA
    
    ;		subq.b	#1,d2
    
    ;
    
    ;loc_14CCA:
    
    ;		dbf	d1,loc_14CC4
    
    ;
    
    ;		bra.s	loc_14CD6
    
    ; ===========================================================================
    
    
    
    ;loc_14CD0:
    
    ;		move.w	#$10,d0
    
    ;
    
    ;loc_14CD4:
    
    ;		move.w	d0,d2
    
    ;
    
    ;loc_14CD6:
    
    ;		move.b	d2,(a2)+
    
    ;		dbf	d3,loc_14CA6
    
    ;
    
    ;		rts	
    
    
    
    ; End of function FloorLog_Unk2
    
    
    Put commans before all the lines like I did or remove all this code.

    Do the same for



    Code:
    
    
    
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; Unused subroutine to squash Sonic
    
    ; ---------------------------------------------------------------------------
    
    ; move.b $26(a0),d0
    
    ; addi.b #$20,d0
    
    ; andi.b #$C0,d0
    
    ; bne.s locret_13302
    
    ; bsr.w Sonic_DontRunOnWalls
    
    ; tst.w d1
    
    ; bpl.s locret_13302
    
    ; move.w #0,$14(a0) ; stop Sonic moving
    
    ; move.w #0,$10(a0)
    
    ; move.w #0,$12(a0)
    
    ; move.b #$B,$1C(a0) ; use "warping" animation
    
    
    
    ;locret_13302:
    
    ; rts
    
    
     
    Last edited by a moderator: Aug 15, 2012
  8. warr1or2

    warr1or2 I AM CLG Member

    Joined:
    Apr 7, 2008
    Messages:
    416
    Location:
    Town Creek, AL
    i'll keep that in mind next time RHS


    and SonicMaster i might just do that if i'm not going to use it
     
    Last edited by a moderator: Aug 15, 2012
  9. SuperEgg

    SuperEgg I'm a guy that knows that you know that I know Member

    Joined:
    Oct 17, 2009
    Messages:
    Location:
    THE BEST GOD DAMN STATE OF TEXAS
    Just because you comment out code doesn't make the branch error disappear. You need to change branch code to an alternative of some sort.
     
  10. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    He was one byte away from not getting the branch error. If it was .w extension. I found a good table that has how long each instruction takes http://www.hot.ee/tmeeco/MD.HTM look for All the 68K instruction execution times(4KB)


    If some cases it may be faster to use a BRA vs JMP or BSR vs a JSR



    Code:
    
    -------------------------------------------------
    
    | BRA | Byte | 10(2/0) | - |
    
    | | Word | 10(2/0) | - |
    
    -------------------------------------------------
    
    | BSR | Byte | 18(2/2) | - |
    
    | | Word | 18(2/2) | - |
    
    -------------------------------------------------
    
    


    Code:
    
    ------------------------------------------------------------------------------------------
    
    |INSTR    | SIZE    |  (An)    | (An)+    | -(An)    | d(An)    |d(A,R)*| xxx.W    | xxx.L    | d(PC)    |d(PC,R)*|
    
    ------------------------------------------------------------------------------------------
    
    | JMP    |    -    | 8(2/0)|    -    |    -    |10(2/0)|14(3/0)|10(2/0)|12(3/0)|10(2/0)| 14(3/0)|
    
    ------------------------------------------------------------------------------------------
    
    | JSR    |    -    |16(2/2)|    -    |    -    |18(2/2)|22(2/2)|18(2/2)|20(3/2)|18(2/2)| 22(2/2)|
    
    ------------------------------------------------------------------------------------------
    
    
     
    Last edited by a moderator: Aug 17, 2012
  11. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    If I could speak publically here, the additional size reduction would normally be considered an important thing, as would processing time. The thing is, in todays standards, size is not as much as an issue, instructions don't take up much memory, thus it's not much of a concern on many hackers' part, the additional processing time gained from one singular instruction would be that of a snowflake on a planet of cold clouds, very insignificant in this situation seeing as it only runs once a frame.


    What Sonic master is saying shouldn't be "ignored" and it does related to the issue entirely, it can (and in this instance, does) prevent branch errors. I do feel that he could have explained it better though =$
     
  12. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    Ok then I will try to explain.


    you could use jsr (address).l and get the same speed as bsr.w and if you did jsr(address).w which is very similar to bsr.w it would take longer. bsr.w takes two less bytes I admit that is not much but I do want to promote good coding habits and hope that people understand exactly what they are doing instead of just guessing. I am not always good at expalining things I should not have assumed that everyone would be able to understand the table but it happens. Also what does that =$ thing at the end of your post mean? it is not in urban dictonary when I google it I get no results the only time I have seen it is when I wrote a program in autoit all variables had to start with a $ symbol.
     
    Last edited by a moderator: Aug 17, 2012
  13. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Well actually, I think you've confused it even more =$ (the =$ is an emoticon by the way, I tend to use the $ rather than an S).


    ("xx" refers to "sr" or "mp"/"ra" from this point on)


    Firstly, "jxx (Address).w" isn't really similar to "bxx Address", I believe you're referring to pc reletive "jxx Address(pc)", which does the same, is the same size, and the same speed. "jxx (Address).w" isn't relative, or well, it could be "considered" relative, but to address 00000000, it is sign-extension, it will assemble only the lower word of the address, and when being read by the processor it will sign extend it before jumping to it.


    • Positive values from 0000 – 7FFF extend to 00000000 – 00007FFF


    • Negative values from 8000 – FFFF extend to FFFF8000 – FFFFFFFF


    Again, this is the same size and same speed. The only benefit to using this over a branch or pc relative jump, is if where it were branching from were too far away from the destination, but the destination were within the range of FFFF8000 - 00007FFF.


    I get what you're saying entirely though about optimisation, you are entirely right and I do agree with you. All I'm saying is, this guy is just looking for the simplest "perminant" fix (minorly beneficial or not), and if you were to explain it thoroughly, you would probably be wasting your time as he is less prone to pay attention.


    Good effort on the previous explanation though, it is nice to see people working this stuff out.
     
    Last edited by a moderator: Aug 18, 2012
  14. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    That is true I should have read though warr1or2's post and noticed a sonic hacking studio reference and I should have used that as a sign that he would not care.
     
    Last edited by a moderator: Aug 18, 2012
  15. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Are we seriously explaining branch out of range errors? If one will not take the time to look at the fundamental basics of 68K, then why the fuck are we explaining this? Start up buides are littered everywhere.
     
  16. Mike B Berry

    Mike B Berry A grandiose return Member

    Joined:
    Jun 6, 2012
    Messages:
    377
    Location:
    New places, newer motivation
    Not to sound like a bitch or a moderator or anything like that, but why is this worthy of an explanation in the first place. I know I ask for too much myself, but; why should we help out someone who couldn't even figure out how to fix a branching error on the first place? In retro spect, that is one of the most vital parts of asm in my point of view. I don't understand why anyone could even be a member for this kind of thing. I do however, understand that these posts aren't regarding a lot of logic, and it get's tiresome having to read something that is so easy but so hard in the eyes of others... I leave my words as such, in place, where they are. And don't hate me for this.
     
  17. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Don't shit on the topic guys, you don't need to be nasty because of a personal quirk you have with the member, if you're concerned, don't post.


    An explanation was given, warr1or2 has his answer, so with that, I think we're done here.
     
  18. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    The branches explanations by MJ and Sonic master may not of been useful to warr1or2, but it may come in use to other members of SSRG. They may read this topic and think "Nice, I didn't know that, thanks" or whatever. It's useful to know why bsr.s is better than bsr.w or jsr, etc.
     
Thread Status:
Not open for further replies.