Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
ARM Control Structures Branch • B identifier Branch (jump) to given identifier Branch Instruction Format • Branch instruction format: – 24 bit immediate 110101110010001001101001 – Shifted left 2 bits to make 26 bit value 11010111001000100110100100 – Sign extended to 32 bits 11111111010111001000100110100100 Branch Instruction Format • Branch instruction format: – 24 bit immediate 110101110010001001101001 – Shifted left 2 bits to make 26 bit value 11010111001000100110100100 – Sign extended to 32 bits 11111111010111001000100110100100 – Signed 26 bit value to be added to PC • +/- 32Mbytes Status Register • CPSR register Tracks state of processor, recent instructions Setting Status • CMP : Compare CMP rn, #___ CMP rn, rm Set status register based on op1 – op2 Other Comparisons • CMN : Compare Negative CMN op1, op2 Set status register based on op1 + op2 • TST : Test bits TST op1, op2 Set status register based on op1 AND op2 Does not set Carry or oVerflow bits • TEQ : Test equal TEQ op1, op2 Set status register based on op1 XOR op2 Does not set Carry or oVerflow bits Conditional Branches • BEQ identifier : Branch on equal – Status register determines if branch taken Conditional Branches • Branch options Most Common If • Assembly if’s are “backwards” High Level Assembly if(i == j) { k = 1; } … Branch to cont if r1 != r2 r3 = 1 cont: …. If • If implemented with branch: – Skip ahead if NOT doing if body If / Else • If/Else implemented with branch: – Branch to skip if body for else case – If body ends with jump to skip else body High Level Assembly if(i == j) { k = 1; } else { k = 2; } … Branch to else if r1 != r2 r3 = 1 jump to endif else: r3 = 2 endif: … If / Else • If/Else implemented with branch: – Branch to skip if body for else case – If body ends with jump to skip else body Loop = jump backwards Loop = jump backwards int i = 0; while(i < 10) { //do stuff i++; } Counting Loop • Test jumps to end when done • End branches back to test Real Code Counting Loop • Naïve loop implementation : – 4 instructions / iteration Real Code Counting Loop • Compilers usually move test to end of loop – Start by jumping to test – 3 instructions / iteration Sum • Sum 0…10 ARM Specific Tricks: Set Bits & Conditional Execution Condition Bits ARM instructions feature 4 condition bits: Condition Bits • Lots of instructions start with E Condition Bits • Specify condition to execute instruction under Condition Bits • E = 1110 Always execute Conditional Execution • Apply conditions to most instructions Condtional Without Branch • Can implement if/else as conditional instructions Setting Flags Fun Fact • CMP, CMN, TST, TEQ set status register Setting Flags Fun Fact • CMP, CMN, TST, TEQ set status register • Data instructions can do so optionally instructionS = Set status Status Flag If • If with CMP & conditional execution: Fun Fact Status Flag If Fun Fact • Setting status with subtraction instead: Status Flag If • Loop using set flags: Fun Fact