DSPRelated.com
Forums

Further detail on the DO-UNTIL query in ADSP 2181

Started by RedBaron April 6, 2001
Thanks for the feedback on my questions so far - very informative!

Here is a further elaboration on Q2 for a little more in-depth detail of the
problem.

The manual does not actually say that the IF NOT CE instruction pops any
stacks.
I assume it must do as I have seen some examples of loop code such as
CNTR = ???;
label: xxxxx
xxxxx
IF NOT CE JUMP label;

Since the CNTR= pushes the CNTR stack, the IF NOT CE must pop the CNTR stack
when the jump is not taken. I assume that the PC and LOOP stacks are not
touched because they could not have been pushed at the start of the loop (as
there is no DO..UNTIL instruction).

Back to my Q2 example.... The loop is constructed with the DO..UNTIL
instruction which as the manual says, pushes the PC and LOOP stacks. The
CNTR was pushed in the loop init code..
BUT - as my DO..UNTIL has an alternative exit via the IF NOT CE, you can see
my dilemma as to what happens to the PC and LOOP stacks.

So far the general consensus is that I correctly pop only the PC and LOOP
stacks at the Quit2 point.

Original Question Q2
==============

I have a loop construct of the following form

CNTR = 15;
DO loop UNTIL CE;
xxxxxx;
IF NOT CE JUMP DecCntr;
JUMP Quit2;
DecCntr: xxxxxx;
xxxxxx;
loop: xxxxxx;

Quit1: {a normal loop exit}
RTS;

Quit2: {alternative loop exit}
RTS;

Where xxxx indicate irrelevant code in this example.

The question is what POPs (if any) should occur at the Quit2 point ?
The processor manual is a bit vague on what gets POPed by IF NOT CE when it
does not jump.
I have assumed that the Quit2 line should execute a POP PC, POP LOOP;
instruction
which seems to work ok.



Page 3-5 of "ADSP-2100 Family Users Manual":

The counter may also be tested and automatically decremented by a
conditional jump instruction that tests CE. The counter is not
decremented when CE is checked as part of a conditional return or
conditional arithmetic instruction.

So i guess IF NOT CE JUMP... decrements CE, but IF NOT CE RTS does
not decrement CE.

So i guess to do your loop without *two* decrements of cntr,
it should be:

CNTR = 15;
DO loop UNTIL CE;
xxxxxx;
IF CE RTS;
DecCntr: xxxxxx;
xxxxxx;
loop:
xxxxxx;

Quit1:
RTS; {a normal loop exit}

Back at the calling point of this routine, pop cntr, pop loop, pop pc
needs to be done for the first RTS, but not the second (yuk).

How about:

CNTR = 15;
DO loop UNTIL CE;
xxxxxx;
DecCntr: xxxxxx; { i assume this decrements loop cntr }
xxxxxx;
IF CE pop PC, pop loop, pop cntr;
loop:
nop; Another way (haven't tried it tho):

CNTR = 15;
DO loop UNTIL CE;
xxxxxx;
DecCntr: xxxxxx; { i assume this decrements loop cntr }
xxxxxx;
IF CE OWRCNTR=1;
loop:
nop; RedBaron wrote:
>
> Thanks for the feedback on my questions so far - very informative!
>
> Here is a further elaboration on Q2 for a little more in-depth detail of the
> problem.
>
> The manual does not actually say that the IF NOT CE instruction pops any
> stacks.
> I assume it must do as I have seen some examples of loop code such as
> CNTR = ???;
> label: xxxxx
> xxxxx
> IF NOT CE JUMP label;
>
> Since the CNTR= pushes the CNTR stack, the IF NOT CE must pop the CNTR stack
> when the jump is not taken. I assume that the PC and LOOP stacks are not
> touched because they could not have been pushed at the start of the loop (as
> there is no DO..UNTIL instruction).
>
> Back to my Q2 example.... The loop is constructed with the DO..UNTIL
> instruction which as the manual says, pushes the PC and LOOP stacks. The
> CNTR was pushed in the loop init code..
> BUT - as my DO..UNTIL has an alternative exit via the IF NOT CE, you can see
> my dilemma as to what happens to the PC and LOOP stacks.
>
> So far the general consensus is that I correctly pop only the PC and LOOP
> stacks at the Quit2 point.
>
> Original Question Q2
> ==============
>
> I have a loop construct of the following form
>
> CNTR = 15;
> DO loop UNTIL CE;
> xxxxxx;
> IF NOT CE JUMP DecCntr;
> JUMP Quit2;
> DecCntr: xxxxxx;
> xxxxxx;
> loop: xxxxxx;
>
> Quit1: {a normal loop exit}
> RTS;
>
> Quit2: {alternative loop exit}
> RTS;
>
> Where xxxx indicate irrelevant code in this example.
>
> The question is what POPs (if any) should occur at the Quit2 point ?
> The processor manual is a bit vague on what gets POPed by IF NOT CE when it
> does not jump.
> I have assumed that the Quit2 line should execute a POP PC, POP LOOP;
> instruction
> which seems to work ok.
>
--
___ ___
/ /\ / /\
/ /__\ / /\/\
/__/ / Russell Shaw, B.Eng, M.Eng(Research) /__/\/\/
\ \ / Victoria, Australia, Down-Under \ \/\/
\__\/ \__\/