English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Asm / Hardware (https://eab.abime.net/forumdisplay.php?f=112)
-   -   nOOb needing help to understand Conditional Branching (https://eab.abime.net/showthread.php?t=99354)

KONEY 25 October 2019 05:35

nOOb needing help to understand Conditional Branching
 
My first steps in 68k assembly and already stuck in something very trivial like how to reuse pieces of code :(

I learnt a subroutine is made up by a label, some code and a RTS statement. Call it with "BSR label" and after the code inside is executed and the RTS reached the flow continues from below where the BSR was issued.

But what if I need to execute a function only with some conditions AND go back? BEQ and BNE jump to a subroutine but at the RTS the program exits. I need instead to BRA to a specific label to make it work but this prevents me from being able to call the subroutine from any part of the code I'd like.

I'm missing something... but I can't figure out what to look in manuals. All I can find are sentences like: "conditional branching will not continue from where it was called, thanks for reading." :banghead: banghead

any help...

deimos 25 October 2019 06:51

You conditionally branch, using the opposite condition, over a branch, so that the bar only gets e ecuted if your condition was true. So to call a subroutine only if d0 is equal to zero:

Code:

        tst.w  d0
        bne    1$
        bar    subroutine
1$      more code...

Use local labels for stuff like this, otherwise you'll spend more time thinking of names than coding.

KONEY 25 October 2019 23:42

WORKED! thanks!


All times are GMT +2. The time now is 03:20.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04232 seconds with 11 queries