Your SlideShare is downloading. ×
Blackfin Loop Asm
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Blackfin Loop Asm

2,589
views

Published on

Published in: Business, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,589
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada
  • 2. 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
  • 3. Stub for void SimpleLoopASM (ushort)
    • #include <defBF533.h> #include <macros.h>
    • .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:
  • 4. 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
  • 5. 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.
  • 6. 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
  • 7. 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:
  • 8. 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?
  • 9. 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
  • 10. How do you do a conditional jump on a Blackfin?
    • Add the answer
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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 DO CC = R1 < 7 (IU);
    • YOU CAN DO CC = R1 < -3;
    • YOU CAN’T DO CC = R1 < -3 (IU);
  • 15. 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;
  • 16. Now you have enough information to code “while” and “do-while” functions
    • While loop function in Blackfin
  • 17. Now you have enough information to code “while” and “do-while” functions
    • Do-While loop function in Blackfin
  • 18. 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
  • 19. 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)
    • }
  • 20. 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)
    • }
  • 21. 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?
  • 22. 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
  • 23.
    • 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.

×