Download presentation
Presentation is loading. Please wait.
1
Computer Science 210 Computer 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) 1 N Z P
8
Example: Subtract 1 from R3
1 When R3 = 0 add R3, R3, -1 N Z P 1 When R3 > 0 Circuitry sets condition codes after add executes N Z P 1 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 N Z P PC offset 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
N Z P PC offset 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:
14
Example: Sum 10..1 sum <- sum & 0 number = 10 while number > 0:
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)
Base Contents of the base register are copied to the PC Can go anywhere in memory!
23
Trap Instruction (TRAP)
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
24
Assembly Language Chapter 7
For Monday Assembly Language Chapter 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.