0% found this document useful (0 votes)
11 views72 pages

EE209 24F 1IntroB

EE209_24F_1Intro for programming and this course

Uploaded by

inixcion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views72 pages

EE209 24F 1IntroB

EE209_24F_1Intro for programming and this course

Uploaded by

inixcion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

EE209: Programming Structures for

Electrical Engineering
EE209:Programming Structures for Electrical Engineering

Lecture 1. Introduction
Overview

Logistics

Overview of Computers Today

Overview of C Programming Language

3
Logistics
When: Mon & Wed 10:30 AM – 11:50 AM
Where: E11 #302 (we will sometimes have Zoom classes)
https://ee209.kaist.ac.kr/ : for course announcements, assignments,
submissions, lecture notes, class videos, etc.
https://campuswire.com/p/G48E4589B for Q&A, discussions, etc.
KLMS is used only for assignment submission.
kaist.ee209.ta.fall24@gmail.com : email to Professors and TAs –
please use this instead of individual emails or kakao talk
Emails or kakao messages to individual staff will be ignored

4
EE209A/B

We are EE209B. Your University ID must end with an even number

What is shared?
Content, exams, assignments, policies, lecture time

Grading

TAs

The pace/progress within the semester

Campuswire

What is different?
Instructors and classroom

In case one of the professors can’t teach on a certain day (e.g., travel,
vaccine side effects, etc.), the other professor will give the live lecture that
day to the merged EE209A/B via Zoom

5
In-person Lectures, but sometimes Zoom

Live lectures in classroom for active interactions

Lecture slides will be uploaded to class website ahead of time

We will sometimes merge EE209A/B and give lectures via Zoom


Current dates for Zoom lectures: 9/9(Mon) and 9/11(Wed)

The dates are subject to change, and we will announce beforehand

6
Guidelines on Using Zoom

Use the Zoom client instead of the web version

Set user name as your KAIST ID and name (e.g., 20210000 Phil Kim)

Turn the camera on; we want to match your name and appearance

Mute the mic except when discussing or asking questions

When you have a question:


Feel free to interrupt the speaker

Raise your hand on Zoom

Write your question on the Zoom Chatroom

7
HELLO!
I am Insu Han
BS - PhD in EE, KAIST (2021)
Became a professor at KAIST in 2024
Research in approximate algorithms
for machine learning

8
Teaching Avengers

Jaehan Kim (Head TA)

Teach Assistants (EE209B)


Name

Seungkwan Kang Seungjun Lee Minkyoo Song Hyeonho Shin

Minseok Kim Haksun Son Inje Hwang Jekyun Park

9
Office Hours
Professor:
By appointment; put [EE209] on email subject
We can chat via Zoom or visit to my office in N1

TAs: on course website

10
TA office hours & EE485

TA office hours (Live on zoom; by appointment)


Led by TAs

Schedule on class website

Set up an appointment by writing down your student ID on the office hour


booking page in the class website

Recommended companion course: “EE485A: Introduction to


Environments and Tools for Modern Software Development”
Supports EE209 lectures by low-level examples

Provides help on your programming assignments

Covers all contents of old “precepts” and more

1 unit, letter grade

11
Campuswire

Combined site for both sessions (A/B)

The platform to ask and answer questions at any time


It has both web-based and mobile app

Any one can answer anyone’s question


TAs, instructors, and peers (you!)

All questions should be posted here (not emailed)


So that everyone can share

Always search for answers before posting

Do not post personal information or assignment code; email to


kaist.ee209.ta.fall24@gmail.com

https://campuswire.com/p/G48E4589B

12
Textbooks (Highly Recommended)

C Programming: A Modern Approach (2 nd Edition),


King, 2008.

C programming language and standard


libraries

Computer Systems: A Programmer's Perspective


(3rd Edition), Bryant and O'Hallaron, 2015.

Low-level programming and systems


environments

All books are reserved in the library

You can use a previous edition

13
Textbooks (Recommended)

The C Programming Language, Kernighan & Ritchie, 1988.

Covers the C programming language

The Practice of Programming, Kernighan & Pike, 1999.

Covers “programming at large”

Programming with GNU Software, Loukides & Oram, 1997.

Covers tools for software development

All books are reserved in the library

You can use a previous edition

14
Manuals

Manuals (for reference only, available online)

Intel 64 and IA-32 Architectures Software Developer's Manual,


Volumes 1-3

Tool Interface Standard & Executable and Linking Format

Using as, the GNU Assembler

Linux man command

short for manual

e.g., man strstr: shows a manual page for strstr()

15
Programming Environment

Haedong Lounge: E3-4, Saenul-dong (새늘동) 1412

Users guide:
https://ee.kaist.ac.kr/student-
facilities-02/

Must read the users guide


before you start using the
machines

16
Programming Environment (cont.)

Linux and all required software are installed

Connect from outside the campus


https://kvpn.kaist.ac.kr/

eelab5.kaist.ac.kr, eelab6.kaist.ac.kr

Your account in haedong lounge


ID: your student id

More information regarding your login ID and password will be uploaded this
week on Campuswire

Change your password (passwd) as soon as possible

If you cannot login, please contact the Haedong lounge TA (staff-


haedong@googlegroups.com)

17
Programming Environment (cont.)

Did I ask if you’re taking EE485A? 


EE485: Introduction to Environment and Tools for Modern Software
Development (1-credit, Letter Grade)

EE485 is meant to replace the precept materials in the past, and we no longer
provide “precept” materials from this course

Strongly recommend you to sign up for EE485 if you haven’t

First thing to do
Log in with your account, and change your password

Use ‘passwd’ command to change your password

You only need to change once – all machines will be automatically updated

More on this in the EE485 course

18
Programming Environment (cont.)
One Option (highly recommended)

Use your own computer

run GNU tools to run your programs locally

– e.g., Install Linux

– e.g., Install Linux subsystem on Windows

– e.g., Install Linux on VMWare Player on Windows

Another Option (not recommended)

Use your own computer

run a non-GNU development environment locally

run your programs locally

– e.g., Visual C++

19
Programming Environment: Notes

We test your program on our Lab machines

– Cannot give grade if your program works on your local machine but
does not run on our Lab machines

Our recommendation:

Use local environment for coding

Use lab environment for testing & debugging

EE485A provides setup instructions

20
Grading

Letter grade only!!!

Midterm 20%

Final 20%

Programming Assignments 55%

Contribution 5%

21
Programming Assignments

Five programming assignments


1. A word counting program

2. String manipulation

3. Hash table, due

4. x86-64 assembly language programs

5. A Unix shell

Assignments #1-4: individual

Assignment #5: team of two members allowed; a single member team gets
20% extra credit

22
Grading: Assignments

Assignment grading
Working code

Clean, readable, maintainable code

On time (no late submissions accepted)

Extra credits may be available for some assignments

Recommended reading: Ten simple rules for writing and sharing


computational analyses in Jupyter Notebooks

Warning! Automatic F for cheating and plagiarism in the assignment and


exams

23
Grading: Contribution

Actively participate in classes and discussions

Ask questions, tell us your thoughts, share your experience, etc.

Both in-class and online Q&A, discussion

More participation  more fun!

If you greatly contribute to the class discussion, you could get extra credit

Contribution could be the difference maker in final grades

24
Attendance

There is no attendance score

But if you don’t attend, you won’t be able to contribute to the class

If you have a legitimate reason for not attending a class, provide me with
the reason and proof in advance

25
Asking for Help

1. Use campuswire: we’ll try to answer your questions as soon as possible

2. Consult with the professor (office hour) and/or TAs (Q&A session) directly

Good: figure out the symptoms of your problem first, and explain to the
TAs in detail what you want

Bad: just give your code to TAs by email, and ask them to figure out what
the problem is – we can’t help you this way

We’ll try hard to help you succeed in this course!

Don’t be shy, but be courteous to the TAs

26
Getting a Good Grade for EE209

Internalize the basic material first


Know the basic grammar: C types, loops, structures, arrays, strings, pointers,
static functions, C runtime library functions, etc.

Read class materials before each class

Allocate some time for EE209


(At least) 7-10 hours per week on EE209

Systematic approach would dramatically reduce debugging time

Consult with TAs and Professors


Don’t be shy: ask the TAs before it’s too late

Office hours with the Professors (or make an appointment)

27
Course Policies

Letter grade only (you’ll thank us later)

Try your absolute best to ask questions in English

All (including assignments, exams, questions) your writing must be in


English

No auditing. Either you’re in or you’re out

If you cheat (including plagiarism), you get an F. No exceptions.


For your assignments and exams, we thoroughly check plagiarism

Don’t test your luck, we have caught many students in the past

Don’t copy the code from your predecessors or across the sessions (we have
all the code)

Don’t risk it. It’s not worth it.

28
Course Policies

Students can use two late submission tokens which can be late up to one
day with penalty for the programming assignments.

That is, you can use your tokens for a total of two assignments. Your token
will be used automatically, i.e., the token is applied to the first two
assignments you submit late. With your tokens, you can submit your
assignment with the following penalty.
95% of the full credit up to 1 hour late,

80% of the full credit up to 24 hours late,

0% of the full credit beyond 24 hours late.

Important:
Any late submission without token will result in zero credit.

We not accept late submission for the last assignment (assignment 5).

29
What is cheating?

Sharing the code


Looking at anyone else’s work during, before, or after the assignment time
period

Allowing anyone to view your work during, before, or after the assignment time
period

Coaching
Helping your friend to write a lab, line by line

Copying or purchasing code from previous course or from elsewhere on


the Internet
Do not Google (or search) code/algorithm directly relevant to the
assignment

In short, not doing your work entirely by yourself

30
What is NOT cheating?

Explaining how to use systems or tools

Explaining what is meant by the specifications

Looking at output and telling whether it is correct or not

Googling basic C grammar, function usage, etc.

In your assignment “readme” file, acknowledge all resources used

Whenever you are not sure, ask TAs or the professor (don’t guess)

31
Why should I take this course?

Software, including AI, is taking over the world!!!


Hottest industry: Google, Facebook, Amazon, NetFlix, Zoom, Tesla, etc.

Avg base salary for SWE in SF is > $145K USD

Even professors are heavily recruited by the industry

32
Why should I take this course?

More Computer Division courses:


Big data analysis

Computer architectures / operating systems

Computer networks / mobile computing

Data structures

and many more (https://ee.kaist.ac.kr/curr_gridv2)

EE209 is a starting point!

33
Course Goal 1: Large-scale Programming

How to write large computer programs


Abstraction; Interfaces and implementations

Specifically, how to:


Write modular code

Hide information, manage resources, handle errors

Write portable code (runs everywhere)

Test and debug your code

Improve your code’s performance (and when to do so)

Use tools to achieve them

34
Course Goal 2: “Under the Hood”

Learn “under the hood” of computer systems

Specifically, two downward tours

C Language Application Program


language service
levels levels
Assembly Language tour Operating System tour

Machine Language Hardware

Goal 2 supports Goal 1


Reveals many examples of effective abstractions

35
Course Goal 2: “Under the Hood”

Learn “under the hood” of computer systems

Specifically, two downward tours

C Language Application Program


language service
Assembly Language
levels Operating System
levels
tour tour
Machine Language Hardware

Goal 2 supports Goal 1


Reveals many examples of effective abstractions

36
We’ll use C Programming Language

Q: Why C instead of Python?

A (Short): C supports Goals 1 and 2 better

A (Long):

C is a lower-level language:

More opportunities to create abstractions

C facilitates language levels tour

C is closely related to assembly language

C facilitates service levels tour

Linux is written in C

37
We’ll use C Programming Language

Q: Why C instead of Python?

We can write an OS with C, but not in Python

C is a lot faster than Python

We can write better games with C than in Python


Access to lower level APIs

Access to memory and I/O with low level operations

Please read the articles:


After All These Years, the World is Still Powered by C Programming

Why Python is not the programming language of the future

38
We’ll use Linux OS

Q: Why Linux instead of Microsoft Windows?

A: Linux is good for education and research

Linux is open-sourced and well-specified

A: Linux is good for programming

Linux is a variant of Unix

Unix has a rich open-source programming environment

39
Topics in this course

Basic C programming
C is a flexible, expressive, low-level programming language

Allows you to write any kind of programs

Writing a large program


How to write modular & portable codes

How to test and debug your large programs

Low-level programming
How is your C code translated and run?

Systems environment
What services underlying systems provide?

40
Tentative Schedule

Total: 16 weeks

C programming language: 4-5 weeks

Writing a large program: 2-3 weeks

Midterm: 1 week

Low-level programming: 2 weeks

Systems environment: 5 weeks

Final: 1 week

41
Today’s Class

Overview and logistics


Goals

Staff

Resources

Grading

Policies

Overview of Computers Today

Overview of C Programming Language

42
What does a computer look like today?

General purpose hardware (x86 architecture)

Multicore: 4 ~ 60 cores (tens of CPU cores)

Multiple 10-Gigabit Ethernet (becoming the norm)

43
Trend#1: Smaller and more powerful

ENIAC (1945)
The first computer

IBM mainframe (1969)


Used by NASA for Apollo
11 to land on the moon

Millions of
times faster

Smartphones today

44
Trend#2: Ubiquitous, everywhere

Computers are dominating our lives!

More things are becoming computers


Cars, watches, speakers, pets, … what’s next?

45
Trend#3: Growing to a larger scale

Scale of the “Cloud”


Many machines spread out around the globe

Meta: hundreds of thousands of machines

Microsoft: 4 million servers (~2021)

Google: 2.5 million servers in 2016

Amazon, Google, Meta, and Microsoft spent $37B in 2020Q3

46
Google’s Datacenters
Machines

Rack

47
Internet-based Services

Servers

Cloud

Clients

Smart Devices

Hierarchical Structure
of Internet-based Services

48
Endless applications using cloud

49
Understanding Computer Systems and Software

Cloud computing industry

Software industry

Not only required in software companies, but just about everywhere


Traditional semiconductor industry

SoC chip designers. Device manufacturing, …

Automobile industry

50
Today’s Class

Overview and logistics


Goals

Staffs

Resources

Grading

Policies

Overview of Computers Today

Overview of C Programming Language

51
Design goals of C

Support structured programming

Support development of the Unix OS and tools

As Unix became popular, so did C

Implications for C

Good for system-level programming

But also used for application-level programming

Low-level

Close to assembly language; close to machine language; close to


hardware

Efficiency over portability

53
C Overview (by Dennis Ritchie)

Dennis Ritchie
Creator of C and Unix
Turing Award Winner (1983)

• “C has always been a language that never attempts to tie a programmer


down.”

• “C has always appealed to systems programmers who like the terse,


concise manner in which powerful expressions can be coded.”

• “C allowed programmers to (while sacrificing portability) have direct


access to many machine-level features that would otherwise require the
use of assembly language.”

54
C Overview (by Dennis Ritchie)

“C is quirky, flawed, and an enormous success. While accidents of history


surely helped, it evidently satisfied a need for a system implementation
language efficient enough to displace assembly language, yet sufficiently
abstract and fluent to describe algorithms and interactions in a wide variety
of environments.”

To summarize, C is a general, flexible, and versatile language that allows


you to program (almost) everything

Make applications

Build system software (e.g., operating system)

Directly control machines

55
Hello World
Include
information about
standard library
hello.c:
main()
function:
#include <stdio.h> entry point
of execution
int main(void) {
printf("Hello, world\n");
return 0;
}
Statements of
main are
enclosed in
braces

$ gcc209 hello.c (compile) main() calls


printf()
$ ./a.out (execution) function to
print the
string

56
What is Programming?

Instruct the computer what to do

Program = states + commands to change states

How to organize the program?

Structured programming (C)

Program = a set of subroutines

A subroutine improves clarity and reduces development time

Object-oriented programming (C++, Java)

Program = interactions between objects

Each object maintains states (member variable) through its


interface functions (member functions)

57
C Variable Types

Variable
Name given to a memory area that a program manipulates

Each variable has a type

Character type char x = ‘a’;


int x = 10;
char (8 bit) float x = 3.14;
Integral type
short (16 bit), int (32 bit), long (64 bit on 64-bit OS)

Floating point type


float (32 bit), double (64 bit), long double (128 bit)

Generic type
void * (64 bit on 64-bit OS)

58
Constants, Array, Pointer Type

Constant: identifier whose value doesn’t change

#define MAX 10
const int MAX = 10;
enum {MAX = 10};

Array: a collection of elements of the same type

char c[10];
double pi[5][2];

Pointer: holds a memory address of a variable of some type

int *p;

59
Variables and Pointers

Memory
Variable: int x
1 100
2 102
Pointer: int* p
3 ‘a’
4 ‘b’
5 3.5
6 420

Addresses Stored values

60
Strings and Structures

String: a collection of characters

char *s = “hello world\n”;


char s[12] = “KAIST EE209”;

Structure: a collection of elements whose types can be different

struct student {
int id;
char *name;
};

61
Arithmetic and Logic Operations

Arithmetic operators
+, -, *, /, %, unary -

Logic operators
&&, ||, !

Relational operators
==, !=, >, <, >=, <=

Bitwise operators
>>, <<, &, |, ^

Assignment operators
=, *=, /=, +=, -=, <<=, >>=, =, ^=, |=, %=

https://www.tutorialspoint.com/cprogramming/c_operators.htm

62
Statements

Statement
Statements are fragments of the C program that are executed in sequence.

Informally: a command that takes a specific action

Typically terminated by ; (a terminator)


switch/case statement
Assignment
int i, j; switch (i) {
i = 10; case 1:
i = j = 0; statement1;
break;
case 2:
statement2;
if statement break;
if (i < 0)
statement1; default:
else statement3;
break;
statement2;
}

63
Loop Statements (1)

for statement

int i = 0
for (int i = 0; i < 10; i++){
statement 1;
statement 2; No
i < 10?
}
statement 3; Yes
statement 1
statement 2

i=i+1

statement 3

64
Loop Statements (2)

while statement
i < 10?
No
while (i < 10){
statement 1; Yes
statement 2; statement 1
} statement 2
statement 3;

statement 3

do while statement
statement 1
do { statement 2
statement 1;
statement 2; Yes
} while (i < 10) i < 10?
statement 3;
No
statement 3

65
Loop Statements (3)

break; // get out of the current loop/switch

while (i < 10) {


statement1;
statement2;
break;
}
statement3;

continue; // go to the start of the next round

while (i < 10) {


statement1;
statement2;
continue;
}
statement3;

goto SomeLabel;

66
Function Definition and Call

Function Definition with a Return Statement

int add(int x, int y) {


return x+y;
}

Function Call

int sum = add(3,5);

67
Other Statements

Compound Statements
{
statement1;
statement2;
}

Comments // for readers, ignored by machines

/*
multiple
line
comment
*/

// single line comment

68
Example C Program (w.o/ comments)

1 #include <stdio.h>
2
3
4 int main(void)
5 {
6 float a, b;
7 int c, d, e;
8
9 c = 0;
10 d = 300;
11 e = 20;
12
13 for (a = c; a <= d; a = a + e) {
14 b = (5.0 / 9.0) * (a – 32.0);
15 printf(“%3.0f %6.1f\n”, a, b);
16 }
17 return 0;
18 }

69
Example C Program (w/ comments)

1 #include <stdio.h>
2 /* print Fahrenheit-Celsius table for
3 fahr = 0, 20, …, 300 */
4 int main(void)
5 {
6 float fahr, celsius;
7 int lower, upper, step;
8
9 lower = 0;
10 upper = 300;
11 step = 20;
12
13 for (fahr = lower; fahr <= upper; fahr = fahr + step) {
14 celsius = (5.0 / 9.0) * (fahr – 32.0);
15 printf(“%3.0f %6.1f\n”, fahr, celsius);
16 }
17 return 0;
18 }

70
Summary

Overview of this course


Learn C and programming environments

How to write a large program

Low-level programming

Overview of Computers Today


Data centers and clouds

(Brief) Overview of C language


C was designed for system programming

C variables and statements

Details are upcoming

71
Action items after class

Join EE209 CampusWire


Check your KAIST email inbox, accept invitation for EE209 Campuswire

Email the TAs if you have not received this invitation

Check out the course website:

72
73

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy