Blackfin Array HandlingPart 2
Moving an array between locations
int * MoveASM( int foo[ ], int fee[ ] , int N);
Array handling -- part 1 -- M. Smith
2 of 30
To be tackled – Array handlingMove 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
Array handling -- part 1 -- M. Smith
3 of 30
Build the project (F7)
Array handling -- part 1 -- M. Smith
4 of 30
Add new tests
BUT WHY THE ERROR MESSAGE
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 ERRORSO YOU KNOW HOW TO FIX IN THE ASSIGNMENTS AND LABS
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
Array handling -- part 1 -- M. Smith
7 of 30
Same memory addressing error as before
INCREMENT IN 4’s with accessing int arrays
TYPOSinpar1 twice
Array handling -- part 1 -- M. Smith
8 of 30
FIXED TYPO
R2 is INPAR 3
#define N_inpar3_R2 R2
Array handling -- part 1 -- M. Smith
9 of 30
How do we pass back a parameter from “ASM” to “C++”
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 4th parameter on “stack” (like MIPS)
Return the “result of a function” using R0 as the return register
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
Array handling -- part 1 -- M. Smith
12 of 30
Tests now all pass
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
Array handling -- part 1 -- M. Smith
14 of 30
Add new tests for numpoints = 10
TEST FAILSAT THIS TIME
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
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
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
Array handling -- part 1 -- M. Smith
18 of 30
Value in R0not neededREUSE R0
Value in R0not neededREUSE R0
#define N_inpar3_R2 R2
N_inpar3_R2
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
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
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
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
Array handling -- part 1 -- M. Smith
23 of 30
Always do a code review to make sure “code” does what you expect
Array handling -- part 1 -- M. Smith
24 of 30
Showing only the tests that failActivateTestsmain.cpp
Change 1 line to showonly the tests that fail
| SHOW_SUCCESS;
To
; // | SHOW_SUCCESSES
Array handling -- part 1 -- M. Smith
25 of 30
To be tackled – Array handlingMove 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