Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V.

Similar presentations


Presentation on theme: "Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V."— Presentation transcript:

1 Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V

2 2 /24 Useful items listed as useful for Assignment 1 Links from ENCM415 September web page  Example Blackfin assembly code file examplecode.asm – had many assignment answers examplecode.asm  Blackfin assembly language quick reference sheet  BF533 Blackfin Hardware Reference  BF533 Blackfin Programming Reference

3 3 /24 Write the Blackfin assembly language instruction(s) to load the address of the internal timer count register into pointer register P1 For details of TIMER COUNTER register -- see index of hardware manual 15-9 Or look in the example assembly language file for answer #include P1.L = lo (TIMER0_COUNTER); P1.H = hi (TIMER0_COUNTER); #include P1.L = lo (TCOUNT); P1.H = hi (TCOUNT); The important thing to remember Just like the MIPS processor – must load 32-bit address in two 16-bit sections Special Blackfin – if using a special register built into (internal to) the Blackfin then these address MUST be loaded using the MACROS hi( ) and lo( ) -- These are defined in the file

4 4 /24 Write the Blackfin assembly language instruction(s) to load the address of the internal timer count register into pointer register P5. Why does this require a different answer to Q2E? #include P1.L = lo (TIMER0_COUNTER); P1.H = hi (TIMER0_COUNTER); [--SP] = P5; P5.L = lo (TIMER0_COUNT); P5.H = hi (TIMER0_COUNT); #include P1.L = lo (TCOUNT); P1.H = hi (TCOUNT); [--SP] = P5; P5.L = lo (TCOUNT); P5.H = hi (TCOUNT); The important thing to remember Just like the MIPS processor – some of the Blackfin registers must be saved on the stack if you plan to use them in a subroutine (non-volatile or compiler- preserved)

5 5 /24 Registers used to control PF pins Flag Data register (FIO_FLAG_D)  Used to read the PF bits (1 or 0)  Need to read pins PF11 to PF8, ignore all other pins values

6 6 /24 #include.global _ReadProgrammableFlags__Fv; _ReadProgrammableFlags__Fv LINK 16; P1.L = lo (FIO_FLAG_D); // could be P0 P1.H = hi (FIO_FLAG_D); R0 = W[P1] (Z); P0 = [FP + 4]; UNLINK; _ReadProgrammableFlags__Fv; JUMP (P0); Must use W [ ] since the manual shows that FIO_FLAG_D register is 16-bits Must use W[P1] (Z) zero-extend as this adds 16 zeros to the 16 bits from FIO_FLAG_D register to make 32-bits to place into R0 int ReadProgrammableFlags( )

7 7 /24 #include.global _ReadProgrammableFlags__Fv; _ReadProgrammableFlags__Fv LINK 16; P1.L = lo (FIO_FLAG_D); // could be P0 P1.H = hi (FIO_FLAG_D); R0.L = W[P1]; R0.H = 0; P0 = [FP + 4]; UNLINK; _ReadProgrammableFlags__Fv; JUMP (P0); FIO_FLAG_D register is 16-bits Here we use a more direct method of filling R0 with the correct values Load (read) the bottom 16 bits of R0 (R0.L) Put zeros into the top 16 bits of R0 (R0.H) int ReadProgrammableFlags( )

8 8 /24 Why do you need to know how to do read (load) and write (store) on internal registers? Flag Direction register (FIO_DIR)  Used to determine if the PF bit is to be used for input or output -- WARNING SMOKE POSSIBLE ISSUE  Need to set pins PF11 to PF8 for input, leave all other pins unchanged

9 9 /24 Registers used to control PF pins Flag Input Enable Register  Only activate the pins you want to use (saves power in telecommunications situation)  Need to activate pins PF11 to PF8 for input, leave all other pins unchanged

10 10 /24 Registers used to control PF pins Flag Polarity Register (FIO_POLAR)  Set pins PF11 to PF8 for active HIGH, leave all other pins unchanged

11 11 /24 Array handling // int SimpleSum(void) { // int InsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // static int InsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // InsideRoutine_FOOarray[0] = 6; // InsideRoutine_FARarray[0] = 6; // ……… Just as in MIPS InsideRoutine_FOOarray[ ] is placed “on the stack”. This array vanishes each time the subroutine SimpleSum( ) exits and gets rebuilt each time the subroutine starts again – C++ has code to reset InsideRoutine_FOOarray[0] = 1 at the start of the function static int InsideRoutine_Fararray[10] – This use of the C++ word STATIC means that array DOES NOT VANISH each time the subroutine SimpleSum( ) exits. Next time you call the subroutine, the values stored in the array InsideRoutine_Fararray[10] are still there looking the same as when the subroutine exitted. InsideRoutine_FARarray[0] = 6;

12 12 /24 Array handling // int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // int SimpleSum(void) { // OutsideRoutine_FOOarray[0] = 6; // OutsideRoutine_FARarray[0] = 6; // ……… Just as in MIPS OutsideRoutine_FOOarray[ ] is NOT placed “on the stack”. This array DOES NOT vanish each time the subroutine SimpleSum( ) exits and gets DOES NOT GET rebuilt each time the subroutine starts again – OutsideRoutine_FOOarray[0] = 6 static int OUTSIDERoutine_Fararray[10] – This use of the C++ word STATIC means that array CAN NOT BE ACCESSED BY ANY FUNCTION THAT IS NOT IN THE SAME FILE AS OUTSIDERoutine_Fararray. NOT ON THE STACK -- DOES NOT VANISH each time the subroutine SimpleSum( ) exits.

13 13 /24 Array handling // int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // int ExampleFum(void) { // OutsideRoutine_FOOarray[0] = 6; // OutsideRoutine_FARarray[0] = 6;.section L1_data;.global _OutsideRoutine_FOOarray; // Can be seen outside this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // There is no global statement – Can’t be seen outside of this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};.section program; _ExampleFum__Fv:

14 14 /24 Array handling // int OutsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // static int OutsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // int ExampleFum (void) { // OutsideRoutine_FOOarray[0] = 6; // OutsideRoutine_FARarray[0] = 6;.section L1_data;.global _OutsideRoutine_FOOarray; // Can be seen outside this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // There is no global statement – Can’t be seen outside of this file.var _OutsideRoutine_FOOarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};.section program; _ExampleFum__Fv: P0.L = _OutsideRoutine_FOOarray; P0.H = _OutsideRoutine_FOOarray; R0 = 6; [P0] = R0; P0.L = _OutsideRoutine_FARarray; P0.H = _OutsideRoutine_FARarray; R0 = 6; [P0] = R0;

15 15 /24 Array handling // int ExampleFum (void) { // int InsideRoutine_FOOarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // static int InsideRoutine_FARarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // InsideRoutine_FOOarray[0] = 6; // InsideRoutine_FARarray[0] = 6;.section L1_data; // STATIC ARRAYS CAN’T BE ON THE STACK.var _InsideRoutine_FARarray[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};.section program; _ExampleFum__Fv; LINK 16 + (10 * 4); // Make room on the stack – SP points to start of // _InsideRoutine_FOOarray[ ] P0 = SP; // Now must rebuild InsideRoutine_FOOarray[ ] R0 = 1; [P0++] = R0; R0 = 2; [P0++] = R0; …………. P0 = SP; // Now point to the start of the array again THIS IS JUST LIKE THE OPERATIONS ON THE MIPS

16 16 /24 Back to assignment ideas // Prototype int SimpleSum(void); int SimpleSum(void) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < 5; count++) { sum2 += Fooarray[count]; } return (sum2); } Problem with this code – only works with ONE array

17 17 /24 Better version of the simple sum // Prototype int SimpleSum(int passedFooarray[ ], int Numpts); int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } Now we have passed in “a copy” of the start of the array passedFooarray Together with “a copy” of the size of the array Numpts

18 18 /24 Different version of the simple sum Version 2 // Prototype int SimpleSum(int *passedFooarray, int Numpts); int SimpleSum(int *passedFooarray, int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } Does exactly the same thing

19 19 /24 Better version of the simple sum Version 3 // Prototype int SimpleSum(int *passedFooarray, int Numpts); int SimpleSum(int *passedFooarray, int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += *passedFooarray++; } return (sum2); } Does exactly the same thing The compiler in “DEBUG” mode will code this for highest speed The compiler in “RELEASE” (optimizing, intelligent) mode will recognize that all the versions are the same thing – and code for this version

20 20 /24 What do we need to know? If this was MIPS then the parameters of the subroutine int SimpleSum(int *passedFooarray, int Numpts); would be passed in which registers? a0 contains the value of the address int *passedFooarray a1 contains the value of the number int Numpts Since this is a Blackfin then the parameters of the subroutine int SimpleSum(int *passedFooarray, int Numpts); would be passed as R0 contains the value of the address int *passedFooarray R1 contains the value of the number int Numpts

21 21 /24 Translate the easy bits first int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } R0 contains value of the address int * passedFooarray R1 contains value of the number int Numpts.section program;.global _SimpleSum_FPii; _SimpleSum_FPii: LINK 16; #define sum2_R2 R2 sum2_R2 = 0; // Can’t be R0 or R1 R0 = sum_R2; P0 = [FP + 4]; UNLINK; _SimpleSum_FPii.END: JUMP (P0);

22 22 /24 Now get the “start address of the array” (R0) and “the number of points in the array” (R1) int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } R0 contains value of the address int * passedFooarray R0 can’t be used to access an array MUST BE MOVED INTO POINTER.section program;.global _SimpleSum_FPii; _SimpleSum_FPii: LINK 16; #define sum2_R2 R2 sum2_R2 = 0; #define start_FOOarray_P0 P0 start_FOOarray_P0 = R0; // since Numpts is already in R1 // leave it there #define Numpts_R1 R1 ; R0 = sum2_R2; P0 = [FP + 4]; UNLINK; _SimpleSum_FPii.END: JUMP (P0);

23 23 /24 Solution for “while loop” form int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } R0 started of containing value of the address int * passedFooarray which was then destroyed when no longer needed R1 contains value of the number int Numpts #define sum2_R2 R2 sum2_R2 = 0; #define start_FOOarray_P0 P0 start_FOOarray_P0 = R0; // since Numpts is already in R1 // leave it there #define Numpts_R1 R1 #define count_R3 R3 WHILE: CC = Numpts_R1 <= count_R3; IF CC JUMP END_WHILE; R0 = [start_FOOarray_P0++]; sum2_R2 = sum2_R2 + R0; count_R3 += 1; JUMP WHILE; END_WHILE: R0 = sum2_R2;

24 24 /24 Now set up the “zero-overhead” loop int SimpleSum(int passedFooarray[ ], int Numpts) { // Demonstrate “zero-over head” loops int sum2 = 0; for (count = 0; count < Numpts; count++) { sum2 += passedFooarray[count]; } return (sum2); } WARNING loop_end is ILLEGAL as a label _SimpleSum_FPii: LINK 16; #define sum2_R2 R2 sum2_R2 = 0; #define start_FOOarray_P0 P0 start_FOOarray_P0 = R0; // since Numpts is already in R1 // leave it there #define Numpts_R1 R1 LC0 = Numpts_R1; LSETUP(loop_start, loop_finish) LC0; loop_start: R0 = [start_FOOarray_P0++]; loop_finish; sum2_R2 = sum2_R2 + R0; R0 = sum2_R2; ASSEMBLER ACCEPTS BUT ISSUES WARNING ABOUT PROCESSOR PIPELINE INEFFICIENCY


Download ppt "Assignment Overview Thermal oscillator One of the ENCM415 Laboratory 2 items Oscillator out GND +5V."

Similar presentations


Ads by Google