Hints for PostLab Quiz 1 Works for other

Hints for Post-Lab Quiz 1 Works for other quizzes and exams too 1

Three types of questions Basic Knowledge Questions Translation Questions You are given the C++ and must convert into Blackfin assembly code Design questions Work out what is needed Generate the design – in C++ or in pseudo code Most often – convert design code into Blackfin assembly code 2

Knowledge type question example CORRECT OR WRONG ANSWER NO PARTIAL MARKS Sometimes more than one correct answer A) Circle and label with an A -- the icon (menu item) that causes Visual. DSP to compile the C++ code, but not build or rebuild the full project. B) Circle and label with a B -- a Blackfin instruction where a non-volatile 3 register is recovered from the stack.

The Rosetta Stone “Question” You understand columns 1 and 2 Demonstrates ability to transfer knowledge Which register is used as the 68 K return register? In this code, which register is used as the 68 K frame pointer? C++ code NEW C++ keyword extern “C” long int Return 1( ); long int Return 1( ){ return 1; } 4 Blackfin code. section program; . global _Return 1; _Return 1: LINK 16; R 0 = 1; UNLINK; RTS; 68 K code. section code; . global _Return 1; _Return 1: LINK #-16, A 4; MOVE. L #1, D 0; UNLINK A 4; RTS;

C++ to assembly Example ACCURACY IMPORTANT TRY TO MATCH ASSEMBLY CODE TO C++ ON A BOX BY BOX BASIS THEN EASIER TO GIVE PARTIAL MARKS 5 #define count_R 1 = 0;

Design question example Acts like one part of the laboratory 6

Design Question Next to impossible to mark if not well documented Therefore many marks are given for the C++ or pseudo- code comments More chance of partial marks if the register names are self documenting 7

Register documentation example ID_R 1. L = lo(CHIPID); ID_R 1. H = hi(CHIPID); CC = ID_R 1 == version_INPAR_R 0; 8 // Marker know that // R 1 used to store ID // Marker knows that // R 0 used for version // Marker also know that you know first parameter is passed in R 0 // and not on the stack – later if you make a mistake version_R 1 then still a good chance for partial (or full) mark

Avoid errors that would take a lot of time to fix in the laboratory Always check for possible return address and stack errors LINK -- at the start of a function UNLINK -- at the end of a function Always check for NAME_MANGLING Variable _fooarray; Function _Fee. Function__Fv (void) _Fee. Function__Fl (long int) _Fee. Function__NM (not sure) _Fee. Function__NM 2 (different not sure) WITH NAME MANGLING – under exam conditions, more interested in that you understand the concept than whether you are getting it exactly correct 9

Avoid pointer errors that would take a lot of time to fix in the laboratory If the memory location is shown as extern in C++ or. extern in Assembly extern long int fun. Variable; . extern _fun. Variable; 10 . section program // will accept. section code P 0. L = lo(_fun. Variable); P 0. H = hi(_fun. Variable); _fun. In. Register. R 0 = [P 0];

Avoid pointer errors that would take a lot of time to fix in the laboratory If the memory location is shown without the word EXTERN long int fun. Variable = 0; . section L 1_data 1; // will accept data, data 1. global _fun. Variable; . var _fun. Variable = 0; // Follow the C++ code fun. Variable is IN MEMORY and not yet in a register You must move the value from memory into a register. section program P 0. L = lo(_fun. Variable); P 0. H = hi( _fun. Variable); fun. In. Register. R 0 = [P 0]; 11 IS P 0. L = _fun. Variable OKAY?

Avoid pointer errors that would take a lot of time to fix in the laboratory If the memory location is known to be part of the special MEMORY LOCATIONS (MMR) used to control special operations of the Blackfin “peripherals” #include <def. BF 533. h> // will accept <defs. h> #include <macros. h> // will accept <macro. h>. section program P 0. L = lo(TCOUNT); // will accept HI( ) and LO ( ) P 0. H = hi(TCOUNT); count. In. Register. R 0 = [P 0]; 12

Know what the hi( ) and lo( ) macros do. section program P 0. L = lo(TCOUNT); P 0. H = hi(TCOUNT); MEANS P 0. L = TCOUNT & 0 x. FFFF; P 0. H = (TCOUNT & 0 x. FFFF 0000) >>16 13

HINT – #define CONSTANTS don’t use CONSTANTS #define MAXVALUE 44000 Either hex or decimal is okay. section program R 0. L = lo(MAXVALUE); R 0. H = hi(MAXVALUE); HINT: If the person is following “standard” coding conventions then CAPITIALS MEAN CONSTANT – use hi(), lo( ) 14

HINT – Will work for small constants too #define MAXVALUE 22000 Either hex or decimal is okay. section program R 0. L = lo(MAXVALUE); R 0. H = hi(MAXVALUE); BUT IN THIS CASE – since the constant is small (short int size) R 0 = MAXVALUE; Or R 0 = 6; HINT: If it looks like IT MIGHT BE a big constant, then let the assembler worry about it -- use hi( ) and lo( ) 15

Condition codes 99999 times out of 100000 the following is wrong CC = R 0 < number; e. g. CC = R 0 < 25; So play the odds R 1 = number; CC = R 0 < R 1; Will accept CC = (R 0 < R 1); under exam conditions WILL NOT ACCEPT CC = R 1 > R 0; CC conditions are always checked VERY closely as they cause so much problem in the laboratory and in “real life” 16

LOAD AND STORE OPERATIONS Rule to remember – if the operation would not work on the MIPS, then it will not work on the Blackfin or any other RISC processor register memory register R 0 = [P 1]; [P 1] = R 0; NEVER add to memory, [P 1] = [P 0] +1; add to register R 0 = R 0 + [P 0]; 17

Register operations Add a small number Make sure that you get the common instructions correct – there are not many R 0 += pretty_small_number R 0 += 6 or R 0 += -10; NOT R 0 = R 0 + 6; Pretty_small_numbers are just that – pretty small numbers -64 <= num <= +63 18

Register operations Add a larger number Make sure that you get the common instructions correct – there are not many instructions that you need to be concerned with R 1 = larger_number; R 0 = R 0 + R 1; R 1 = 0 x 2000; R 0 = R 0 + R 1; NOT R 0 += R 1; R 1 = 20000; R 0 = R 0 + R 1; R 1. L = lo(40000); R 1. H = hi(40000); R 0 = R 0 + R 1; HINT: Hexadecimal numbers are easy to work out if they are small (need 16 -bits) or very large (need 32 -bits). Decimal numbers are not – PLAY THE ODDS – if it looks large in decimal – then use lo( ), hi( ) approach 19

Other instructions we have used Make sure that you get the common instructions correct – there are not many common instructions to worry about 20 JUMP LABEL_END; // OFTEN JUMP (P 0); // typically end of function

Other instructions we have used Make sure that you get the common instructions correct – there are not many CALL _Fee. Pass. Void. Function__Fv // void Fee. Pass. Void. Function(void); NOTE: CALL _Fee. Pass. Void. Function__Fv // long int Fee. Pass. Void. Function(void); // Returns a value in R 0; 21

Other instructions we have used Make sure that you get the common instructions correct – there are not many // void Fee. Pass. Long. Int. Function(long int); CALL _Fee. Pass. Long. Int. Function__Fl (little L) CALL _Fee. Pass. Long. Int. Function__NM -- okay in exam CALL _Fee. Pass. Int. Function__Fi (little I) // void Fee. Pass. Int. Function(long int); CALL _Fee. Pass. Int. Function__NM 2 -- okay in exam 22

Other instructions we have used Make sure that you get the common instructions correct – there are not many 23 R 0 = 7; CALL _Fee. Function__Fl; // Fee. Function( 7); R 1 = 6; R 0 = 7; CALL _Fum. Function__NM; // Fum. Function(7, 6 );

Other instructions we have used �Make sure that you get the common instructions correct – there are not many � R 0 = 7; CALL _Fee. Function__Fl; // Fee. Function( 7); � R 1 = 6; R 0 = 7; CALL _Fum. Function__NM; // Fum. Function(7, 6 ); 24

When to use a register and when to use memory. extern _value; // extern long int value. section L 1_data; . global _fum_value; // long int fum_value; . var _fum_value; . section program; . global _Foo. Function__Fl; // void Foo. Function(long int passed_Fickle) { _Foo. Function__Fl: LINK 16; passed_Fickle_R 0 += 6; // passed_Fickle = passed_Fickle +6; P 0. H = hi(_value); P 0. L = lo(_value); // value = value + 6; R 1 = [P 0]; R 1 += 6; [P 0] = R 1; P 1. H = hi(_fum_value); P 1. L = lo(_fum_value); // fum_value = fum_value + 6; R 2 = [P 1]; R 2 += 6; [P 1] = R 2; ……… 25 // Rest of the function

When to use a register and when to use memory. section program; . global _Foo. Function__Fl; // void Foo. Function(long int passed_Fickle) { _Foo. Function__Fl: LINK 16; passed_Fickle_R 0 += 6; // passed_Fickle = passed_Fickle +6; #define value_R 1 // long int value_R 1 += 6; // value = value + 6; #define fum_value. R 2 fum_value_R 2 += 6; ……… 26 // long int fum_value; // fum_value = fum_value + 6; // Rest of the function

Other requested question and answers 27
- Slides: 27