300 likes | 406 Views
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”
E N D
Blackfin Array HandlingPart 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” • 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 Array handling -- part 1 -- M. Smith
The test Initialize the test array Check (some) initial values Call the assembly code routine Check (some) final values Array handling -- part 1 -- M. Smith
“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 Array handling -- part 1 -- M. Smith
Build the project (F7) Array handling -- part 1 -- M. Smith
Build the project (F7) also loads “.dxe” if successful Array handling -- part 1 -- M. Smith
Run the code “F5” Array handling -- part 1 -- M. Smith
BEST INDICATION that code “ran to completion” DISASSEMBLY WINDOW SHOWS “BLUE LINE”AT __lib_prog_term – library program terminate function Array handling -- part 1 -- M. Smith
indication that code “ran to completion” ALL expected tests ran and the assert statistics are shown Array handling -- part 1 -- M. Smith
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” beingused to check “linkage” Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith
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 ILLEGAL TO STORE A VALUEDIRECTLY TO MEMORY Double click on the errorjumps you to the errorin the “source” code Array handling -- part 1 -- M. Smith
MIPs has “general” registersBlackfin has “data” and “pointer” registers ILLEGAL TO STORE A VALUE DIRECTLY TO MEMORY Place in register, store register value 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 ILLEGAL TO USE [R0] TO ACCESS MEMORY Why not useR1 = 0; Rather than R2 = 0; Array handling -- part 1 -- M. Smith
“address” parameter passed in “data” register R0. Move R0 to “pointer” P0 ILLEGAL TO STORE A VALUE DIRECTLY TO MEMORY Place in register, store register value 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 Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith
Note that one more test has now passed E-TDD GUIdeactivatedso “click” to find error no longer works Right click toshow “line”numbers Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith
“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 Array handling -- part 1 -- M. Smith
Add new tests for 10 points NOTE COMPILER ERROR MESSAGE Fix code by tellingcompiler that thechange is not a defect Array handling -- part 1 -- M. Smith
#undef N#define N 10 – stops error messages Array handling -- part 1 -- M. Smith
As expected – code fails the new test Array handling -- part 1 -- M. Smith
REFACTOR the code to make it more readable REFACTORING does not fix errors Define the incomingparameters Array handling -- part 1 -- M. Smith
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” Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith
Attempt 1 at doing “software for-loop” Set count = 0 Check count Loop content Increment countjump to loop start BUT GET ERRORMESSAGE Array handling -- part 1 -- M. Smith
Hint at what is wrong LOOP is in blue Blue means “keyword” inBlackfinassembly Only works (turns BLUE)if using VDSP editor Array handling -- part 1 -- M. Smith
LOOP Is a keyword for the Blackfinassembly codeas the processorcan do “highlyefficient”hardware loops Array handling -- part 1 -- M. Smith
Will do “hardware loops” in another class ZERO OVER-HEAD LOOPSHARDWARE DOES count++and check for count >= N Array handling -- part 1 -- M. Smith
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 Array handling -- part 1 -- M. Smith