1 / 55

Branching and Looping

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.

kezia
Download Presentation

Branching and Looping

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Branching and Looping Chapter 5

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

  3. Branch Displacement

  4. Negative Branch

  5. Branch on Z flag

  6. Branch on Z flag

  7. Branch on Z flag

  8. Branch on N flag

  9. Branch on N flag

  10. Branch on C and V flags

  11. Bit-Condition Branch Instruction

  12. How many times is the instruction INCB executed?

  13. Signed Branch Instructions

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

  15. WHYP Branching and Looping Words • IF…ELSE…THEN • FOR…NEXT • BEGIN…AGAIN • BEGIN…WHILE…REPEAT • DO…LOOP

  16. 68HC12 Code for <

  17. 68HC12 Code for U<

  18. TRUE = -1 FALSE = 0

  19. 68HC12 Code for AND

  20. IF…ELSE…THEN <cond> IF <true statements> ELSE <false statements> THEN

  21. TRUE iftest true statements next statements FALSE iftest next statements

  22. TRUE if.else.test true statements next statements FALSE if.else.test false statements next statements

  23. IF…ELSE…THEN Example

  24. FOR…NEXT Loop n FOR <WHYP statements> NEXT

  25. : stars for ." *" next ;

  26. 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

  27. Longer Delays Note: A 10 second delay on the MC68HC12A4EVB takes about 17 seconds because one wait state has been added to each access to external RAM. The 68HC11 takes over twice as long to execute the same delay instructions.

  28. BEGIN…AGAIN BEGIN <WHYP statements> AGAIN

  29. BEGIN…UNTIL BEGIN <WHYP statements> <flag> UNTIL

  30. BEGIN…WHILE…REPEAT BEGIN <words> <flag> WHILE <words> REPEAT

  31. Sine and Arcsine

  32. Sine and Arcsine

  33. Sine and Cosine

  34. DO…LOOP <limit> <index> DO <WHYP statements> LOOP Moves <limit> and <index> to return stack Increments <index> on return stack and loops back to <WHYP statements> if <index> is less than <limit>, else pop <limit> and <index> from return stack and exit loop

  35. 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

  36. DO…LOOP Example

  37. The Word LEAVE Exits a DO loop prematurely

More Related