Presentation is loading. Please wait.

Presentation is loading. Please wait.

The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1.

Similar presentations


Presentation on theme: "The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1."— Presentation transcript:

1 The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1

2 Data Movement Instructions Recall that there are three types of instructions: – Operate instructions – Data movement instructions – Control instructions We consider the control instructions today

3 Control Instructions Recall that these types of instruction affect the flow of execution That is, they directly change the PC value depending on the result of the instruction We first consider a condition branch instruction

4 Conditional Branches Recall the LC-3 has three condition codes: – N – negative – Z – zero – P – positive These codes are set when an instruction write to a register Only one of these are set at a time

5 Conditional Branches The instructions that set these flags are – ADD – AND – NOT – LD – LDR – LDI – LEA

6 Conditional Branches The condition branch has opcode 0000 Bits [11:9] correspond to the N, Z, and P condition codes Bits [8:0] is the PC offset address for the branch Range of offset is -256…255 Target must be 256 bytes of the PC

7 Conditional Branches If the particular condition code is set in the processing unit(N,Z, or P) and it is selected by the instruction, then the jump if executed If the condition code is false, the jump do not occur This corresponds to an if (condition) ->jump else do nothing;

8 BR (PC-Relative) What happens if bits [11:9] are all zero? All one?

9 Task: Compute sum of 12 integers. Assume the numbers start at location 0x3100 Assume the program code starts at location 0x3000 Using Branch Instructions

10 Pseudocode: – addr= 0x3100 – valsleft = 12 – sum=0 – If (valsleft==0) end – Load value from memory[addr] – Sum=sum+value – valsleft=valsleft-1 – addr=addr+1

11 Using Branch Instructions R1  x3100 R3  0 R2  12 R2=0? R4  M[R1] R3  R3+R4 R1  R1+1 R2  R2-1 NO YES

12 AddressInstructionComments x30001 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 R1  0x3100 (PC+0xFF) x30010 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 R3  0 x30020 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2  0 x30030 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 R2  12 x30040 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 If Z, goto 0x300A (PC+5) x30050 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 Load next value to R4 x30060 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0 Add to R3 x30070 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 Increment R1 (pointer) X30080 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 Decrement R2 (counter) x30090 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 Goto 0x3004 (PC-6)


Download ppt "The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1."

Similar presentations


Ads by Google