Download presentation
Presentation is loading. Please wait.
Published byBennett Lewis Modified over 8 years ago
1
Computer Science 210 Computer Organization Machine Language Instructions: Control
2
Control Structures: Sequence Statement-1 Statement-n.... begin statement-1. statement-n end
3
Control Structures: Selection Consequent Boolean expression Alternative False True if condition then consequent sequence else alternative sequence
4
Control Structures: Loops (Entry Control) Loop body Boolean expression False True while condition do loop body sequence
5
Control Structures: Loops (Exit Control) Loop body Boolean expression False True do loop body sequence until condition
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) 010 N Z P
8
Example: Subtract 1 from R3 add R3, R3, -1 010 N Z P When R3 = 0 001 N Z P When R3 > 0 100 N Z P When R3 < 0 Circuitry sets condition codes after add executes
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 0 0 0 0 N Z P PC 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 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 0 0 0 0 N Z P PC 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 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) 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 Contents of the base register are copied to the PC Can go anywhere in memory! 1 1 0 0 0 1 0 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
23
Trap Instruction (TRAP) 1 1 1 1 0 0 0 0 Trap vector (8 bits) 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.