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

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

Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.
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.
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.
LCD programming Design and implementation details on the way to a valid SPI-LCD interface driver.
Developing a bicycle speed-o-meter A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.
Timers and Timing Signals Tutorial. 6/18/2015 Timer Control Copyright M. Smith, ECE, University of Calgary, Canada 2 / 31 Temperature Sensor -- Lab 3.
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.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
Developing a bicycle speed-o-meter Midterm Review.
Blackfin Timers Independent timers build into the processor Watchdog Timer is a major part of Lab. 2 (Code provided to you to use)
Understanding the TigerSHARC ALU pipeline Determining the speed of one stage of IIR filter – Part 3 Understanding the memory pipeline issues.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM511.
Generating “Rectify( )” Test driven development approach to TigerSHARC assembly code production Assembly code examples Part 1 of 3.
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);
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
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.
A Play Core Timer Interrupts Acted by the Human Microcontroller Ensemble from ENCM415.
Developing a bicycle speed-o-meter
Instructions for Making Decisions
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Generating the “Rectify” code (C++ and assembly code)
A Play Core Timer Interrupts
SPI Compatible Devices
Thermal arm-wrestling
DMA example Video image manipulation
The planned and expected
Overview of SHARC processor ADSP Program Flow and other stuff
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
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.
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
Thermal arm-wrestling
Concept of TDD Test Driven Development
Explaining issues with DCremoval( )
Independent timers build into the processor Basis for Lab. 2
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
Blackfin Timers Independent timers build into the processor
Independent timers build into the processor
Developing a bicycle speed-o-meter
Developing a bicycle speed-o-meter
Thermal arm-wrestling
Building a simple loop using Blackfin assembly code
Developing a bicycle speed-o-meter Part 2
A first attempt at learning about optimizing the TigerSHARC code
Blackfin Syntax Moves and Adds
Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps
MIPS instructions.
Presentation transcript:

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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 2 / 23 Tackled on Tutorial Bring Blackfin Instruction Reference Manual to the Tutorial  Okay to work on exercises with your lab. partner 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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 3 / 23 Stub for void SimpleLoopASM (ushort) #include #include.section program;.global _SimpleLoopASM;.align 2; #define SimpleLoopASMSTACK 16 _SimpleLoopASM: // void SimpleLoopASMTime (unsigned short int timeToUse) { LINK SimpleLoopASMSTACK; // Code goes here and replaces next line R0 = 0; P0 = [FP + 4 ]; UNLINK; JUMP (P0); // } _SimpleLoopASM.end:

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 4 / 23 C++ version of code Could be constructed using “for-loop” void SimpleLoop(unsigned short int timeToUse) { unsigned short int counter = 0; for (counter = 0; count <= timeToUse; count++) { counter = counter; // Waste time } // Spin the wheels

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 5 / 23 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 ?  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.

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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 7 / 23 Can now develop / test a “C++” prototype function WHILE unsigned short int counter = 0; while (counter <= timeToUse) { counter++; } PREPARE FOR ASSEMBLY CODE TRANSLATION unsigned short int counter = 0; WHILE: IF (counter <= timeToUse) then JUMP to ENDWHILE label ELSE { counter++; JUMP to WHILE label } ENDWHILE:

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 8 / 23 Knowledge needed to continue unsigned short int counter = 0; WHILE: IF (counter <= timeToUse) then JUMP to ENDWHILE label ELSE { counter++; JUMP to WHILE label } ENDWHILE: What register is suitable to store the counter value? How is the parameter timeToUse being passed to the function? How do you do a conditional jump? How do you do a test such as counter < timeToUse? What is the difference between a loop using a signed value timeToUse and one using an unsigned value timeToUse? What is the difference between a loop using a short int value timeToUse and one using a long int value timeToUse?

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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 10 / 23 How do you do a conditional jump on a Blackfin? Add the answer

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 11 / 23 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 Legal conditional MOVE instructions? IF NOT LEGAL WHY NOT?  IF CC R4 = R5; IF !CC R6 = R7;  IF CC P0 = R5;IF !CC P2 = P7;  IF CC R0 = R7.L; IF !CC R0.L = R4.L

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 12 / 23 The condition code register CC Reference Blackfin Instruction Manual  Chapter 4, MOVE instruction Legal conditional MOVE instructions? IF NOT LEGAL WHY NOT?  IF CC R4 = R5; IF !CC R6 = R7;  IF CC P0 = R5;IF !CC P2 = P7;  IF CC R0 = R7.L; IF !CC R0.L = R4.L ANSWER HERE

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 13 / 23 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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 14 / 23 Important to know what you CAN’T DO 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 DOCC = R1 < 7 (IU); YOU CAN DOCC = R1 < -3; YOU CAN’T DOCC = R1 < -3 (IU);

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 15 / 23 LEGAL OR NOT? CC = R1.L < 2; CC = R1.L < 9; CC = R1.L < R2.L; CC = P3 <= P4; CC = P3 < 4; R3 = CC; R4 = R5 – R6; then CC = AZ;

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 16 / 23 Now you have enough information to code “while” and “do-while” functions While loop function in Blackfin

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 17 / 23 Now you have enough information to code “while” and “do-while” functions Do-While loop function in Blackfin

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 18 / 23 Questions to answer 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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 19 / 23 Are there advantages for a Do- while loop with an initial test? WHILE unsigned short int counter = 0; while (counter <= timeToUse) { counter++; } DO_WHILE unsigned short int counter = 0; do { counter++; } while (counter <= timeToUse) DO_WHILE WITH INITIAL TEST unsigned short int counter = 0; if (counter > timeToUse) { do { counter++; } while (counter <= timeToUse) }

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 20 / 23 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) }

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 21 / 23 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?

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 22 / 23 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

6/2/2015Building a simple loop using Blackfin assembly code Copyright M. Smith, University of Calgary, Canada 23 / 23 Information taken from Analog Devices On-line Manuals with permission 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.