Title: CS2200 Presentation 2a
1CS2200Presentation 2a
2Results
- Number of students who took the assessment
3Question
4Question 1
5Question
6Question 2
- Write a function in C called swap that will swap
two ints - It will be called like this
- int a 42
- int b 78
- / Call to swap goes here /
- printf("d d\n", a, b)
- The output would be
- 78 42
- Write swap here
-
7Solution
- void swap(int x, int y)
-
- int t
- t x
- x y
- y t
-
- / Call... /
- swap(a, b)
8Results Question 2 (Swap)
Lots of people don't know how pointers work!
9Question 3
- What does a "make" do? Your answer should include
three major items.
10Solution
- The make program generates a sequence of commands
for execution by the Unix shell - Make uses a table of dependencies input by the
programmer - Make automatically updates files for the user
- When a change is made, make creates proper files
with a minimum of effort - Make has a macro facility
- name string CCgcc
- (name) (CC)
11Wrong answers?
- Make compiles your program
- Make cleans up your directory
- Make turns in your assignment
- Make is a preprocessor
- Make is like a batch file
- Makes your life faster and easier
- Touches files
- Slices, dices, liquefies a bass!
12Results
- Question 3 (Make)Wide variety of answers from
blank to pretty close.Many answers based on
perceptions gained from use.
13Question 4
- Write 42 in binary and in hexadecimal
- Write 42.25 in binary
- (Not IEEE Floating Point)
14Solution
- 4210 1010102
- 4210 2A16 0x2A
- 42.2510 101010.012
15Results
Obsolete
- Question 4 (Binary/Hex numbers)
a
b
c
16Question 4a Write 42 in Binary
17Question 4b Write 42 in Hexadecimal
18Question 4c Write 42.25 in Binary (Not IEEE
Floating Point)
19Question 5
- Given a full adder as a building block
- Inputs
- A B
-
-
- ---------
-
-
- Carry out -- -- Carry in
-
-
- ----------
-
- Output
20Question 5
- Given a full adder as a building block
-
Inputs
A
B
Carry out
Carry in
Output
21What does it do?
Inputs
A
B
Carry out
Carry in
Output
22What does it do?
- A, B and Carry in Carry out Output
- 3 zeros 0 0
- One 1 0 1
- Two 1's 1 0
- Three 1's 1 1
Inputs
A
B
Carry out
Carry in
Output
23Make an 4 bit adder
A0
A1
A2
A3
B0
B1
B2
B3
0
C0
C1
C2
C3
C A B
24How do we subtract?i.e. A - B
- Take the 2's complement of B and add!!!
- A B 1
25Complement?
B
x o r
C
26Can it subtract?
A0
A1
A2
A3
B0
B1
B2
B3
C0
C1
C2
C3
Control Calculation 0 C A B 1 C
A - B
27Overflow?
28Recall
N 3
Number Stored
Number Represented
29Consider
- 3 bit numbers
- Max allowed 3 (011)
- Min allowed -4 (100)
- 2 -2 2 -2
- 3 3 -3 -3
- 5 1 -1 -5
- 010 110 010 110
- 011 011 101 101
- 0101 1001 0111 1011
- Bad Ok Ok Bad
30Overflow?
A0
A1
A2
A3
B0
B1
B2
B3
C0
C1
C2
C3
Control Calculation 0 C A B 1 C
A - B
31Results
- Question 5 (Simple Arithmetic unit)
Drew 4 boxes
32Question 6
- What do you suppose this does
- load r1, 2
- load r2, 3
- add r3, r1, r2
- store r3, answer
-
- answer word 0
33One possibility...
- load r1, 2 Put 2 in R1
- load r2, 3 Put 3 in R2
- add r3, r1, r2 Add R1 and R2 result R3
- store r3, answer Store R3 in location
- answer
-
- answer word 0 Variable
34Results
Obsolete
- Question 6 (Pseudo assembly code)
Some confusion about memory use. Indication that
very rigid ideas exist as toassembler syntax.
35Question 6 (Pseudo assembly code)
-Some confusion about memory use. -Memory
Address Value -Indication that very rigid ideas
exist as to assembler syntax.
36Question 7
- What do you think about this
- Plan createNewSelectionNode(
- Cond condition,
- char relation)
-
- Plan newNode
- newNode(Plan)malloc(sizeof(Plan))
- newNode-gtopSELECTION
- newNode-gtcondParams0condition
- newNode-gttableP1NULL
- newNode-gttableP2NULL
- newNode-gttable1relation
- free(newNode)
- return newNode
-
37Solution
- Where do you think that this question came from?
- What's the really big error?
- What will happen?
- How likely?
- What's the other evil sin?
- What might happen?
- How likely?
38Misconceptions
- free() returns NULL
- free doesn't return anything!
- free() causes an immediate core dump?
- No! The free statement is perfectly valid!
- Hardly anyone mentioned checking the return value
from malloc!!! - 4 people caught the malloc but not the free!
- Casting return value from malloc is not illegal!
Dates back to days before void pointers were
invented. In fact, it might still be a good idea!
39Results
Obsolete
- Question 7 (Bad C Function)Note Wide variety
of interpretations ofexactly what were
implications of problem.
Excellent Identified errors
consequences Good Identified errors Fair
Identified free error
40Results
Excellent Identified errors
consequences Good Identified errors Fair
Identified free error
- Question 7 (Bad C Function)Note Wide variety
of interpretations of exactly what were
implications of problem.
41Conclusions
- Many of you need to quickly get the prerequisite
knowledge for this course - You will be designing control systems for digital
logic circuits and implementing them in C!!! - You need to know pointers, structs, queues,
stacks, etc. really well
42Recommendation 1
- Buy (don't borrow) Kernighan Ritchie The C
Programming Language - Put the book under your pillow
- Crawl under your pillow with a laptop and a case
of Surge - Read the book. Work all the problems!!!
43Recommendation 2
- Review your 2030 stuff
- Use Appendix B in Patterson Hennessy
- Buy Code by Charles Petzold
- Follow same instructions re pillow and Surge
44Questions?
45(No Transcript)