1 hints for post-lab quiz 1 works for other quizzes and exams too

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

Post on 20-Dec-2015

226 views

Category:

Documents


2 download

TRANSCRIPT

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

1

Hints for Post-Lab Quiz 1Hints for Post-Lab Quiz 1

Works for other quizzes and Works for other quizzes and exams tooexams too

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

22

Three types of questionsThree types of questions Basic Knowledge QuestionsBasic Knowledge Questions

Translation QuestionsTranslation Questions• You are given the C++ and must convert into You are given the C++ and must convert into

Blackfin assembly codeBlackfin assembly code

Design questionsDesign questions• Work out what is neededWork out what is needed• Generate the design – in C++ or in pseudo Generate the design – in C++ or in pseudo

codecode• Most often – convert design code into Most often – convert design code into

Blackfin assembly codeBlackfin assembly code

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

33

Knowledge type question exampleKnowledge type question example

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

CORRECTOR WRONGANSWERNO PARTIAL MARKS

Sometimes more than one correct answer

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

44

The Rosetta Stone “Question”The Rosetta Stone “Question”You understand columns 1 and 2You understand columns 1 and 2

C++ codeC++ code

NEW C++ keywordNEW C++ keyword

extern “C” long int extern “C” long int Return1( ); Return1( );

long int Return1( ){long int Return1( ){ return 1; return 1;

}}

Blackfin codeBlackfin code

.section program;.section program; .global _Return1; .global _Return1;

_Return1:_Return1: LINK 16; LINK 16;

R0 = 1;R0 = 1;

UNLINK;UNLINK; RTS; RTS;

68K code68K code

.section code;.section code; .global _Return1; .global _Return1;

_Return1:_Return1: LINK #-16, A4; LINK #-16, A4;

MOVE.L #1, D0;MOVE.L #1, D0;

UNLINK A4;UNLINK A4; RTS; RTS;

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?

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

55

C++ to assembly ExampleC++ to assembly Example

ACCURACYIMPORTANT

TRY TO MATCH ASSEMBLY CODE TO C++ ON A BOX BY BOX BASIS

THEN EASIER TO GIVEPARTIAL MARKS

#define count_R1 R1count_R1 = 0;

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

66

Design question exampleDesign question exampleActs like one part of the laboratoryActs like one part of the laboratory

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

77

Design QuestionDesign Question

Next to impossible to mark if not well Next to impossible to mark if not well documenteddocumented• Therefore many marks are given for the Therefore many marks are given for the

C++ or pseudo-code commentsC++ or pseudo-code comments

More chance of partial marks if the More chance of partial marks if the register names are self documentingregister names are self documenting

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

88

Register documentation exampleRegister 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

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

99

Avoid errors that would take a lot of Avoid errors that would take a lot of time to fix in the laboratorytime to fix in the laboratory

Always check for possible return address and stack Always check for possible return address and stack errorserrors• LINK -- at the start of a functionLINK -- at the start of a function• UNLINK -- at the end of a functionUNLINK -- at the end of a function

Always check for NAME_MANGLINGAlways check for NAME_MANGLING• Variable _fooarray;Variable _fooarray;• Function _FeeFunction__Fv (void)Function _FeeFunction__Fv (void) _FeeFunction__Fl (long int)_FeeFunction__Fl (long int)

_FeeFunction__NM (not sure) _FeeFunction__NM (not sure) _FeeFunction__NM2 (different not sure) _FeeFunction__NM2 (different not sure)

WITH NAME MANGLING – under exam conditions, more WITH NAME MANGLING – under exam conditions, more interested in that you understand the concept than interested in that you understand the concept than whether you are getting it exactly correctwhether you are getting it exactly correct

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

1010

Avoid pointer errors that would take Avoid pointer errors that would take a lot of time to fix in the laboratorya lot of time to fix in the laboratory

If the memory location is shown as If the memory location is shown as extern in C++ or .extern in Assemblyextern in C++ or .extern in Assembly

extern long int funVariable;extern long int funVariable;

.extern _funVariable;.extern _funVariable;

.section program .section program // will accept code// will accept code

P0.L = lo(_funVariable);P0.L = lo(_funVariable);P0.H = hi(_funVariable);P0.H = hi(_funVariable);

_funInRegisterR0 = [P0];_funInRegisterR0 = [P0];

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

1111

Avoid pointer errors that would take Avoid pointer errors that would take a lot of time to fix in the laboratorya lot of time to fix in the laboratory

If the memory location is shown without the word EXTERNIf the memory location is shown without the word EXTERN long int funVariable = 0;long int funVariable = 0;

.section L1_data1; // will accept data, data.section L1_data1; // will accept data, data .global _funVariable;.global _funVariable; .var _funVariable = 0; // Follow the C++.var _funVariable = 0; // Follow the C++

funVariable is IN MEMORY and not yet in a register funVariable is IN MEMORY and not yet in a register You must move the value from memory into a registerYou must move the value from memory into a register

.section program.section program P0.L = lo(_funVariable); IS P0.L = _funVariableP0.L = lo(_funVariable); IS P0.L = _funVariable P0.H = hi( _funVariable); OKAY?P0.H = hi( _funVariable); OKAY?

funInRegisterR0 = [P0];funInRegisterR0 = [P0];

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

1212

Avoid pointer errors that would take Avoid pointer errors that would take a lot of time to fix in the laboratorya lot of time to fix in the laboratory

If the memory location is known to be part of the If the memory location is known to be part of the special MEMORY LOCATIONS (MMR) used to control special MEMORY LOCATIONS (MMR) used to control special operations of the Blackfin “peripherals”special operations of the Blackfin “peripherals”

#include <defBF533.h> // will accept <defs.h>#include <defBF533.h> // will accept <defs.h>#include <macros.h> // will accept <macro.h>#include <macros.h> // will accept <macro.h>

.section program.section program P0.L = P0.L = lo(lo(TCOUNT); // will accept HI( ) and LO ( )TCOUNT); // will accept HI( ) and LO ( )

P0.H = P0.H = hi(hi(TCOUNT);TCOUNT);countInRegisterR0 = [P0];countInRegisterR0 = [P0];

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

1313

Know what the hi( ) and lo( ) Know what the hi( ) and lo( ) macros domacros do

.section program.section program

P0.L = P0.L = lo(lo(TCOUNT); TCOUNT); P0.H = P0.H = hi(hi(TCOUNT); TCOUNT);

MEANSMEANS

P0.L = TCOUNT & 0xFFFF; P0.L = TCOUNT & 0xFFFF; P0.H = (TCOUNT & 0xFFFF0000) >>16 P0.H = (TCOUNT & 0xFFFF0000) >>16

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

1414

HINT – #define CONSTANTSHINT – #define CONSTANTSdon’t use CONSTANTSdon’t use CONSTANTS

#define MAXVALUE 44000 #define MAXVALUE 44000 Either hex or decimal is okay Either hex or decimal is okay

..section programsection program R0.L = R0.L = lo(MAXVALUE);lo(MAXVALUE);

R0.H = R0.H = hi(MAXVALUE);hi(MAXVALUE);

HINT: If the person is following “standard” HINT: If the person is following “standard” coding conventions then CAPITIALS MEAN coding conventions then CAPITIALS MEAN CONSTANT – use hi( ), lo( )CONSTANT – use hi( ), lo( )

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

1515

HINT – Will work for small HINT – Will work for small constants tooconstants too

#define MAXVALUE 22000 #define MAXVALUE 22000 Either hex or decimal is okay Either hex or decimal is okay

.section program.section program R0.L = R0.L = lo(MAXVALUE);lo(MAXVALUE);

R0.H = R0.H = hi(MAXVALUE);hi(MAXVALUE);

BUT IN THIS CASE – since the constant is small (short int size)BUT IN THIS CASE – since the constant is small (short int size) R0 = MAXVALUE;R0 = MAXVALUE;

Or R0 = 6;Or R0 = 6;

HINT: If it looks like IT MIGHT BE a big constant,HINT: If it looks like IT MIGHT BE a big constant, then let the assembler worry about it -- use hi( ) and lo( ) then let the assembler worry about it -- use hi( ) and lo( )

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

1616

Condition codesCondition codes 99999 times out of 100000 the following is wrong99999 times out of 100000 the following is wrong

CC = R0 < number;CC = R0 < number;

So play the oddsSo play the odds

R1 = number;R1 = number; CC = R0 < CC = R0 < R1R1;;

Will accept CC = (R0 < R1); under exam conditionsWill accept CC = (R0 < R1); under exam conditionsWILL NOT ACCEPT CC = R1 > R0;WILL NOT ACCEPT CC = R1 > R0;

CC conditions are always checked VERY closely as they cause CC conditions are always checked VERY closely as they cause so much problem in the laboratory and in “real life”so much problem in the laboratory and in “real life”

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

1717

LOAD AND STORE OPERATIONSLOAD AND STORE OPERATIONS

Rule to remember – if the operation Rule to remember – if the operation would not work on the MIPS, then it would not work on the MIPS, then it will not work on the Blackfin or any will not work on the Blackfin or any other RISC processorother RISC processor

register register memory R0 = [P1]; memory R0 = [P1];memory memory register [P1] = R0; register [P1] = R0;

NEVER add to memory, [P1] = [P0] +1;NEVER add to memory, [P1] = [P0] +1; add to register R0 = R0 + [P0]; add to register R0 = R0 + [P0];

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

1818

Register operationsRegister operationsAdd a small numberAdd a small number

Make sure that you get the common instructions Make sure that you get the common instructions correct – there are not manycorrect – there are not many

R0 += pretty_small_number R0 += pretty_small_number R0 += 6 or R0 += -10; R0 += 6 or R0 += -10;

NOT R0 = R0 + 6;NOT R0 = R0 + 6;

Pretty_small_numbers are just that – pretty small Pretty_small_numbers are just that – pretty small numbers numbers -64 <= num <= +63 -64 <= num <= +63

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

1919

Register operationsRegister operationsAdd a larger numberAdd a larger number

Make sure that you get the common instructions correct – there are not Make sure that you get the common instructions correct – there are not manymany

R1 = larger_number;R1 = larger_number;R0 = R0 + R1; R0 = R0 + R1;

R1 = 0x2000;R1 = 0x2000; R0 = R0 + R1; R0 = R0 + R1; NOT R0 += R1;NOT R0 += R1;

R1 = 20000;R1 = 20000; R0 = R0 + R1; R0 = R0 + R1;

R1.L = lo(40000);R1.L = lo(40000); R1.H = hi(40000); R1.H = hi(40000); R0 = R0 + R1; R0 = R0 + R1;

HINT: Hexadecimal numbers are easy to work out if they are small (need 16-HINT: Hexadecimal numbers are easy to work out if they are small (need 16-bits) or very large (need 32-bits). bits) or very large (need 32-bits). Decimal numbers are not – PLAY THE ODDS – if it looks large in decimal – Decimal numbers are not – PLAY THE ODDS – if it looks large in decimal – then use lo( ), hi( ) approachthen use lo( ), hi( ) approach

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

2020

Other instructions we have usedOther instructions we have used

Make sure that you get the common Make sure that you get the common instructions correct – there are not instructions correct – there are not many common instructions to worry many common instructions to worry aboutabout

JUMP LABEL_END; // OFTENJUMP LABEL_END; // OFTEN JUMP (P0); // typically end of function JUMP (P0); // typically end of function

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

2121

Other instructions we have usedOther instructions we have used

Make sure that you get the common Make sure that you get the common instructions correct – there are not manyinstructions correct – there are not many

CALL _FeePassVoidFunction__FvCALL _FeePassVoidFunction__Fv

// void FeePassVoidFunction(void); // void FeePassVoidFunction(void);

NOTE: CALL _FeePassVoidFunction__FvNOTE: CALL _FeePassVoidFunction__Fv

// long int FeePassVoidFunction(void); // long int FeePassVoidFunction(void); // Returns a value in R0; // Returns a value in R0;

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

2222

Other instructions we have usedOther instructions we have used Make sure that you get the common instructions Make sure that you get the common instructions

correct – there are not manycorrect – there are not many

// void FeePassLongIntFunction(long int);// void FeePassLongIntFunction(long int); CALL _FeePassLongIntFunction__Fl (little L)CALL _FeePassLongIntFunction__Fl (little L)

CALL _FeePassLongIntFunction__NM -- okay in exam CALL _FeePassLongIntFunction__NM -- okay in exam

CALL _FeePassIntFunction__Fi (little I)CALL _FeePassIntFunction__Fi (little I)

// void FeePassIntFunction(long int); // void FeePassIntFunction(long int);

CALL _FeePassIntFunction__NM2 -- okay in exam CALL _FeePassIntFunction__NM2 -- okay in exam

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

2323

Other instructions we have usedOther instructions we have used

Make sure that you get the common Make sure that you get the common instructions correct – there are not manyinstructions correct – there are not many

R0 = 7;R0 = 7; CALL _FeeFunction__Fl; CALL _FeeFunction__Fl; // FeeFunction( 7); // FeeFunction( 7);

R1 = 6;R1 = 6; R0 = 7; R0 = 7; CALL _FumFunction__NM; CALL _FumFunction__NM; // FumFunction(7, 6 ); // FumFunction(7, 6 );

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

2424

Other instructions we have usedOther instructions we have used

Make sure that you get the common Make sure that you get the common instructions correct – there are not manyinstructions correct – there are not many

R0 = 7;R0 = 7; CALL _FeeFunction__Fl; CALL _FeeFunction__Fl; // FeeFunction( 7); // FeeFunction( 7);

R1 = 6;R1 = 6; R0 = 7; R0 = 7; CALL _FumFunction__NM; CALL _FumFunction__NM; // FumFunction(7, 6 ); // FumFunction(7, 6 );

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

2525

When to use a register andWhen to use a register andwhen to use memorywhen to use memory

..extern _value;extern _value; // extern long int value // extern long int value .section L1_data;.section L1_data; .global _fum_value; // long int fum_value; .global _fum_value; // long int fum_value;

.var _fum_value;.var _fum_value;

.section program;.section program; .global _FooFunction__Fl; // void FooFunction(long int .global _FooFunction__Fl; // void FooFunction(long int passed_Ficklepassed_Fickle) {) {

_FooFunction__Fl:_FooFunction__Fl: LINK 16; LINK 16;

passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6; passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6;

P0.H = _value; // value = value + 6;P0.H = _value; // value = value + 6; P0.L = _value; P0.L = _value; R1 = [P0]; R1 = [P0]; R1 += 6; R1 += 6;

[P0] = R1;[P0] = R1;

P1.H = _fum_value; // fum_value = fum_value + 6;P1.H = _fum_value; // fum_value = fum_value + 6; P1.L = _fum_value; P1.L = _fum_value; R2 = [P1]; R2 = [P1]; R2 += 6; R2 += 6;

[P1] = R2; [P1] = R2; ……… ……… // Rest of the function// Rest of the function

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

2626

When to use a register andWhen to use a register andwhen to use memorywhen to use memory

.section program;.section program; .global _FooFunction__Fl; // void FooFunction(long int .global _FooFunction__Fl; // void FooFunction(long int passed_Ficklepassed_Fickle) {) {

_FooFunction__Fl:_FooFunction__Fl: LINK 16; LINK 16;

passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6; passed_Fickle_R0 += 6; // passed_Fickle = passed_Fickle +6;

#define value_R1 R1 // long int value#define value_R1 R1 // long int value value_R1 += 6; // value = value + 6; value_R1 += 6; // value = value + 6;

#define fum_valueR2 R2 // long int fum_value; #define fum_valueR2 R2 // long int fum_value;

fum_value_R2 += 6; // fum_value = fum_value + 6;fum_value_R2 += 6; // fum_value = fum_value + 6;

……… ……… // Rest of the function// Rest of the function

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

2727

Other requested question and Other requested question and answersanswers