Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Homework 2 FIVER

Download as docx or pdf
Download as docx or pdf
You are on page 1of 4
Instructions - General ‘There are 5 questions on this assignment. Answer all forful credit. Questons or their subparts are not necesseriy eaualy weighted + You may workin groups of two but you must formulate your own responses, answer or solutions foreach question or problem. Formulating one ansner or solution and copying from each oer is not permissible. + Provide rationale, explanation, tre of soliton o reasoning or your answers where applicable. Simply and magically providing responses or ansners for those questions or problems that equre reasoning may not receive any cect + Submission must be in hardcopy and delved by the student in person. Use blank nd eter size typing (printer) paper andin porta layout ‘You may use handwriting or word processor or combination for your submission. However, it must be organized, legible and presentable ‘Wie your fullname, rocket ID and your group member's name on the op right ofthe rst page of your submission. For ‘multiple sheets, staple them a the top left Instructions - Specific to this assignment + You must use Keilisin to develop code for embedded applications. lease not that a Kel C project template for programming questions inthis assignment is provided as a single compressed folder whichis named as “keProjectTemplateForn2" and posted wth the course Blackboard sit + For programming questions, you wil ned fo very the corectness of your code using the Keiluision debugger. ‘Accordingly, you are expected to capture snapshots (as screen captures) of relevant debug windons to demonstrate the correctness of your code during execution. Annotate your screen captures to explain es needed, which must be included in your submission ‘+ Capture end include in your submission the compilrlinker output window that shows that your code compiles and inks without error warnings for each programming queston. ‘Develop a flonchart and pseudocode for each programming question (except question 1) end include es part of your submission, + Provide the sourcecode in your submission wth proper indentation, label use, commenting and layout foreach ‘programming queston. + For programing tasks thats not fully functional, provide @ detailed explanation for whats functional. Questions: 1, Implement and test the following functionalities through C code fragments, a) Write a C eode fragment to check a bit value. Declare three character type variables eb, eh? ‘and mask with initial values of 0x34 and 0x20 for chl and mask, respectively. C code should set, character type variable ch2 to | ifthe bit 5 in mask is I otherwise 0. Note that bits ina byte are numbered from 0 (sb) to 7 (msb) b) Write a C code fragment to seta bit value, Declare two character type variables eh1 and mask ‘with initial value of 0x34 for ch. C code should set bit 7 in variable ch! to I using mask without changing any other bit values in ch. ©) Write a C eode fragment to clear a bit value. Declare two character type variables ehI and mask ‘with initial value of 0x34 for chi. C code should clear bit 3 in variable ch to 0 using mask ‘without changing any other bit values in chi. 4) Write a C code fragment to toggle a bit value. Declare two character type variables ch and. ‘mask with intial value of Ox34 for ch1. C code should toggle bit 4 in variable ch! using mask ‘without changing any other bit values in chl. 2. Write a C program for an embedded application (which must have a dead’ forever loop) which computes factorial of number $ using a “for loop” structure. Your program should use a single ‘nain() funetion to implement the fanetionality, and stay inthe desl forever loop once computation is complete 3. Write a C program for an embedded application (using a dead forever loop) which determines the ‘maximum valued number in an array of numbers. Declare a global array with 10 elements of integer type, name it maxValueArray, and initialize the array to following values: -1, 5,3, 8, -10, 23,6, 5 10. Declare a global integer type variable “arraySize” and initialize it to 10. Implement the functionality within the main() function. Once the task of determining the maximum number is ‘completed, the main() should stay in a forever loop. 4, Develop the following template into an embedded C program. '* Global variables here - avoid declaring too many glabals unnecessarily as itis not considered a good programming practice. “ int creditRatingAlice = 750; {VO represents “defaulted” and 1 represents “pai” forthe payment history int monthiyPaymenthistoryAlve|24)={1.000000001.41414.101.114.404) void main (void) { | main), while looping endlessly, sets a global flag creditStatus to the value retumed by the function J) rewardsOrAlarm(), } 1" Function called when Alice makes a monthly payment or defaults on the monthly payment. * Retums nothing, updates global variable creditRatingAlice, *! void updateCreditRatingAlice (int opcode, /" Of default, 4 if paid *){ J each monthly payment increments rating by 10 points all the way up to 800 1 every default decrements rating by 10 points down to 700. } "Function that raises an alarm when Alice's rating is 700 for 2 consecutive months, * or rewards her if she has maintained a rating of 800 for 2 consecutive months. * Reads montlyPaymentHistoryAlice for input * Returns 0 if alarm, 1 if reward, */ Page 2 of 4 int rewardsOrAlarm (){ | Read next value in monthlyPaymenthistoryAlice. Note that this function needs to keep track of the | last array element accessed so that when it reaches the last it can rewind tothe first in 2 round, |_robin fashion to read a value from the monthlyPaymentHistoryAlice array forever. I Pass the read value in monthlyPaymentHistoryAlice to function updateCreditRatingAlioe(int x) Return reward/alarm value, ' 5. One approach to functional debugging is to collect input and output data forthe software for typical input values. In particular we define a set of input values, tin the software, and record the output data ‘generated by the software, In this exercise we will test the software using input values from 0 to NI, where Vis 25. Consider the funetion s\n (n) to test. The elaim is that this funetion calculates the sum. ofthe numbers N down to 1. For example suum (5 is $+4#3+2+1 which equals 15. Furthermore, we ‘ill also test the hypothesis that the sum of '’ numbers can be expressed as the simple caleulation of (HD)2. ‘The test program will evaluate the fumetion sum (r.) and store the result in the array at sunBtof [1]. We need to define a sevond funetion fun (n) that simply caleulates (N(V*1))2. We have another array funBut that we will use to store the fist 25 calculations of this second funetion ‘We will check in the main program for equivalence of the two functions by comparing elements of cumBu£ to the elements of funBué, The main funetion should set a flag value based on the outcome of this comparison. Ina top-down approach, we place the main program on the top and the funetions after. In this example, ‘we will configure the system as bottom up by placing the functions first and the main program at the end, Notice that bottom up organization does not need prototypes for the functions. Following C program template with code fragments are given to help you get started: ‘define TRUE 1 ‘define FALSE 0 ‘define N25 Waray size ‘unsigned long sum(unsigned long n){ ‘unsigned long partial, count: ) ‘unsigned long fun(unsigned long n) ) int main(voidy{ Unsigned long num: Unsigned long sumBuflN], funBufN}; 1! arrays to store computed values: int corectFlag, ) Write the C code with following functions: sum (), fun () and main () ina bottom-up layout in a single source code file as an embedded application. Note that function definitions precede the main function in a bottom-up layout and therefore not requiring fuction prototype declarations as given in the above template. ‘As a secondary method of verification for equivalence of two computations, use Keil'uVision to verily that um (1) and fun (2) finetions compute the same values by comparing values stored in the unBu and FunBut arrays using appropriate windows in the debugger.

You might also like