1 / 27

Hints for Post-Lab Quiz 1

This post provides hints and tips for the post-lab quiz, covering three types of questions (basic knowledge, translation, and design) and design tips for converting C++ code into Blackfin assembly code. Learn key concepts and strategies to improve your quiz performance.

noahc
Download Presentation

Hints for Post-Lab Quiz 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. Knowledge type question example CORRECTOR WRONGANSWERNO PARTIAL MARKS Sometimes more than one correct answer • Circle and label with an A -- the icon (menu item) that causes VisualDSP 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 register is recovered from the stack.

  4. The Rosetta Stone “Question”You understand columns 1 and 2 Demonstrates ability to transfer knowledgeWhich register is used as the 68K return register?In this code, which register is used as the 68K frame pointer?

  5. C++ to assembly Example ACCURACYIMPORTANT #define count_R1 R1count_R1 = 0; TRY TO MATCH ASSEMBLY CODE TO C++ ON A BOX BY BOX BASIS THEN EASIER TO GIVEPARTIAL MARKS

  6. Design question exampleActs like one part of the laboratory

  7. 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

  8. Register documentation example ID_R1.L = lo(CHIPID); // Marker know thatID_R1.H = hi(CHIPID); // R1 used to store ID CC = ID_R1 == version_INPAR_R0; // Marker knows that // R0 used for version// Marker also know that you know first parameter is passed in R0 // and not on the stack – later if you make a mistake version_R1then still a good chance for partial (or full) mark

  9. 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 _FeeFunction__Fv (void) _FeeFunction__Fl (long int) _FeeFunction__NM (not sure) _FeeFunction__NM2 (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 We are using extern “C” to this point in the class. We will get to “function overloading” and “name_mangling” at a latter date

  10. 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 funVariable; .extern _funVariable; .section program // will accept .section code P0.L = lo(_funVariable);P0.H = hi(_funVariable); _funInRegisterR0 = [P0];

  11. 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 funVariable = 0; .section L1_data1; // will accept data, data1 .global _funVariable; .var _funVariable = 0; // Follow the C++ code funVariable is IN MEMORY and not yet in a register You must move the value from memory into a register .section program P0.L = lo(_funVariable); IS P0.L = _funVariable P0.H = hi( _funVariable); OKAY?funInRegisterR0 = [P0];

  12. 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 <blackfin.h> .section program; // Will note accept missing sections P0.L = lo(TCOUNT); // will accept HI( ) and LO ( )P0.H = hi(TCOUNT);countInRegisterR0 = [P0];

  13. Know what the hi( ) and lo( ) macros do .section program P0.L = lo(TCOUNT); P0.H = hi(TCOUNT); MEANS P0.L = TCOUNT & 0xFFFF; P0.H = (TCOUNT & 0xFFFF0000) >>16

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

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

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

  17. 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 R0 = [P1];memory  register [P1] = R0; NEVER add to memory, [P1] = [P0] +1; add to register R0 = R0 + [P0];

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

  19. Register operationsAdd a larger number • Make sure that you get the common instructions correct – there are not many instructions that you need to be concerned with R1 = larger_number; R0 = R0 + R1; R1 = 0x2000; R0 = R0 + R1; NOT R0 += R1;R1 = 20000; R0 = R0 + R1; R1.L = lo(40000); R1.H = hi(40000); R0 = R0 + R1; 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

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

  21. Other instructions we have used • Make sure that you get the common instructions correct – there are not many • CALL _FeePassVoidFunction__Fv // void FeePassVoidFunction(void); NOTE: CALL _FeePassVoidFunction__Fv // long int FeePassVoidFunction(void); // Returns a value in R0; • extern “C” _FeePassVoidFunction – used in this class CALL _FeePassVoidFunction

  22. Other instructions we have used • Make sure that you get the common instructions correct – there are not many // void FeePassLongIntFunction(long int); • CALL _FeePassLongIntFunction__Fl (little L) CALL _FeePassLongIntFunction__NM -- okay in exam • CALL _FeePassIntFunction__Fi (little I) // void FeePassIntFunction(long int); CALL _FeePassIntFunction__NM2 -- okay in exam

  23. Other instructions we have used • Make sure that you get the common instructions correct – there are not many • R0 = 7; CALL _FeeFunction__Fl; // FeeFunction( 7); • R1 = 6; R0 = 7; CALL _FumFunction__NM; // FumFunction(7, 6 );

  24. Make sure that you get the common instructions correct – there are not many R0 = 7; CALL _FeeFunction__Fl; // FeeFunction( 7); R1 = 6; R0 = 7; CALL _FumFunction__NM; // FumFunction(7, 6 ); Other instructions we have used

  25. When to use a register andwhen to use memory .extern _value; // extern long int value.section L1_data; .global _fum_value; // long intfum_value; .var _fum_value; .section program; .global _FooFunction__Fl; // void FooFunction(long intpassed_Fickle) { _FooFunction__Fl: LINK 16; passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6;P0.H = hi(_value); P0.L = lo(_value); // value = value + 6; R1 = [P0]; R1 += 6; [P0] = R1; P1.H = hi(_fum_value); P1.L = lo(_fum_value); // fum_value = fum_value + 6; R2 = [P1]; R2 += 6; [P1] = R2; ……… // Rest of the function

  26. When to use a register andwhen to use memory .section program; .global _FooFunction__Fl; // void FooFunction(long int passed_Fickle) { _FooFunction__Fl: LINK 16; passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6;#define value_R1 R1 // long int value value_R1 += 6; // value = value + 6; #define fum_valueR2 R2 // long int fum_value; fum_value_R2 += 6; // fum_value = fum_value + 6; ……… // Rest of the function

  27. Other requested question and answers

More Related