程序代写案例-CSE 121
时间:2021-09-30

CSE 121 – Fall 2021 Homework 1 Due Friday, Oct 1 (Submit through Gradescope) This is a review of material covered in prerequisite classes CMPE 13, CMPE 100 and EE 101. All solutions submitted must be your own. The first three exercises are to write small C functions. You can use any C compiler and system to test your code. You need to submit only the code for the function. Do not submit the code used to test the function. Because this is a class on embedded systems, the efficiency of the code is an important grading criterion. Each of the functions should take only a few lines of code to implement. It is not sufficient to have working code, but it also needs to be simple and compact. We do not specify the maximum acceptable number of lines for each function (which is difficult because there are many ways to define what a line of code means). However, the following example illustrates what is acceptable and what is not. Example: Write a C Function that takes a 32‐bit unsigned integer as its only argument, reverses the order of its bytes, and returns the result. For example, when the input is 0x12345678, the function should return 0x78563412. The following is an efficient solution: unsigned int transposeBytes (unsigned int a) { return ( ((a >> 24) & 0xff) | ((a >> 8) & 0xff00) | ((a << 8) & 0xff0000) | ((a << 24) & 0xff000000)); } The following is a working, but unacceptable, solution: WARNING: This material is copyrighted and provided for your own use only. Uploading this material to sites such as CourseHero and Chegg is a violation of copyright laws and may subject you to legal action. It could also result in a failing grade for the class. 1. Write a function that takes a 32-bit unsigned integer as its only argument and returns the index of the bit position where the first 0-to-1 transition occurs (assume that the bits are numbered such that 0 is the least significant bit and 31 is the most significant bit). The function should return -1 when the input has no transition. int first_transition (unsigned int a) { } - Input of 0x110 should return 3, because the first 0-to-1 transition is at bit index 3. - Input of all zeroes or all 1’s should return -1. - Input of 0xff returns -1 (there is a 1-to-0 transition, but no 0-to-1 transition). 2. Write a function that takes a 32-bit unsigned integer as its only argument and returns the length of the longest run of zeroes or ones in it. unsigned int longest_run(unsigned int a) { } - Input of 0xff00ff00 should return 8, because the length of the longest sequence of consecutive zeroes is 8, and the length of the longest run of ones is also 8. - Input of ffff8000 should return 17 because this sequence has 15 zeroes followed by 17 ones. - Input of all zeroes or all ones should return 32. - The smallest value returned is 1 (when the input is an alternating sequence of zeros and ones). 3. Write a C function that takes a pointer to a string and returns a 1 if the input is hello world, and returns 0 otherwise. unsigned int helloWorld(char *greeting){ } You can assume greeting points to a null-limited character string. You need to check if the first word (token) of the string is “hello” and the first five characters of the following word is “world”. There can be any amount of white space between words. The characters can be lower-case or upper-case. “world” may be followed by any number of characters. You can assume at least one space between “hello” and “world”. The following are some of the input patterns that pass the test: - “Hello World” - “Hello World\n\r” - “ HeLLo WorlD123!” The following are examples of patterns that fail the test: - “Helo World” - “Hello !World” - “HelloWorld” You should use the C string library to solve this problem. The solution should only take a few lines. You can use the strtok() function to tokenize the string and strcmp() or strncmp() to compare strings. There are also functions in the library for case-insensitive comparisons. 4. The following diagram shows the LED from the parts kit (datasheet can be found here). The anode voltage is 5V. Assuming you want to limit the maximum forward current through each LED to 10 mA, determine the minimum value for each series resistor? Use the typical values of the forward voltages from the datasheet for the calculations (for example, for the red LED the typical forward voltage is 1.8V). What is the total power in milliWatts consumed by this circuit? R G B 5. The D flip-flop below is designed capture pulses at its input. It is clocked by a 100 MHz clock and the input pulses are asynchronous to the clock. The flop’s parameters are: - Setup time = 100 ps - Hold time = 60 ps - Clock to output delay = 70 ps DATA CLOCK What is the minimum width of an input pulse in nanoseconds that can be reliably captured by the flip-flop? Note: 1 picosecond = 10-12 second, 1 nanosecond = 10-9 second, 1 MHz = 106 Hz. 6. Determine the voltage V1 in the circuit below (Vss is ground). You can use the symmetry of the ladder to arrive at the result with no complex calculations.


















































































































































































学霸联盟


essay、essay代写