ECE347_Lab3_Subs_and_Params ECE347 Lab Project – Stack and Passing Data to Subroutines 1. StartwithaMAINprogram,whichinitializesanARRAYof108-bitarbitrary...

Lab Project – Stack and Passing Data to Subroutines



ECE347_Lab3_Subs_and_Params ECE347 Lab Project – Stack and Passing Data to Subroutines 1.StartwithaMAINprogram,whichinitializesanARRAYof108-bitarbitrary numbersandreservesspaceforanother10-elementarraycalledEVENS.Then createsubroutinesasdescribedbelow.MAINshouldcallallsubroutinesinthe ordershowninthisdescription,thenexecuteaninfiniteloopwithsomeNOPs. 2.SubroutineEVEN_CNTcountsthenumberofevenarrayelements.Thetotal elementcountforthesourcearray(10)ispassedusingregisterA.Theaddressof thesourcearrayispassedusingregisterX.Thecountofevenelementsisreturned inregisterB.Uponreturning,MAINshouldsavetheBvalue,asitmaybeneeded laterintheprogram. 3.SubroutineCOPY_EVENcopiesalltheevenarrayelementstothearraycalled EVENS.Theaddressesofthesourceandtargetarraysarepassedonthestack.The numberofelementstoscan(10)ispassedonthestack. 4.SubroutineEVEN_AVEcalculatestheaverageofEVENelements.Thesource arrayaddressandnumberofevenelementsispassedonthestack.Theaverageis returnedina"stackhole."Ifthenumberofevenelementsis0,thesubroutine shouldexitimmediatelyupondetectingthis.Uponreturning,MAINshouldstorethe averagevaluethatwasreturnedfromEVEN_AVE. Testyourcodeanddocumentyourresultsforthefollowingcases: caseA:sevenevenelements,threeoddelements caseB:alloddelements,noevenelements Thisisanofficiallabinwhichaprofessionalreportistobeturnedin.Include inyoursinglepdffileanMSPEC,PCODE,unittestplan,andclearly documentedtestresultsforalltestcases.Thetestresultscanbecapturedby usingtheSNIPtoolonCodeWarriordebuggermemorydisplayorvariable window.Makesureyourdocumentationisclearandeasytoread. CSheet_v3 1 Embedded C Programming Reference Sheet v3 Libraries, some with standard functions (like printf, getchar), are pulled into your code through include statements: #include _____________________________________________________________________ All programs must have a function entitled main. The function's return data type is declared in front of the name; parameter type is enclosed in parens. Code and data declarations are enclosed in {}. Code statements end with semi-colon: void main(void) { int blob; float scum; printf("Hello! \n"); } _____________________________________________________________________ All variables must have their data type declared. Some data types are standard, but some may be machine dependent (MD): char character 8 bits int integer 16 bits (MD) long int (integer twice the size of an int) float single precision floating point double double precision floating point void means nothing is returned from /passed to a function _____________________________________________________________________ The following KEYWORDS cannot be used for variables of functions: auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while The keyword extern allows for file2 to access variables that are defined in file1: file1: int scum; void main(void) { scum = 17; } 2 file2: int blob(void) { extern int scum; scum = scum + 1; return scum; } _____________________________________________________________________ If you want a variable to retain its value for later use, you must use the static keyword: static int keep; Note that this prevents BDM from putting this variable in the symbols list. _____________________________________________________________________ You can force a variable to be stored in a CPU register (rather than memory) by using: register int blob = 12; _____________________________________________________________________ Constants can be declared using: const double PI = 3.14159265; _____________________________________________________________________ Arrays are declared using [size], and initialized using {} : int inbuf[100]; char string1[] = {"make a character array"}; float pressure[] = {1.1,2.3,5.9,1.7}; _____________________________________________________________________ Operators: add +, subtract -, multiply *, divide /, modulo (remainder) %, less than <, less="" than="" or="" equal=""><=, greater="" than="">, greater than or equal>=, is equal ==, is not equal !=, logical AND &&, logical OR ||, increment ++, decrement -- _____________________________________________________________________ Bitwise operators: logical AND &, logical OR |, exclusive OR ^, right shift >>, left shift <, one's="" comp="" ~="" _____________________________________________________________________="" 3="" usage="" of="" some="" operators:="" y="y">< 5;="" (shift="" contents="" of="" y="" 5="" bits="" to="" the="" left)="" r="r" &="" ~7;="" (="r" anded="" with="" the="" not="" of="" %00000111="r" anded="" with="" %11111000="" )="" tips="" (the="" following="" assume="" 16="" bit="" operands,="" 0x="" means="" hex="" number):="" testing="" bit="" fields:="" if="" (blob="" &="" 0x0400)="" then="" ...="" true="" only="" if="" bit="" 10="" of="" blob="" is="" true="" setting="" bits:="" blob="blob" |="" 0x0400;="" ....="" sets="" bits="" 10="" of="" blob="" blob="blob" |="" (1="">< 7);="" ...="" sets="" bit="" 7="" of="" blob="" clearing="" bits:="" blob="blob" &="" 0xfffe;="" ...="" clears="" bit="" 0="" of="" blob="" blob="blob" &="" ~(1="">< 7);="" ...="" clears="" bit="" 7="" of="" blob="" toggling="" bits:="" blob="blob" ^="" 0x0002;="" ...="" toggles="" bit="" 1="" of="" blob="" blob="blob" ^="" (1="">< 6);="" ...="" flips="" bit="" 6="" of="" blob="" _____________________________________________________________________="" conditionals:="" i="0;" while="" (="" i="">< 10)="" {="" out[i]="in[i]*4.3;" i="i" +="" 1;="" }="" for="" (i="0;" i="">< 10;="" i++)="" {="" out[i]="in[i]*4.3;" }="" if="" (="" i="=" 0)="" {="" a="b+c;" d="0;" }="" else="" a="b+d;" brackets="" optional="" if="" there="" is="" only="" one="" instruction="" break="" ;="" ...="" exit="" the="" current="" block="">
Apr 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here