CS2200 Presentation 2a - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

CS2200 Presentation 2a

Description:

The free statement is perfectly valid! ... Crawl under your pillow with a laptop and a case of Surge. Read the book. Work all the problems! ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 43
Provided by: ccGa
Category:

less

Transcript and Presenter's Notes

Title: CS2200 Presentation 2a


1
CS2200Presentation 2a
  • Pre-assessment Results

2
Results
  • Number of students who took the assessment

3
Question
  • What do you want to do?

4
Question 1
5
Question
  • What do you know?

6
Question 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

7
Solution
  • void swap(int x, int y)
  • int t
  • t x
  • x y
  • y t
  • / Call... /
  • swap(a, b)

8
Results Question 2 (Swap)
Lots of people don't know how pointers work!
9
Question 3
  • What does a "make" do? Your answer should include
    three major items.

10
Solution
  • 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)

11
Wrong 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!

12
Results
  • Question 3 (Make)Wide variety of answers from
    blank to pretty close.Many answers based on
    perceptions gained from use.

13
Question 4
  • Write 42 in binary and in hexadecimal
  • Write 42.25 in binary
  • (Not IEEE Floating Point)

14
Solution
  • 4210 1010102
  • 4210 2A16 0x2A
  • 42.2510 101010.012

15
Results
Obsolete
  • Question 4 (Binary/Hex numbers)

a
b
c
16
Question 4a Write 42 in Binary
17
Question 4b Write 42 in Hexadecimal
18
Question 4c Write 42.25 in Binary (Not IEEE
Floating Point)
19
Question 5
  • Given a full adder as a building block
  • Inputs
  • A B
  • ---------
  • Carry out -- -- Carry in
  • ----------
  • Output

20
Question 5
  • Given a full adder as a building block

Inputs
A
B
Carry out
Carry in
Output
21
What does it do?
  • 5 Adds A, B and Carry in

Inputs
A
B
Carry out
Carry in
Output
22
What 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
23
Make an 4 bit adder
A0
A1
A2
A3
B0
B1
B2
B3
0
C0
C1
C2
C3
C A B
24
How do we subtract?i.e. A - B
  • Take the 2's complement of B and add!!!
  • A B 1

25
Complement?
B
x o r
C
26
Can it subtract?
A0
A1
A2
A3
B0
B1
B2
B3
C0
C1
C2
C3
Control Calculation 0 C A B 1 C
A - B
27
Overflow?
28
Recall
N 3
Number Stored
Number Represented
29
Consider
  • 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

30
Overflow?
A0
A1
A2
A3
B0
B1
B2
B3
C0
C1
C2
C3
Control Calculation 0 C A B 1 C
A - B
31
Results
  • Question 5 (Simple Arithmetic unit)

Drew 4 boxes
32
Question 6
  • What do you suppose this does
  • load r1, 2
  • load r2, 3
  • add r3, r1, r2
  • store r3, answer
  • answer word 0

33
One 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

34
Results
Obsolete
  • Question 6 (Pseudo assembly code)

Some confusion about memory use. Indication that
very rigid ideas exist as toassembler syntax.
35
Question 6 (Pseudo assembly code)
-Some confusion about memory use. -Memory
Address Value -Indication that very rigid ideas
exist as to assembler syntax.
36
Question 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

37
Solution
  • 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?

38
Misconceptions
  • 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!

39
Results
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
40
Results
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.

41
Conclusions
  • 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

42
Recommendation 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!!!

43
Recommendation 2
  • Review your 2030 stuff
  • Use Appendix B in Patterson Hennessy
  • Buy Code by Charles Petzold
  • Follow same instructions re pillow and Surge

44
Questions?
45
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com