Branching and Looping

1 / 55

# Branching and Looping - PowerPoint PPT Presentation

Branching and Looping. Chapter 5. Branching and Looping. 68HC12 Branch Instructions WHYP Branching and Looping Words Recursion in WHYP. Branch Displacement. Negative Branch. Branch on Z flag. Branch on Z flag. Branch on Z flag. Branch on N flag. Branch on N flag.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Branching and Looping' - kezia

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Branching and Looping

Chapter 5

Branching and Looping
• 68HC12 Branch Instructions
• WHYP Branching and Looping Words
• Recursion in WHYP
Branching and Looping
• 68HC12 Branch Instructions
• WHYP Branching and Looping Words
• Recursion in WHYP
WHYP Branching and Looping Words
• IF…ELSE…THEN
• FOR…NEXT
• BEGIN…AGAIN
• BEGIN…WHILE…REPEAT
• DO…LOOP
TRUE = -1

FALSE = 0

IF…ELSE…THEN

IF ELSE THEN

TRUE iftest

true statements

next statements

FALSE iftest

next statements

TRUE if.else.test

true statements

next statements

FALSE if.else.test

false statements

next statements

FOR…NEXT Loop

n FOR NEXT

FOR…NEXT Delay Loop

8 MHz clock: #ms = #clock_cycles/8 = 7.75 +1.375*N

N = (#ms - 7.75)/1.375

Ex: 50 ms delay: N = (50000 - 7.75)/1.375 = 36358

Longer Delays

Note: A 10 second delay on the MC68HC12A4EVB

takes about 17 seconds because one wait state

The 68HC11 takes over twice as long to execute

the same delay instructions.

BEGIN…AGAIN

BEGIN AGAIN

BEGIN…UNTIL

BEGIN UNTIL

BEGIN…WHILE…REPEAT

BEGIN WHILE REPEAT

DO…LOOP

DO LOOP

Moves and

to return stack

Increments on return stack

and loops back to

if is less than ,

else pop and from

return stack and exit loop

DO…LOOP

The WHYP word I copies the index value from

the return stack to the top of the parameter stack.

: test ( -- )

11 1 DO

I .

LOOP ;

will print

1 2 3 4 5 6 7 8 9 10

The Word LEAVE

Exits a DO loop prematurely

Branching and Looping
• 68HC12 Branch Instructions
• WHYP Branching and Looping Words
• Recursion in WHYP
Recursion in WHYP

n! = n * (n - 1)!