Re: LF: programming command


[Prev][Next][Index][Thread]

Re: LF: programming command



Jake Robb wrote:
> Well, sort of.  I've been meaning to ask, and that reminded me.  So,
> anyway,  this program:
> 
> <some commands here>
> move #10,D0
> DBRA D0,LOOP
> <even more commands here>
> 
> LOOP
>    <some more commands>
> 
> would execute the 'some commands', put 10 into D0, jump to LOOP, and
> execute 'some more commands', decrement d0 by 1, and repeat, for a total
> of 11 times, and then execute 'even more commands'?
> 
> If I am missing anything in the lines of syntax (I'm new to this),
> especially in the loop part, please tell me.
> --
> Jake Robb

No, you've got it backwards (or upside down).  All of the DBcc
instructions (including DBRA) FOLLOW the code you want to repeat.  Your
example should be like this:

	<some commands>
	move #10,d0
loop:
	<this code is what's repeated>
	dbra d0,loop
	<rest of code>

So <some commands> would be executed, then 10 would be put in d0, then
the code you want to "repeat" would execute, when that was done DBRA
would subtract 1 from d0 and if d0 is not -1 then jump back up to loop,
otherwise continue on with <rest of code>.  You are correct that it
would run 11 times. You could also use one of the other DBcc
instructions, for example:

	move #9,d1
loop:
	jsr flib[idle_loop]
	cmp #20,d0
	dbne d1,loop

That would pause until the user hits a key, compare the key value to 20,
then DBNE (decrement and branch if not equal) would check the NE (not
equal) flag, if it was set then DBNE would decrement d1 and if d1 wasn't
-1 it would jump to loop.  If the NE flag wasn't set (that is, if
20=d0), then it would exit the loop.  This loop would run 10 times or
till the user pressed a key with value 20, whichever came first. Hope
that helps.


Josh Franta	MAIL -	jfranta@mail.coin.missouri.edu
		WEB  -	http://www.cec.wustl.edu/~jdf1


References: