Presentation is loading. Please wait.

Presentation is loading. Please wait.

Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);

Similar presentations


Presentation on theme: "Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);"— Presentation transcript:

1 Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);

2 Array handling -- part 1 -- M. Smith 2 of 30 To be tackled – Array handling Move arrays – Max array (Exercise) Recap Setting up the tests Writing “enough” assembly code so you can “call the code, and return without crashing” Move one value between arrays Moving through an array – Hard coding and auto-increment addressing modes – Software loops – Hardware loops will be covered in a later lecture

3 Array handling -- part 1 -- M. Smith 3 of 30 Build the project (F7)

4 Array handling -- part 1 -- M. Smith 4 of 30 Add new tests BUT WHY THE ERROR MESSAGE

5 Array handling -- part 1 -- M. Smith 5 of 30 “Just enough code” to safely return after call to assembly code.section program.global start_address label with : end_address label with : HOWEVER LINKER SAYS “CAN”T FIND THIS FUNCTION” RECOGNIZE THIS ERROR SO YOU KNOW HOW TO FIX IN THE ASSIGNMENTS AND LABS

6 Array handling -- part 1 -- M. Smith 6 of 30 Use C++ keywords ‘extern “C” ‘ so compiler knows ASM follows C calling convention and not C++ calling convention Expected test failures

7 Array handling -- part 1 -- M. Smith 7 of 30 Same memory addressing error as before INCREMENT IN 4’s with accessing int arrays TYPOS inpar1 twice

8 Array handling -- part 1 -- M. Smith 8 of 30 FIXED TYPO R2 is INPAR 3 #define N_inpar3_R2 R2

9 Array handling -- part 1 -- M. Smith 9 of 30 How do we pass back a parameter from “ASM” to “C++”

10 Array handling -- part 1 -- M. Smith 10 of 30 Parameter passing convention Pass first parameter “into” function using R0 (same for data or addresses) Pass second parameter using R1 Pass third parameter using R2 Pass 4 th parameter on “stack” (like MIPS) Return the “result of a function” using R0 as the return register

11 Array handling -- part 1 -- M. Smith 11 of 30 The starting address of “final[ ]” is still (unchanged) in R2 – copy it to “return_register” NOTE R2 typos to be fixed N_inpar3_R2 R2 #define N_inpar3_R2 R2

12 Array handling -- part 1 -- M. Smith 12 of 30 Tests now all pass

13 Array handling -- part 1 -- M. Smith 13 of 30 This code format using “index” addition can’t be looped Stop using [P0 + 4] [P0 + 8] etc Go to auto increment mode [P0++]; #define N_inpar3_R2 R2

14 Array handling -- part 1 -- M. Smith 14 of 30 Add new tests for numpoints = 10 TEST FAILS AT THIS TIME

15 Array handling -- part 1 -- M. Smith 15 of 30 Your exercise – convert to software loop format Stop using [P0 + 4] [P0 + 8] etc Go to auto increment mode [P0++]; #define N_inpar3_R2 R2

16 Array handling -- part 1 -- M. Smith 16 of 30 Problem to solve R0 – used for source in-parameter R1 – used for final in-parameter R2 – used for “N points” in-paramater R3 – used for “temp” when reading and writing memory YOU CAN’T USE R4, R5, R6, R7 without saving them to the stack. Do we have to learn about the correct way of saving things to the stack or is there another way

17 Array handling -- part 1 -- M. Smith 17 of 30 Let’s rewrite the code R0 is used to pass in the address of the beginning of the “start” array R0 is transferred to P0 so we can access memory The value in R0 is not needed again in this function Rather than learning to save things to the stack – lets re-use R0

18 Array handling -- part 1 -- M. Smith 18 of 30 Value in R0 not needed REUSE R0 #define N_inpar3_R2 R2 N_inpar3_R2

19 Array handling -- part 1 -- M. Smith 19 of 30 Exercise 1 Stop using [P0 + 4] [P0 + 8] etc Go to auto increment mode [P0++]; #define N_inpar3_R2 R2

20 Array handling -- part 1 -- M. Smith 20 of 30 Exercise 2 – Write the assembly code to determine the location of the maximum of an array Some example tests

21 Array handling -- part 1 -- M. Smith 21 of 30 Problems to solve R0 used to pass in array address P0  R0 – therefore R0 is dead can be reused R0 reused to store temporary value when reading from memory R1 used in pass in number of points R2 used to store loop counter value R3 used to store maximum value R? used to store maximum location If use R4, R5, R6 and R7 then must learn to use “the stack” Solution 1 – use R2 as loop counter and decrement to 0 Solution 2 – store maximum location in another register (P1) and then transfer to R0 before we leave the routine Solution 3 – use hardware loop

22 Array handling -- part 1 -- M. Smith 22 of 30 Hints Write the tests for the code running in “C” ArrayMaxLocationCPP( ) Write the code first in “C++”ArrayMaxLocationCPP( ) Use the C++ code as comments in the assembly code

23 Array handling -- part 1 -- M. Smith 23 of 30 Always do a code review to make sure “code” does what you expect

24 Array handling -- part 1 -- M. Smith 24 of 30 Showing only the tests that fail ActivateTestsmain.cpp Change 1 line to show only the tests that fail | SHOW_SUCCESS; To ; // | SHOW_SUCCESSES

25 Array handling -- part 1 -- M. Smith 25 of 30 To be tackled – Array handling Move arrays – Max array (Exercise) Recap Setting up the tests Writing “enough” assembly code so you can “call the code, and return without crashing” Move one value between arrays Moving through an array – Hard coding and auto-increment addressing modes – Software loops – Hardware loops will be covered in a later lecture


Download ppt "Blackfin Array Handling Part 2 Moving an array between locations int * MoveASM( int foo[ ], int fee[ ], int N);"

Similar presentations


Ads by Google