Blackfin Array Handling Part 2 Moving an array
Blackfin Array Handling Part 2 Moving an array between locations int * Move. ASM( int foo[ ], int fee[ ] , int N);
To be tackled – Array handling Move arrays – Max array (Exercise) l Recap l 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 l l l – – 2 of 30 – Hard coding and auto-increment addressing modes Software loops Hardware loops will be covered in a later lecture Array handling -- part 1 -- M. Smith
Build the project (F 7) 3 of 30 Array handling -- part 1 -- M. Smith
Add new tests BUT WHY THE ERROR MESSAGE 4 of 30 Array handling -- part 1 -- M. Smith
“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” 5 of 30 RECOGNIZE THIS ERROR SO YOU KNOW HOW TO FIX IN THE ASSIGNMENTS AND LABS Array handling -- part 1 -- M. Smith
Use C++ keywords ‘extern “C” ‘ so compiler knows ASM follows C calling convention and not C++ calling convention Expected test failures 6 of 30 Array handling -- part 1 -- M. Smith
TYPOS inpar 1 twice Same memory addressing error as before 7 of 30 INCREMENT IN 4’s with accessing int Array handling -- part 1 arrays -- M. Smith
#define N_inpar 3_R 2 FIXED TYPO R 2 is INPAR 3 8 of 30 Array handling -- part 1 -- M. Smith
How do we pass back a parameter from “ASM” to “C++” 9 of 30 Array handling -- part 1 -- M. Smith
Parameter passing convention l l l 10 of 30 Pass first parameter “into” function using R 0 (same for data or addresses) Pass second parameter using R 1 Pass third parameter using R 2 Pass 4 th parameter on “stack” (like MIPS) Return the “result of a function” using R 0 as the return register Array handling -- part 1 -- M. Smith
The starting address of “final[ ]” is still (unchanged) in R 2 – copy it to “return_register” #define N_inpar 3_R 2 NOTE R 2 typos to be fixed N_inpar 3_R 2 11 of 30 Array handling -- part 1 -- M. Smith
Tests now all pass 12 of 30 Array handling -- part 1 -- M. Smith
This code format using “index” addition can’t be looped #define N_inpar 3_R 2 Stop using [P 0 + 4] [P 0 + 8] etc 13 of 30 Go to auto increment mode [P 0++]; Array handling -- part 1 -- M. Smith
Add new tests for numpoints = 10 TEST FAILS AT THIS TIME 14 of 30 Array handling -- part 1 -- M. Smith
Your exercise – convert to software loop format #define N_inpar 3_R 2 Stop using [P 0 + 4] [P 0 + 8] etc 15 of 30 Go to auto increment mode [P 0++]; Array handling -- part 1 -- M. Smith
Problem to solve l l l 16 of 30 R 0 – used for source in-parameter R 1 – used for final in-parameter R 2 – used for “N points” in-paramater R 3 – used for “temp” when reading and writing memory YOU CAN’T USE R 4, R 5, R 6, R 7 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 Array handling -- part 1 -- M. Smith
Let’s rewrite the code l l 17 of 30 R 0 is used to pass in the address of the beginning of the “start” array R 0 is transferred to P 0 so we can access memory The value in R 0 is not needed again in this function Rather than learning to save things to the stack – lets re-use R 0 Array handling -- part 1 -- M. Smith
#define N_inpar 3_R 2 Value in R 0 not needed REUSE R 0 N_inpar 3_R 2 18 of 30 Value in R 0 not needed REUSE R 0 Array handling -- part 1 -- M. Smith
Exercise 1 #define N_inpar 3_R 2 Stop using [P 0 + 4] [P 0 + 8] etc 19 of 30 Go to auto increment mode [P 0++]; Array handling -- part 1 -- M. Smith
Exercise 2 – Write the assembly code to determine the location of the maximum of an array Some example tests 20 of 30 Array handling -- part 1 -- M. Smith
Problems to solve l l l l l 21 of 30 l R 0 used to pass in array address P 0 R 0 – therefore R 0 is dead can be reused R 0 reused to store temporary value when reading from memory R 1 used in pass in number of points R 2 used to store loop counter value R 3 used to store maximum value R? used to store maximum location If use R 4, R 5, R 6 and R 7 then must learn to use “the stack” Solution 1 – use R 2 as loop counter and decrement to 0 Solution 2 – store maximum location in another register (P 1) and then transfer to R 0 before we leave the routine Solution 3 – use hardware loop Array handling -- part 1 -- M. Smith
Hints l l l 22 of 30 Write the tests for the code running in “C” Array. Max. Location. CPP( ) Write the code first in “C++”Array. Max. Location. CPP( ) Use the C++ code as comments in the assembly code Array handling -- part 1 -- M. Smith
Always do a code review to make sure “code” does what you expect 23 of 30 Array handling -- part 1 -- M. Smith
Showing only the tests that fail Activate. Testsmain. cpp Change 1 line to show only the tests that fail | SHOW_SUCCESS; To ; // | SHOW_SUCCESSES 24 of 30 Array handling -- part 1 -- M. Smith
To be tackled – Array handling Move arrays – Max array (Exercise) l Recap l 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 l l l – – 25 of 30 – Hard coding and auto-increment addressing modes Software loops Hardware loops will be covered in a later lecture Array handling -- part 1 -- M. Smith
- Slides: 25