Building a simple loop using Blackfin assembly code

Slides:



Advertisements
Similar presentations
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Advertisements

Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Daddy! -- Where do instructions come from? Program Sequencer controls program flow and provides the next instruction to be executed Straight line code,
6/2/2015 Labs in ENCM415. Laboratory 2 PF control, Copyright M. Smith, ECE, University of Calgary, Canada 1 Temperature Sensor Laboratory 2 Part 2 – Developing.
Thermal arm-wrestling Design of a video game using two programmable flags (PF) interrupts Tutorial on handling 2 Hardware interrupts from an external device.
Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin There is always a “MAKE-UP-YOUR-QUESTION-AND-ANSWER-IT” Question on a Dr. Smith.
Developing a bicycle speed-o-meter Part 2 A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.
Review of Blackfin Syntax Moves and Adds 1) What we already know and have to remember to apply 2) What we need to learn.
Software and Hardware Circular Buffer Operations First presented in ENCM There are 3 earlier lectures that are useful for midterm review. M. R.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin Expand on these ideas for Q9 question and answer on the final.
Developing a bicycle speed-o-meter A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.
Understanding the Blackfin ADSP-BF5XX Assembly Code Format
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Laboratory 1 – ENCM415 Familiarization with the Analog Devices’ VisualDSP++ Integrated Development Environment.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Just enough information to program a Blackfin Familiarization assignment for the Analog Devices’ VisualDSP++ Integrated Development Environment.
Blackfin BF533 EZ-KIT Control The O in I/O
Developing a bicycle speed-o-meter Midterm Review.
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 3 Understanding the memory pipeline issues.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);
A first attempt at learning about optimizing the TigerSHARC code TigerSHARC assembly syntax.
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
Generating a software loop with memory accesses TigerSHARC assembly syntax.
Developing a bicycle speed-o-meter
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Software and Hardware Circular Buffer Operations
Generating the “Rectify” code (C++ and assembly code)
Generating “Rectify( )”
A Play Core Timer Interrupts
Thermal arm-wrestling
DMA example Video image manipulation
The planned and expected
Overview of SHARC processor ADSP Program Flow and other stuff
Trying to avoid pipeline delays
Generating a software loop with memory accesses
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
* M. R. Smith, University of Calgary, Alberta,
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Thermal arm-wrestling
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Assembly Language Review
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Expand on these ideas for Q9 question and answer on the final
Getting serious about “going fast” on the TigerSHARC
Thermal arm-wrestling
3.
Concept of TDD Test Driven Development
Explaining issues with DCremoval( )
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
DMA example Video image manipulation
Developing a bicycle speed-o-meter
Independent timers build into the processor
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Thermal arm-wrestling
Developing a bicycle speed-o-meter Part 2
A first attempt at learning about optimizing the TigerSHARC code
Working with the Compute Block
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
Presentation transcript:

Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada

Tackled today Bring Blackfin Instruction Reference Manual Determine the differences / advantages and disadvantages between for-loops, while-loops, do-while-loops and do-while-loops with initial tests Demonstrate ability to turn functioning “C++” into Blackfin assembly code 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

C++ version of code -- “for-loop” int SimpleForLoopCPP(void) { int counter = 0; int sum = 0; for (counter = 0; count <= 15; count++) { sum += counter; } return sum; 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Stub for int SimpleForLoopASM (void) #include <defBF533.h> #include <macros.h> .section program; .global _SimpleForLoopASM; .align 4; #define SimpleForLoopASMSTACK 16 _SimpleForLoopASM:         // void SimpleForLoopASM (void) {     LINK SimpleForLoopASMSTACK;         // Code for loop goes here                         P0 = [FP + 4 ];     UNLINK;     JUMP (P0);          // } _SimpleForLoopASM.end: 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Translation problems with “for-loop” into assembly code Most processors don’t any capability to directly perform “for-loops” in assembly code. Blackfin has “limited” capability MIPS has ? 68000 has ? Time spent in function depends on capabilities of compiler and processor An optimizing compiler may recognize that “nothing useful” is happening in the loop and remove it from the function Loop speed depends on processor speed – improve the processor means code speed is faster Original “Invaders” game on Atari processor used this as a “feature” and not a bug. 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

C++ version of code while-loop and do-while loop Could be constructed using “while” and “do while” constructs WHILE int counter = 0; while (counter <= 15) { sum += counter; counter++; } DO_WHILE int counter = 0; do { sum += counter; counter++; } while (counter <= 15) ; NOTES ON ISSUES WITH WHILE AND DO- WHILE CONSTRUCTS 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Can now develop / test a “C++” prototype function WHILE int counter = 0; while (counter <= 15) { sum += counter; counter++; } CHANGE CODE FORMAT TO PREPARE FOR ASSEMBLY CODE TRANSLATION – 1 ACTION PER LINE int counter = 0; WHILE: IF (counter > 15) then JUMP to ENDWHILE label ELSE { counter++; JUMP to WHILE label ENDWHILE: 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Knowledge we need to have in order to be able to continue int counter = 0; WHILE: IF (counter > 15) then JUMP to ENDWHILE label ELSE { sum += counter; counter++; JUMP to WHILE label } ENDWHILE: What register is suitable to store the counter value? What register is suitable to store the sum value? How do you do a conditional jump? How do you do a test such as counter > 2? How do you do a test such as counter > 15? -- There IS a difference 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

How do you do a conditional jump on a Blackfin? Key reference material Blackfin Instruction Manual Chapter 7 Program Flow Control Instruction Summary • “Jump” on page 7-2 • “IF CC JUMP” on page 7-5 • “Call” on page 7-8 • “RTS, RTI, RTX, RTN, RTE (Return)” on page 7-10 • “LSETUP, LOOP” on page 7-13 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

How do you do a conditional jump to instruction label END_WHILE: Add the answer 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

The condition code register CC This is the Blackfin Boolean condition code or flag register Can take the value TRUE = 1 Can take the value FALSE = 0 Can be set in a number of different ways 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

The condition code register CC used to conditionally move register values Legal conditional MOVE instructions? IF NOT LEGAL WHY NOT? CONDITIONAL MOVE CHECK THEM OUT BY LOOKING IN CHAPTER 9-8!! IF CC R4 = R5; // If CC TRUE then set R4 = R5 Meaning MOVE the value in R5 into R4 (leaves R5 unchanged) IF !CC R6 = R7; // If CC FALSE then set R4 = R5 IF CC P0 = R5; IF !CC P2 = P7; IF CC R0 = R7.L; IF !CC R0.L = R4.L 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

How to we set the CC register? Reference Blackfin Instruction Manual Chapter 6, Condition Code Bit Management CC = Dreg == Dreg ; /* equal, register, signed (a) */ CC = Dreg < Dreg ; /* less than, register, signed (a) */ CC = Dreg <= Dreg ; /* less than or equal, register, signed (a) */ CC = Dreg == imm3 ; /* equal, immediate, signed (a) */ CC = Dreg < imm3 ; /* less than, immediate, signed (a) */ CC = Dreg <= imm3 ; /* less than or equal, immediate, signed (a) */ CC = Dreg < Dreg (IU) ; /* less than, register, unsigned (a) */ CC = Dreg <= Dreg (IU) ; /* less than or equal, register, unsigned (a) CC = Dreg < uimm3 (IU) ; /* less than, immediate, unsigned (a) */ CC = Dreg <= uimm3 (IU) ; /* less than or equal, immediate unsigned 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Important to know what you CAN’T DO when setting CC!! YOU CAN DO CC = R1 == R2 YOU CAN’T DO CC = (R1 == R2); YOU CAN DO CC = R1 < 3; YOU CAN’T DO CC = R1 < 7; BUT YOU CAN DO CC = R1 < 7 (IU); YOU CAN DO CC = R1 < -3; YOU CAN’T DO CC = R1 < -3 (IU); 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

WHAT ARE WE TRYING TO DO? IS IT LEGAL SYNTAX OR NOT? CC = R1 < 2; // Attempting to test 32-bit DATA register CC = R1 < 9 ; // Attempting to test 32-bit register CC = R1.L < 2 ; // Attempting to test 16-bit register CC = R1.L < 9 ; // Attempting to test 16-bit register CC = P3 <= P4; // Attempting to test 32-bit POINTER register CC = P3 < 4; // Attempting to test 32-bit POINTER register R3 = 1; // Putting TRUE value into R3? CC = R3; R4 = R5 – R6; // Math operations – sets the Arithmetic Zero flag CC = AZ; 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Now you have enough information to code “while” operations in Blackfin Translate line-by-line int counter = 0; WHILE: IF (counter <= 15) then JUMP to ENDWHILE label ELSE { sum += count; counter++; JUMP to WHILE label } ENDWHILE: 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Code the do-while loop DO_WHILE int counter = 0; do { sum += counter; } while (counter <= 15); } 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Are there advantages for a Do-while loop with an initial test? WHILE int counter = 0; while (counter <= 15) { sum += counter; counter++; } JUMPS NEEDED IN RED DO_WHILE int counter = 0; do { } while (counter <= 15) FASTEST LOOP DO_WHILE WITH INITIAL TEST int counter = 0; // Unknown value in “avalue” if (counter > avalue) { do { sum += counter; counter++; } while (counter <= avalue) } 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Code the do-while loop with initial test DO_WHILE WITH INITIAL TEST unsigned short int counter = 0; if (counter > timeToUse) { do { counter++; } while (counter <= timeToUse) } 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Questions to answer at a later time Speed -- timing issues Number of instructions in do-while loop function Number of instructions in while loop function Number of jump operations (each time round the loop) with do-while loop function Number of jump operations (each time round the loop) with while loop function 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Major problem A major problem with any form of loop is the “one-off” problem You go round the loop one time too many You go round the loop one time too few Do any of the code examples in this lecture suffer from this problem? 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Blackfin “real” for-loops Needed in Assignment 1 int counter = 0; int sum = 0; for (counter = 0; count <= 15; count++) { sum += counter; } Chapter 7 Form 1 – big loops LOOP loop_name loop_counter LOOP_BEGIN loop_name LOOP_END loop_name Form 2 – small loops LSETUP (Begin_Loop, End_Loop) loop_counter 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Blackfin “real” for-loops Needed in Assignment 1 int counter = 0; int sum = 0; for (counter = 0; count <= 15; count++) { sum += counter; } Chapter 7 Form 1 – big loops LOOP loop_name loop_counter LOOP_BEGIN loop_name LOOP_END loop_name Form 2 – small loops LSETUP (Begin_Loop, End_Loop) loop_counter Special loop control registers Loop_Top LT1 and LT0 (address) Loop_Bottom LB1 and LB0 (address) Loop_Count LC1 and LC0 (number) 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Code the “big loop” format int counter = 0; int sum = 0; for (counter = 0; count <= 15; count++) { sum += counter; } Form 1 – big loops LOOP loop_name loop_counter LOOP_BEGIN loop_name LOOP_END loop_name 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Code the “small loop” format int counter = 0; int sum = 0; for (counter = 0; count <= 15; count++) { sum += counter; } Form 2 – small loops LSETUP (Begin_Loop, End_Loop) loop_counter 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Tackled Today Differences in behaviour between for-loops, while-loops, do-while-loops, do-while loops with initial test Conditional JUMP and Conditional MOVE instructions Setting the CC condition code register What you would like to do, and can What you would like to do, but can’t 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada

Information taken from Analog Devices On-line Manuals with permission http://www.analog.com/processors/resources/technicalLibrary/manuals/ Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright  Analog Devices, Inc. All rights reserved. 4/17/2019 Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada