Expanded out-of-range-error fixing tutorial

Discussion in 'Tutorials Archive' started by Oerg866, Feb 28, 2009.

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

    Oerg866 Well-Known Member Member

    Joined:
    Aug 29, 2008
    Messages:
    299
    Location:
    Frankfurt, Germany
    Right.


    Out-of-range errors happen when you add code and a branch routine points to a subroutine that is out of range for the selected branch type.


    Let's have a quick look at all branch types.

    • BRA
    • BSR



    The following ones are used after a CMP command

    • BLT
    • BEQ
    • BNE
    • BLE
    • BGT
    • BGE]



    BRA: Branch to a location


    BSR: Branch to a subroutine


    AFTER CMP:


    BLT: Branch if less


    BEQ: Branch if equal


    BNE: Branch if not equal


    BLE: Branch if less or equal


    BGT: Branch if greater


    BGE: Branch if greater or equal


    BRA and BSR can be fixed in the following way:



    Code:
       bra.&#40;s or w&#41; <label>


    Code:
       bsr.w <label>


    Are changed to





    Code:
    jsr <label>




    For all the CMP commands you have to be careful when fixing them.



    Fixing a BLT:





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       blt.s RoutineLess44; If it&#39;s less than that, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bge.s RoutineGreaterOrEqual44; If it&#39;s greater or equal, branch
    
       jsr RoutineLess44
    
    
    
    
    
    RoutineGreaterOrEqual44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    What we've done here is to revert the "Less" -- So if it isn't less then it of course has to be "Greater or Equal". We made the branch to point to the code that would've happened if d0 was lower than $44.





    Fixing a BEQ





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       beq.s RoutineEqual44; If it&#39;s equal, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bne.s RoutineNotEqual44; If it&#39;s not equal, branch
    
       jsr RoutineEqual44
    
    
    
    
    
    RoutineNotEqual44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Self explantatory, I guess.



    Fixing a BNE is following the exact same pattern.





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bne.s RoutineNotEqual44; If it&#39;s not equal, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       beq.s RoutineEqual44; If it&#39;s equal, branch
    
       jsr RoutineNotEqual44
    
    
    
    
    
    RoutineNotEqual44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Fixing a BLE is pretty easy too.





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       ble.s RoutineLessOrEqual44; If it&#39;s less or equal, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bgt.s RoutineGreater44; If it&#39;s greater, branch
    
       jsr RoutineLessOrEqual44
    
    
    
    
    
    RoutineGreater44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Fixing a BGT is easy again.





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bgt.s RoutineGreater44; If it&#39;s greater, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       ble.s RoutineLessOrEquall44; If it&#39;s greater, branch
    
       jsr RoutineGreater44
    
    
    
    
    
    RoutineLessOrEqual44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Fixing a BGE





    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bge.s RoutineGreaterOrEqual44; If it&#39;s greter or equal, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;


    Will change to:







    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       bne.s RoutineNotEqual44; If it&#39;s not equal, branch
    
       jsr RoutineGreaterOrEqual44
    
    
    
    
    
    RoutineNotEqual44&#58;
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       &#40;...&#41;



    I hope you've understood it better now.


    By the way, if you add new code, I suggest you to add it at the end of the ASM file (but before the END command of course)
     
    Last edited by a moderator: Feb 28, 2009
  2. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    I get Selbi's and I don't get yours. And you fail at spelling understandable.
     
  3. c1owd

    c1owd Previously 'CarrascoZX0' Member

    Joined:
    Dec 13, 2008
    Messages:
    364
    I agree I think Selbi's is easier and his tutorial on it is better than yours... I actually understand Selbi's tutorial...


    EDIT: You spelled "understandabl" wrong... xD... it's understandable...
     
    Last edited by a moderator: Feb 28, 2009
  4. Malevolence

    Malevolence Well-Known Member Member

    Joined:
    Jul 29, 2008
    Messages:
    97
    Not necessarily, some can be used after the tst command


    Firstly bsr can be bsr.s or bsr.w and secondly bsr should be changed to jsr and bra should be changed to jmp.






    First of all if it is less then it will continue this code "RoutineGreaterOrEqual44:" unless you use a jmp (same for all of them with jsr in that instance). Secondly you could just do:



    Code:
       cmpi.&#40;b/w/l&#41; $44,d0; Is value $44 in d0?
    
       blt.s JmpToRoutineLess44; If it&#39;s less than that, branch
    
       nop; Code that comes after
    
       move.b #$45,d0
    
       rts
    
    
    
    JmpToRoutineLess44&#58;
    
       jmp RoutineLess44
    
       &#40;...&#41;


    If you don't have the rts it will continue and jump to the subroutine anyway.





    The second branches if greater than, you'd want a bge which is greater than or equal.

    This is branching if less than or equal, you'd want blt.

    If it's less than this is branching, if it's greater than, it's branching. You'd want a ble.


    At the bottom of this, there's a section called "Condition Codes for Bcc, DBcc and Scc Instructions" which would seem to help you, you seem to be confused on a few things.
     
  5. eggboyX0

    eggboyX0 Newcomer Member

    Joined:
    Dec 23, 2008
    Messages:
    21
    Location:
    West Hills, California
    Holy crap, this is confusing ;) ... I like Selbi's tutorial better... It's easier to understand... ;)
     
  6. bareirito

    bareirito Well-Known Member Member

    Joined:
    Nov 17, 2008
    Messages:
    87
    Location:
    Argentina
    I followed all the steps in your BNE guide, it didn't worked, sorry.
     
  7. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Are you fucking kidding me? My guide is shit but this one is awesome? The only thing you made, was to add the other branch types (BLT, BGT,....)! Sorry, but you failed at this. It's not understandable (for me). Also, I hate these Code-Box. They are such annoying with their replacing system (Tab with a normal Space)! Next time use the ASM-Box or I'll get mad! And, I guess you just made the guide to bug me. Don't think I want to be your friend anymore!


    Just to say something.


    ~Selbi
     
  8. snkenjoi

    snkenjoi Well-Known Member Member

    Joined:
    Sep 6, 2008
    Messages:
    59
Thread Status:
Not open for further replies.