Blackfin Array Handling Part 2 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Blackfin Array Handling Part 2

Description:

Return the 'result of a function' using R0 as the return register ... R0 is used to pass in the address of the beginning of the 'start' array ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 26
Provided by: electr76
Category:

less

Transcript and Presenter's Notes

Title: Blackfin Array Handling Part 2


1
Blackfin Array HandlingPart 2
  • Moving an array between locations
  • int MoveASM( int foo , int fee ,
    int N)

2
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

3
Build the project
(F7)
4
Add new tests BUT WHY THE ERROR MESSAGE
5
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
  • CANT FIND THIS FUNCTION
  • RECOGNIZE THIS ERRORSO YOU KNOW HOW TO FIX IN
    THE ASSIGNMENTS AND LABS

6
Use C keywords extern C so compiler knows
ASM follows C calling convention and not C
calling convention
Expected test failures
7
TYPOSinpar1 twice
Same memory addressing error as before INCREMENT
IN 4s with accessing int arrays
8
define N_inpar3_R2 R2
FIXED TYPO R2 is INPAR 3
9
How do we pass back a parameter from ASM to
C
10
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

11
The starting address of final is still
(unchanged) in R2 copy it to return_register
define N_inpar3_R2 R2
NOTER2 typos to be fixed N_inpar3_R2 R2
12
Tests now all pass
13
This code format using index addition cant be
looped
define N_inpar3_R2 R2
Stop using P0 4P0 8 etc Go to auto
increment mode P0
14
Add new tests for numpoints 10
TEST FAILSAT THIS TIME
15
Your exercise convert to software loop format
define N_inpar3_R2 R2
Stop using P0 4P0 8 etc Go to auto
increment mode P0
16
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 CANT 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
Lets 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
define N_inpar3_R2 R2
Value in R0not neededREUSE R0
N_inpar3_R2
Value in R0not neededREUSE R0
19
Exercise 1
define N_inpar3_R2 R2
Stop using P0 4P0 8 etc Go to auto
increment mode P0
20
Exercise 2 Write the assembly code to
determine the location of the maximum of an array
Some example tests
21
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
Hints
  • Write the tests for the code running in C
    ArrayMaxLocationCPP( )
  • Write the code first in CArrayMaxLocationCPP(
    )
  • Use the C code as comments in the assembly code

23
Always do a code review to make sure code does
what you expect
24
Showing only the tests that fail
ActivateTestsmain.cpp Change 1 line to showonly
the tests that fail SHOW_SUCCESS To //
SHOW_SUCCESSES
25
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
Write a Comment
User Comments (0)
About PowerShow.com