1 / 21

The LC-3 – Chapter 6

The LC-3 – Chapter 6. COMP 2620. Problem Solving. Recall from Chapter 1 that for electrons to solve problems, we need to get through several levels of transformation We go from natural language description of the problem down to electrons

mick
Download Presentation

The LC-3 – Chapter 6

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. The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP 2620

  2. Problem Solving • Recall from Chapter 1 that for electrons to solve problems, we need to get through several levels of transformation • We go from natural language description of the problem down to electrons • Recall the second step was to write the problem as an algorithm

  3. Problem Solving • That is, we write a step-by-step process to solve our problem • Recall the properties of an algorithm: • Finiteness – terminates properly • Definiteness – each step is precisely stated • Effective Computability – it can be carried out by a computer or Turing machine

  4. Problem Solving • For this course, we will use the concept of structured programming • This originated in the 1960s as a way describing a complex system and decomposing it into smaller, more manageable tasks • Sometimes we call this systematic decomposition

  5. Problem Solving • We will use systematic decomposition as a way to design computer programs that are more complex • This technique is useful at any level

  6. Three Constructs • The main idea behind systematic decomposition is taking a task and breaking it into smaller units • These units, when put together, work the same as the larger task • We can repeat the process over and over • Works well with extremely complex tasks

  7. Three Constructs • This process is sometimes referred to as stepwise refinement • That is, we take each larger step and refine it into smaller, more detailed tasks • The smaller tasks are generally simplier that the larger task

  8. Three Constructs • There are three constructs for doing this: • Sequential • Conditional • Iterative

  9. Three Constructs

  10. Three Constructs • The sequential construct is the one to use if the task can be broken into two subtasks, one following the other • The first task executes, then the second one happens • Many times, the first task computes something that is needed by the second task • There is no repetition here!

  11. Three Constructs

  12. Three Constructs • The conditional construct tests a condition and performs one of two subtasks depending on the result • If condition is true, we perform one task • Otherwise, there is another task that we perform

  13. Three Constructs • This correlates with an if-else statement • Either task may be vacuous • There is no repetition of the check or the tasks

  14. Three Constructs

  15. Three Constructs • The iterative construct is used when there needs to be a task run multiple times • First, a condition is tested to determine where the iteration should continue • If so, the subtask runs • Otherwise the iteration is done

  16. Three Constructs • After the subtask is finished, the condition is rechecked • Then, the process repeats until the condition is false • This is similar to a while() loop

  17. Three Constructs

  18. Using the LC-3 with Constructs • We will now illustrate how the control instructions on the LC-3 can implement this three constructs • How do we use LC-3 instructions to encodethe three basic constructs? • Sequential • Instructions naturally flow from one to the next,so no special instruction needed to gofrom one sequential subtask to the next.

  19. Using the LC-3 with Constructs • Conditional and Iterative • Create code that converts condition into N, Z, or P. Example: Condition: “Is R0 = R1?” Code: Subtract R1 from R0; if equal, Z bit will be set. • Then use BR instruction to transfer control to the proper subtask.

  20. Using the LC-3 with Constructs PC offset toaddress C Exact bits depend on condition being tested Unconditional branchto Next Subtask PC offset toaddress D Assuming all addresses are close enough that PC-relative branch can be used.

  21. Using the LC-3 with Constructs PC offset to address C Exact bits depend on condition being tested Unconditional branchto retest condition PC offset toaddress A Assuming all addresses are on the same page.

More Related