ECE 11: Computational Methods in ECE

advertisement
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
ECE 11: Computational Methods in ECE
Winter Quarter, 2000
Douglas C. Schmidt
University of California, Irvine
Email: schmidt@uci.edu
Web Pages: http://e3.uci.edu/00w/14700/ and http://www.eng.uci.edu/~schmidt/classes/ece011/
UCI Phone: (949) 824-1901
UCI Office (meeting place): Engineering Tower 616E
Office Hours: TBD and by appointment
Readings from Brooks are prefaced by [DB]. Readings from Kelley and Pohl are prefaced by [KP]. Readings from Gamma et
al. are prefaced by [GoF]
Class notes are available for purchase at the Engineering Copy Center or can be downloaded from class Web pages
Cross references to the Brooks text are included in the notes
Week
Day
Date
Topic
Notes
Readings
1
Tu
Th
1/11
1/13
Class Overview
Introduction to Computers and C
Ch 1
[DB] Ch 1
[KP] Ch 1
2
Tu
Th
1/18
1/20
Intro to Patterns
A Gentle Introduction; Data Types and Constants
2-1...2-32
[GoF] Ch 1 [DB] Ch 2-3
[KP] Ch 2-3
3
Tu
Th
1/25
1/27
Arithmetic Operators; if/else
Type Conversions; assignment and conditional ops
2-33...2-52
3-1...3-29
[DB] Ch 3-4
[KP] Ch 2, 4
4
Tu
Th
2/1
2/3
while, for, switch,
Bitwise operators; do, break, continue
3-30...3-43
4-1...4-23
[DB] Ch 4
[KP] Ch 4, 7
5
Tu
Th
2/8
2/10
Functions and Program Structure I
MIDTERM EXAM
5-1...5-32
[DB] Ch 5
[KP] Ch 5
6
Tu
Th
2/15
2/17
Functions and Program Structure I (cont)
Mathematical Induction; Recursion
5-33...5-53
6-1...6-31
[DB] Ch 5
[KP] Ch 5; Notes: Ch 6
7
Tu
Th
2/22
2/24
Common design patterns
Functions and Program Structure II
7-1...7-25
[GoF] Ch 2
[KP] Ch 5
8
Tu
Th
2/29
3/2
The C Preprocessor
The C Preprocessor (cont)
8-1...8-21
8-22...8-45
[KP] Ch 8
9
Tu
Th
3/7
3/9
One Dimensional Arrays
Introduction to Pointers
9-1...9-15
9-16...9-29
[DB] Ch 6
[KP] Ch 6
10
Tu
Th
3/14
3/16
Pointers and Arrays
Pointers and Strings
9-30...9-41
9-42...9-54
[DB] Ch 6
[KP] Ch 6
Finals
F
3/24
FINAL EXAM, TBA…
Grading: Lab Assignments (300), Midterm (300), Final Exam (400)
1
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
Points
10
8-9
7
5
3
1
Interpretation
Perfect, no mistakes
Minor computational error(s)
Minor flaw
Right idea, poor execution
Some clue
Mercy
Points are awarded only when the answer (assignment) is on the right track. Off the wall solutions, downright wrong solutions,
or solutions making fatal mistakes will get zero (0) points. An example would be a problem asking the student to rewrite a
code fragment using a for loop and the student writes it using a while loop. Zero.
My target grading standard (out of 1000): A+ (> 900), A (810), A- (800); B+ (790), B (710), B- (700); C+ (690), C (610), C(600); D+ (590), D (510), D- (500).
The following table lists all lab assignments for this class. All labs are either from the required Brooks [DB] textbook or the
required Kelley and Pohl [KP] textbook. Instructor Handouts are included in the course notes. Lab scores will be totaled
and scaled to 300 points.
Lab No
Week Due
Points
Page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
1
1
2
2
2
2
3
3
3
4
4
4
4
5
5
5
5
6
6
6
6
7
8
8
8
9
9
9
10
10
10
10
10
10
10
10
10
10
20
30
30
10
20
20
20
20
30
10
30
20
20
30
10
200
20
30
50
30
50
30
30
40
30
[KP] 61
[KP] 66
[KP] 100
[DB] 108
[DB] 110
[DB] 115
[DB] 119
[KP] 192
[KP] 192
[KP] 194
[DB] 159
[DB] 160
[DB] 162
[DB] 163
[KP] 357
[KP] 357
[KP] 357
[KP] 358
[DB] 163
[DB] 216
[DB] 222
[KP] 193
[DB] 217
[DB] 217
[DB] 219
[DB] 276
[DB] 285
[DB] 278
[DB] 280
[DB] 286
Lab Assignment
#5
#19
#18
#1
#6
#12
#16 (see p. 53 for file I/O example)
#24
#25
#31
#1
#3 (both parts)
#9
#11
#2
#3
#4
#6
#12
#6
#12
#29
Instructor Handout I
#7
#8
#10
#3
#14 (must write a test program/driver for it)
Instructor Handout II
#5
#8
#16
2
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
ECE 11 LAB POLICIES
All lab assignments must be checked off by the TA during lab hours. Labs are held on
Sunday, Monday, Tuesday, and Thursday, and Friday. To receive full credit for a given
week's labs, one must have it checked off before the conclusion of the last lab on Friday.
Please note that the last lab meets from 5:00 to 7:50 p.m.. You should expect the TAs to
shut the doors and close the lab promptly at 7:50. Do not expect them to keep it open to
give you extra time. You can receive 70% credit on a lab by having it checked off before
the conclusion of the last lab on Tuesday. Again, please note that this lab meets from
11:00 to 1:50 p.m.. There will be absolutely no extensions to this lab so those failing to
get their labs checked off at this time will be SOL. In the 10th week, all labs must be
checked off by the end of Friday's session. Since there are no labs held during Final's
week, there are no extensions beyond Friday.
There are no extensions to any labs.
The TAs may be willing to accept labs via email, but it is his/her sole discretion. It is your
responsibility to arrange it with him/her and it is strictly up to him/her whether to allow
such submissions. I will not intervene on your behalf.
All lab submissions given to me (the instructor) will be discarded. Do not send me labs
and expect me to forward them or grade them. You are wasting your time.
Lab 23 notes
Lab 23 is a long and significant lab. Because of this, it is the only required lab during a
one week period. All other labs are pale in comparison. This lab is designed to give you
experience with the bitwise operators, functions, and overall design and planning.
Planning is the key word. This is as much a laboratory and exercise in planning and time
management as it is technical. Because of this, I give the following stern warnings.
Do not wait until the last minute to do this lab. If you do, you will fail. Instead, begin
working on portions of this lab as early as possible. The user interface is as big as the
bitwise operator function implementation. Implement the user interface first. Then
implement the bitwise operators.
You may also attempt to get this lab checked off early to get a provisional grade. You
may get it checked off later for a higher grade. The grade recorded will be the highest of
all of the grades.
Lab 23 is due Friday, February 25 for full credit. The lab will also be accepted
through Tuesday, February 29 at 70% credit and Friday, March 3 at 40% credit.
There are no exceptions or excuses. This includes the lab being too busy.
3
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
Instructor Handout I (Lab 23)
200 points
In this assignment, you are to implement each part of it as a function. You must also have a test driver
program which the lab attendant can run to test your program. No credit will be given if the lab attendant
cannot test your program. Implement the project using at least two source files and a header file. One
source file shall have these bitwise functions in them, another shall have your test driver, and the header
file shall have the function declarations. A source file (any file containing function or variable
definitions) shall not include another source file. You must modify your project to include each of the
source files and to compile each of them separately. No credit will be given to anyone violating these
requirements.
The first thing you should do is write the test program. That is, implement main() such that it loops,
prints out a menu, reads in the selection, and then executes the desired function. For each selection, you
should prompt the user for any additional inputs that you may require.
Assume that all operations act on a single 32 bit (unsigned long) value which is initially 0. Each
operation shall assume that this variable is the operand. Your test driver shall have a command which
allows us to display the current value of this operand.
1.
Write a function to retrieve the ith bit of its argument. It should return 0 if it is out of range. The
function prototype should be as follows:
int get_bit(unsigned long x, int i);
Your test driver shall prompt the user for the desired bit, retrieve it from the operand, and then display
whether it is ON or OFF, e.g. 1 or 0.
2.
Write a function to set the ith bit of its argument. It should do nothing if it is out of range. The
function prototype should be as follows:
unsigned long set_bit(unsigned long x, int i, int bit);
Your test driver shall prompt the user for the desired bit, then prompt the user for value of the bit (0 or 1),
perform the operation, and then display the changed operand in 8 digit HEX format.
3.
Write a function to extract from x the right-most n bits that begin at position p. If the number of
bits n extends beyond the end of the object, stop (do not wrap around). Return 0 if no bits can be
fetched. The function prototype should be as follows:
unsigned long getbits(unsigned long x, int p, int n);
Your test driver shall prompt the user for n and p and then call this function on the operand. It should
then display the output (result) in 8 digit HEX format.
4
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
4.
Write a function that returns x with the n bits that begin at position p set to the rightmost n bits of
y, leaving the other bits unchanged. Do not implement wrap-around. The function prototype
should be as follows:
unsigned long setbits(unsigned long x, int p, int n,
unsigned long y);
Your test driver shall prompt the user for n, p, and y. Assume that y is being entered in HEX and use the
appropriate scanf argument. Then call the function and save the result as the operand and display the
changed operand in 8 digit HEX format.
5.
Write a function to extract from x the right-most n bits that begin at position p. If the number of
bits n extends beyond the end of the object, extract the bits from the left side, i.e. wrap-around.
Thus, x[7:16] yields x[7:8] & x[31:8] if x is an unsigned long object and where &
stands for bit-vector concatenation. For example 0xABCDEF12[7:16] yields 0x12AB. If n
exceeds the number of bits in the object, stop when you wrap around to where you started. The
function prototype should be as follows:
unsigned long getfield(unsigned long x, int p, int n);
Hint: consider using getbits () from #3 to implement this function. Your test driver shall prompt the
user for n and p and then call this function on the operand. It should then display the output (result) in 8
digit HEX format.
6.
Write a function that returns x with the n bits that begin at position p set to the rightmost n bits of
y, leaving the other bits unchanged. Implement wrap-around. The function prototype should be
as follows:
unsigned long setfield(unsigned long x, int p, int n,
unsigned long y);
Hint: consider using setbits () from #4 to implement this function. Your test driver shall prompt the
user for n, p, and y. Assume that y is being entered in HEX and use the appropriate scanf argument.
Then call the function and save the result as the operand and display the changed operand in 8 digit
HEX format.
For a sample test driver, see a Sample (Useless) Test Driver further down in the notes.
Be prepared to answer questions on each of your functions. The TA may ask you to
explain how each function works to ensure that you did, indeed, write the code yourself
and that you do, indeed, understand it. If you fail to satisfactorily explain how these
functions work, then you will not receive any credit for those things which you do not
understand. This policy may be applied to other labs as well so do your own work.
5
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
Instructor Handout II (Lab 29)
30 points
In Lab 23 (Instructor Handout I), your wrote functions get_bit(), set_bit(),
getbits(), and setbits(). Rewrite each of these functions as macros.
Place the definitions of these macros in a header file and have your test driver
implementation file #include that header file. The header file should have the definition
of these four macros.
The test driver you wrote in Lab 23 should work with very little changes.
6
ECE 11 Syllabus: Winter, 2000, Douglas C. Schmidt
A Sample (Useless) Test Driver
#include <stdio.h>
void main(void)
{
char choice;
int ret;
int print_menu = 1, skipit = 0;
for (;;)
{
if (print_menu)
{
printf("(1)
printf("(2)
printf("(3)
printf("(q)
First choice\n");
Second choice\n");
Third choice\n");
Quit\n");
printf("Enter selection: ");
}
else print_menu = 1;
ret = scanf("%1c", &choice);
if (ret != 1)
{
printf("Invalid input\n");
return;
}
else if (skipit)
{
print_menu = 0;
if (choice == '\n') skipit = 0;
continue;
}
skipit = 1;
switch (choice) {
case '1':
printf("Menu selection 1\n");
printf("val=%08LX\n", (long)0xF83AB);
break;
case '2':
printf("Menu selection 2\n");
break;
case '3':
printf("Menu selection 3\n");
break;
case 'q': case 'Q':
printf("Quitting\n");
return;
case '\n':
print_menu = 0;
skipit = 0;
break;
default:
printf("Invalid menu selection: %c\n", choice);
break;
}
}
}
7
Download