1 / 23

Computer Science 210 Computer Organization

Computer Science 210 Computer Organization. Machine Language Instructions: Control. Control Structures: Sequence. Statement-1. begin statement-1 . . statement- n end. Statement- n. Control Structures: Selection. if condition then consequent sequence else

earl
Download Presentation

Computer Science 210 Computer Organization

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. Computer Science 210Computer Organization Machine Language Instructions: Control

  2. Control Structures: Sequence Statement-1 begin statement-1 . . statement-n end . . Statement-n

  3. Control Structures: Selection if condition then consequent sequence else alternative sequence Boolean expression False Alternative True Consequent

  4. Control Structures: Loops (Entry Control) while condition do loop body sequence Boolean expression False True Loop body

  5. Control Structures: Loops (Exit Control) do loop body sequence until condition Loop body False Boolean expression True

  6. LC-3 Control Instructions • Conditional branch (BR) • Absolute branch (JMP) • Procedure call (JSR, JSRR, RET, RTI) • System call (TRAP)

  7. Condition Codes • 3 single-bit registers named N, Z, and P • Exactly one will be set at all times • Set by any instructions that write data to a register (ADD, AND, NOT, LD, LDR, LDI, LEA) 0 1 0 N Z P

  8. Example: Subtract 1 from R3 0 1 0 When R3 = 0 add R3, R3, -1 N Z P 0 0 1 When R3 > 0 Circuitry sets condition codes after add executes N Z P 1 0 0 When R3 < 0 N Z P

  9. Conditional Branch (BR) • Alters a sequence of instructions by changing the PC • Branch is taken if the condition is true • Signed offset is added to PC if condition is true; otherwise, PC not changed

  10. Conditional Branch 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 N Z PPC offset 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 0 1 BR n z p x0D9 Offset is sign-extended and added to the incremented PC Destination must be no more than +256 or -255 from the BR itself

  11. Data Path for BR

  12. Example: An Unconditional Branch 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 N Z PPC offset 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 1 BR n z p x0D9 At least one condition code is guaranteed to match the codes in this instruction

  13. Example: Sum 10..1 sum = 0 number = 10 while number > 0: sum += number number -= 1

  14. Example: Sum 10..1 sum <- sum & 0 number = 10 while number > 0: sum += number number -= 1

  15. Example: Sum 10..1 sum <- sum & 0 number <- sum + 10 while number > 0: sum += number number -= 1

  16. Example: Sum 10..1 sum <- sum & 0 number <- sum + 10 while number > 0: sum <- sum + number number -= 1

  17. Example: Sum 10..1 sum <- sum & 0 number <- sum + 10 while number > 0: sum <- sum + number number <- number + (-1)

  18. Example: Sum 10..1 sum <- sum & 0 number <- sum + 10 while: sum <- sum + number number <- number + (-1) BR p while while is a label for the address of an instruction

  19. Example: Sum 10..1 R2 <- R2 & 0 R1 <- R2 + 10 while: R2 <- R2 + R1 R1 <- R1 + (-1) BR p while Replace variables with registers R2 = sum, R1 = number

  20. Example: Sum 1..10 sum = 0 number = 1 limit = 10 while number <= limit: sum += number number += 1

  21. Example: Sum 1..10 sum <- sum & 0 number <- sum + 1 limit <- sum + 10 while: diff <- limit – number BR n endwhile sum <- sum + number number <- number + 1 BR nzp while endwhile:

  22. Jump Instruction (JMP) 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 1 0 0 Base 0 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Contents of the base register are copied to the PC Can go anywhere in memory!

  23. Trap Instruction (TRAP) 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 1 1 1 0 0 0 0 Trap vector (8 bits) OS service routine Operation coded in trap vector x23 = character input, x21 = character output, x25 = halt program R0 used for input and output After completion, PC is set to instruction following the TRAP

More Related