Blackfin Syntax Stores, Jumps, Calls and Conditional Jumps What we already know and have to remember to apply What we need to learn
Assembly code “stub” Each function written in assembly code has the same general look The necessary #include files and Section name Declaration of the function as “global” combined with labels for start and end of function Setting size of link operation and using LINK instruction to save the return address Unlink used with JUMP(P0) instruction to cause the function to return “to calling program” R0 used for return parameter Required code with Documentation of code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Example 1 -- stub code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Example 2 – Stub code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Store/Write code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Store/write error messages 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Load/read 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Jump 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
If CC jump If !CC jump 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Jump predicted taken (bp) IF CC JUMP WHILE [--SP] = (R7:0); // Save to stack WHILE: R0 = R1; R2 = R3; CC = R1 < R4; IF CC JUMP WHILE; R6 = R7; R5 = R4; IF CC JUMP WHILE [--SP] = (R7:0); // Save to stack WHILE: R0 = R1; R2 = R3; CC = R1 < R4; IF CC JUMP WHILE (BP); R6 = R7; R5 = R4; 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Processor fetches instructionS before execution 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
UP to 10 instructions being executed in paraller Processor fetches 9 new instructions before execution of 1st instruction is complete UP to 10 instructions being executed in paraller 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Jump predicted taken (bp) IF CC JUMP WHILE [--SP] = (R7:0); // Save to stack WHILE: R0 = R1; R2 = R3; CC = R1 < R4; IF CC JUMP WHILE; R6 = R7; R5 = R4; IF CC JUMP WHILE [--SP] = (R7:0); // Save to stack WHILE: R0 = R1; R2 = R3; CC = R1 < R4; IF CC JUMP WHILE (bp); R6 = R7; R5 = R4; 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Jump example code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Call instruction 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
void ExampleASM(void) { C++ code void ExampleASM(void) { ConvertTempASM(100,200,1); // declared as extern “C” } Assembly code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
void Example2ASM(void) { C++ code void Example2ASM(void) { CalculateTemperature(100,200,1); // C++ function } Assembly code 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Move Register 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Conditional move register 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Practice Exercise Translate in Blackfin Assembly Code extern “C” unsigned long int WaitTillLow(void); extern “C” unsigned long int WaitTillHigh(void); unsigned short int MeasureTimeHigh_ASM(void) { unsigned long int value; WaitTillLow( ); WaitTillHigh( ); value = WaitTillLow( ); return value; } 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Practice Exercise 2 Translate in Blackfin Assembly Code extern “C” unsigned long int WaitTillLow(void); extern “C” unsigned long int WaitTillHigh(void); unsigned long int MeasureTimeHigh_ASM(void) { unsigned long int value1, value2; WaitTillLow( ); WaitTillHigh( ); value1 = WaitTillLow( ); value2 = WaitTillLow( ); return (value1 + value2); } 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada
Practice Exercise 3 Translate in Blackfin Assembly Code extern “C” unsigned long int WaitTillLow(void); extern “C” unsigned long int WaitTillHigh(void); extern unsigned long int value1; extern unsigned long int value2; unsigned long int MeasureTimeHigh_ASM(void) { WaitTillLow( ); WaitTillHigh( ); value1 = WaitTillLow( ); value2 = WaitTillLow( ); return (value1 + value2); } 8/5/2019 Timer Control -- Lab.3, Copyright M. Smith, ECE, University of Calgary, Canada