1 / 101

Program Control

Program Control. ECE511: Digital System & Microprocessor. What we are going to learn in this session:. Program Control: What are they. Available instructions. How they effect program flow. Introduction. Program Control Group. Instructions that perform Conditional execution.

shanae
Télécharger la présentation

Program Control

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. Program Control ECE511: Digital System & Microprocessor

  2. What we are going to learn in this session: • Program Control: • What are they. • Available instructions. • How they effect program flow.

  3. Introduction

  4. Program Control Group • Instructions that perform • Conditional execution. • Unconditional execution. • Subroutine handling. • Achieves this through branching. • Manipulate PC.

  5. Branch Always Conditional Branch Decrement & Branch Conditional Set Program Control Branch to Subroutine Unconditional Jump Jump to Subroutine Return from Subroutine Return from Subroutine & Restore CCR The Program Control Group

  6. Unconditional Branch

  7. BRA (Branch Always) • Performs unconditional branching. • Used to create infinite loops. • Repeats the same instructions over and over. • Doesn’t stop until M68k resets/turned off.

  8. BRA (Branch Always) • Uses relative addressing mode: • Has limitations. • 8-bit signed displacement: -128 to 127. • 16-bit signed displacement: -32,768 to 32,767.

  9. BRA Format Example: BRA <ea> BRA $001000 BRA LABELNAME BRA THERE

  10. Unconditional Branching Example Instruction #1 Instruction #2 BRA HERE Instruction #3 Instruction #4 HERE Instruction #5 Instruction #6 Never executed.

  11. Infinite Loop Example LABELNAME Instructions #1 Instructions #2 … Instructions #n BRA LABELNAME

  12. BRA Example START ORG $1000 BRAHERE MOVE.B #9,D0 MOVE.B #19,D1 ADD.B D1,D0 BRA BRAHERE END START

  13. BRA Limitations • Can address maximum 32,768 addresses back, and 32,767 addresses forward. • Max forward = Address + 32,767. • Max backward = Address – 32,768. • If need to be farther, can use Jump (JMP).

  14. BRA Limitations • Find the allowed range when BRA address is at $030000. $030000 = 196,608 Max forward = 196,608 + 32,767 = 229,375 = $37FFF. Max backward = 196,608 – 32,768 = 163,840 = $28000. $28000 < Range < $37FFF

  15. JMP (Unconditional Jump) • Similar to BRA, but without limitations: • Jumps to any location in program. • Not limited to 16-bit displacements anymore.

  16. Conditional Branch

  17. Bcc

  18. Bcc (Conditional Branch) • Conditional branching: • Branch if condition is TRUE. • Execute/skip instructions results. • Addressing limitations similar to BRA: • 8-bit, 16-bit displacement. • -32,768 to 32,767.

  19. Bcc (Conditional Branch) • Conditions tested using CMP. • (Antonakos, pg. 83) • Results stored in CCR. • Used to create: • Finite loops. • Do…while loops. • If…else blocks.

  20. BGT D0.B > D1.B BGE D0.B ≥ D1.B Signed BEQ D0.B = D1.B BNE D0.B ≠ D1.B BLE D0.B ≤ D1.B BLT D0.B < D1.B Bcc BHI D0.B > D1.B BCC D0.B ≥ D1.B BEQ D0.B = D1.B Unsigned BNE D0.B ≠ D1.B BLS D0.B ≤ D1.B BCS D0.B < D1.B Conditions (cc) CMP.B D1,D0 *(Antonakos, pg. 84)

  21. Why do we need signed/unsigned conditions? • Signed/unsigned numbers carry different values. • Example: $FF12: • Need to choose cc properly. 65,298 (unsigned) -238 (signed)

  22. If treated as unsigned number, $FE = 254 $23 = 35 D0.B > D1.B If treated as signed number, $FE = -2 $23 = 35 D0.B < D1.B X N Z V C - 1 0 0 0 Bcc Example D0 = $000000FE D1 = $00000023 CMP.B D1,D0

  23. Bcc Flowchart START Evaluate conditions using CMP Condition = TRUE? TRUE FALSE Go to LABEL Execute next instruction FINISH

  24. Bcc Format LABELNAME Instructions #1 Instructions #2 … Instructions #n Test Condition Bcc LABELNAME Instructions after Bcc… If condition = TRUE If conditions = FALSE

  25. Bcc Format If conditions = TRUE, Instructions 1  n will not be executed Test Condition Bcc LABEL Instructions #1 Instructions #2 … Instructions #n LABEL Instructions after LABEL… If conditions = FALSE, All instructions executed line-by-line.

  26. If…Else Using Bcc • Check the byte stored in D3. If D3 > 10, clear the byte. Else, add 3 to the value stored in D3.B.

  27. Flowchart START Move value to D3 True False D3 > 10? Clear D3 D3 = D3 + 3 FINISH

  28. Assembly Code START ORG $1000 MOVE.B #11,D3 CMP.B #10,D3 BHI MORE BLE LESS MORE CLR.B D3 BRA FINISH LESS ADD.B #3,D3 BRA FINISH FINISH END START D3.B > 10 D3.B < 10

  29. Bcc Example – If… • Check contents of D0: • If D0 > 10, add 54 to it. • If D0 ≤ 10, do nothing.

  30. Flowchart START Move value to D0 True False D0 > 10? D0 = D0 + 54 FINISH

  31. When D0 ≤ 10 START ORG $1000 MOVE.B #5,D0 CMP #10,D0 BLE DONTHNG ADD.B #54,D0 DONTHNG NOP END START If D0 ≤ 10

  32. Condition = TRUE

  33. When D0 > 10 START ORG $1000 MOVE.B #15,D0 CMP #10,D0 BLE DONTHNG ADD.B #54,D0 DONTHNG NOP END START

  34. Condition = FALSE, Executes next line

  35. This line also executed.

  36. Program Flow MOVE.B #1,D0 CMP #10,D0 BLE DONTHNG ADD.B #54,D0 DONTHNG NOP END START If D0 ≤ 10 If D0 > 10

More Related