blackfin array handling part 1

30
Blackfin Array Handling Part 1 Making an array of Zeros void MakeZeroASM(int foo[ ], int N);

Upload: wade-hooper

Post on 03-Jan-2016

36 views

Category:

Documents


5 download

DESCRIPTION

Blackfin Array Handling Part 1. Making an array of Zeros void MakeZeroASM(int foo[ ], int N);. To be tackled – Array handling. Setting test environment – part of Lab.0 Setting up the tests Writing “enough” assembly code so you can “call the code, and return without crashing” - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Blackfin Array Handling Part 1

Blackfin Array HandlingPart 1

Making an array of Zeros void MakeZeroASM(int foo[ ], int N);

Page 2: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

2 of 30

To be tackled – Array handling

Setting test environment – part of Lab.0

Setting up the tests Writing “enough” assembly code so you can “call the

code, and return without crashing” Setting one value in an array Moving through an array

– Hard coding and auto-increment addressing modes– Software loops– Hardware loops will be covered in a later lecture

Page 3: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

3 of 30

The test

Initialize the test array

Check (some) initial values

Call the assembly code routine

Check (some) final values

Page 4: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

4 of 30

“Just enough code” to safely return after call

Tell “linker” which “section” is needed to place the code – program memory section NOT data

Tell “linker” that this is available for all to use (global and not private function)

Start label – need colon :

End label with RTS statementRTS = ReTurn from Subroutine

Page 5: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

5 of 30

Build the project (F7)

Page 6: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

6 of 30

Build the project (F7) also loads “.dxe” if successful

Page 7: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

7 of 30

Run the code “F5”

Page 8: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

8 of 30

BEST INDICATION that code “ran to completion”

DISASSEMBLY WINDOW SHOWS “BLUE LINE”AT __lib_prog_term – library program terminate function

Page 9: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

9 of 30

indication that code “ran to completion”

ALL expected tests ran and the assert statistics are shown

Page 10: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

10 of 30

IF E-TDD GUI is active then “double click” on the error takes you to the test

We “expect” the test to failas we only have “stub” being

used to check “linkage”

Page 11: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

11 of 30

Set first value in array to 0Will pass the first test if correctly done

Blackfin is like MIPS, passes parameters into functions using registers and the stack

R0 – first parameter R1 – second parameter R2 – third parameter Fourth parameter passed on the stack

Page 12: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

12 of 30

Like MIPs, Blackfin has “load” and “store” architecture

Blackfin is like MIPS – it has load and store architecture

This means you can’t put values directly into memory You must load value into a register and then store register to memory

Double click on the errorjumps you to the errorin the “source” code

ILLEGAL TO STORE A VALUEDIRECTLY TO MEMORY

Page 13: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

13 of 30

MIPs has “general” registersBlackfin has “data” and “pointer” registers

Blackfin (like Motorola 68K) has “data” and “pointer” registers

“data” registers store data values “pointer” registers store addresses and can be used to access memory

Why not useR1 = 0;

Rather than R2 = 0;

ILLEGAL TO STORE A VALUE DIRECTLY TO MEMORYPlace in register, store register value

ILLEGAL TO USE [R0] TO ACCESS MEMORY

Page 14: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

14 of 30

“address” parameter passed in “data” register R0. Move R0 to “pointer” P0

Blackfin (like Motorola 68K) has “data” and “pointer” registers

P0 = R0; transfer “parameter” (R0) into a pointer register (P0) [P0] = R2; Use “pointer” register to access memory

ILLEGAL TO STORE A VALUE DIRECTLY TO MEMORYPlace in register, store register value

Page 15: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

15 of 30

Assembler “warns” you about inefficiencies in your code -- WAIL

You set P0 and then immediately use P0 This causes the processor “instruction

pipeline” to stall

Page 16: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

16 of 30

Note that one more test has now passed

E-TDD GUIdeactivated

so “click” to find error no longer works

Right click toshow “line”numbers

Page 17: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

17 of 30

Make first 5 values of array = 0 through “hard-coding” (straight line coding)

Weird error messages

[P0 + 0] and [P0 + 4]are legal

[P0 + 1], [P0 + 2], [P0 + 3]are illegal

Reason – we are using“ints” – 32-bit values

4 bytes for each memory location

Page 18: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

18 of 30

Increment pointer register by 4 when accessing “int” arrays

Get correct result when increment by 4

Avoid this common addressing error by allowing the processor to do the calculation

Page 19: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

19 of 30

“AUTO”Increment pointer register by 4 when accessing “int” arrays

Get correct result when increment by 4

Avoid this common addressing error by allowing the processor to do the calculation

Page 20: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

20 of 30

Add new tests for

10 points

NOTE

COMPILER

ERROR MESSAGE

Fix code by tellingcompiler that thechange is not a defect

Page 21: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

21 of 30

#undef N#define N 10 – stops error messages

Page 22: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

22 of 30

As expected – code fails the new test

Page 23: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

23 of 30

REFACTOR the code to make it more readable REFACTORING does not fix errors

Define the incomingparameters

Page 24: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

24 of 30

REFACTOR the code to make it more readable REFACTORING does not fix errors

Define the local variables

called “registering” the variables

An “optimization” as “C++” would place these on the “local stack”

Page 25: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

25 of 30

REFACTOR the code to make it more readable REFACTORING does not fix errors

This FORMATTING is this “course” REQUIREDconvention for coding as makes it easier to understand by you, TA’s and me

Page 26: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

26 of 30

Attempt 1 at doing “software for-loop”

Set count = 0

Check count

Loop content

Increment countjump to loop start

BUT GET ERRORMESSAGE

Page 27: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

27 of 30

Hint at what is wrong

LOOP is in blue

Blue means “keyword” inBlackfinassembly

Only works (turns BLUE)if using VDSP editor

Page 28: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

28 of 30

LOOPIs a keyword for the Blackfinassembly codeas the processorcan do “highlyefficient”hardware loops

Page 29: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

29 of 30

Will do “hardware loops” in another class

ZERO OVER-HEAD LOOPSHARDWARE DOES count++and check for count >= N

Page 30: Blackfin Array Handling Part 1

Array handling -- part 1 -- M. Smith

30 of 30

Tackled – Basic Array handling

Setting test environment – part of Lab.0

Setting up the tests Writing “enough” assembly code so you can “call the

code, and return without crashing” Setting one value in an array Moving through an array

– Hard coding and auto-increment addressing modes– Software loops– Hardware loops will be covered in a later lecture