360 likes | 390 Views
INC 161 , CPE 100 Computer Programming. Lecturer Associate Prof. Dr. Poj Tangamchit. About the Instructor. Office: CB40603 (CB4 6 th floor) Control System and Instrumentation Eng. (INC) Tel: x-9094 E-mail: poj.tan@kmutt.ac.th Research Interest: Robotics, Artificial Intelligence (AI).
E N D
INC 161 , CPE 100Computer Programming Lecturer Associate Prof. Dr. Poj Tangamchit
About the Instructor Office: CB40603 (CB4 6th floor) Control System and Instrumentation Eng. (INC) Tel: x-9094 E-mail: poj.tan@kmutt.ac.th Research Interest: Robotics, Artificial Intelligence (AI)
Course Details • 3 Credits 2 credits Lecture + 1 credits Practice • Class time 4 hours / week • 2 hours lecture + 2 hours lab • Review + Homework 6-12 hours/week • Teaching Style = Self Lecture + Practice
Scoring & Grading Midterm Exam 40% Final Exam 40% Homework 15% In-class attendance 5 % Grading follows the faculty of Engineering’s standard procedure.
Homework & Assignment Homework takes time. Allocate 6-12 hours each week for it. Students need self-practice outside class time.
Copy of Homework (Plagiarism) Students should do their homework separately. If two or more students have similar homework, they will get homework score = -100%, no matter who is the original. Program codes will bechecked byINC-MOSS (Measure Of Software Similarity developed by INC) This is our standard used for judge copying.
Textbooks Schaum's Outline of Programming with C, 2nd Edition By Byron S. Gottfried ISBN-139780070240353
Class Webpage http://www.inc.eng.kmutt.ac.th/inc161 • Announcement • Lecture Slides Facebook discussion group https://www.facebook.com/groups/138077300115052/
What is a computer? Computer = Data Processing Machine
Why computers are important? • Document Processing • High-Tech Machine Control • Mobile Embedded Devices
HDD, Ram, Cache are data storage CPU is data processing unit Hard disk Ram Cache CPU
Real Worldrepresentation of data ‘0’ is represented by voltage 0 volts ‘1’ is represented by voltage 5 volts (TTL level)
How much data? 1 bit = 1 unit of data (can be represent as ‘0’ or ‘1’) 1 byte = 8 bit 1 kilobyte = 1024 bytes 1 megabyte = 1024 kilobytes
‘0’ and ‘1’ can represent everything • Number - 33, 55, 1.2332 • Word, Sentence - .txt .doc • Picture - .jpg .bmp • Video - .mpg .avi • Sound - .wav .mp3
Functionality of the CPU Command 001101110101 Input 0011010101 0101010000 1001010101 0101010001 0101010110 0010101000 Output CPU 001101110101 010101011000
The purpose of this course Know how to give commands to the CPU to make it work as we want. Command 001101110101 Input 0011010101 0101010000 1001010101 0101010001 0101010110 0010101000 Output CPU 001101110101 010101011000
Machine Language(Code)for 32-bit OS 32 digits Add - 01010010010100100101001001010010 Subtract- 11010110110100100101001001010111 Multiply- 00010110100100100100001001010000 Division- 10010010110100100101001000010001 : :
Hard to remember? Suppose we want to command the CPU Add Add Subtract Multiply What is the code?
Compiler Compiler translates a language to machine code. 010101000010010101010010001010101010010101010100001010010010100 Add Add Subtract Compiler
Computer Programming Languages Three types of programming languages • Machine code or machine languages A sequence of 0’s and 1’s giving machine specific instructions Example: 00011001 2. Assembly language Using meaningful symbols to represent machine code. Example: add hl,de Assembler: Assembly code machine code Disassembler: machine code assembly code
Computer Programming Languages 3. High-level languages Similar to everyday English and use mathematical notations (processed by compilers or interpreters) Example of a C statement: a = a + 8;
Computer Programming Languages 3. High-level languages Similar to everyday English and use mathematical notations (processed by compilers or interpreters) Example of a C statement: a = a + 8;
Comparison of High-Level Language with Machine Code and Assembly Code The memory addresses, machine code, and assembly code corresponding to a C statement a = a + 8 for the Rabbit 3000 8-bit microprocessor. Memory address Machine code Assembly code ------------------------------------------------------------------------------------- 0X1EA1 000100010000100000000000 ld de,0x0008 0X1EA4 1100010000000000 ld hl,(sp+0) 0X1EA6 00011001 add hl,de 0X1EA7 1101010000000000 ld (sp+0),hl
Topics • Expression • Operation • Flow Control • if for while • Function • Data type: int float char • Array • Pointer • Structure Command 001101110101 Input 0011010101 0101010000 1001010101 0101010001 0101010110 0010101000 Output CPU 001101110101 010101011000
How can we give commands to a computer? By running the program .exe = executable program .txt = text file .jpg = pictures .avi = audio+video file
Command Compiler translates a language to machine code. 010101000010010101010010001010101010010101010100001010010010100 Add Add Subtract Compiler Learn this format
C Program Structure main () { } Put commands in here
Variable Declaration We can define a part of memory to store data. We can give a name to it. Later, we can refer to it by this name. However, a name must not be reserved words.
int = integer float = floating point char = character Follow with variable name e.g. int a; (Every command in C must end with semi-colon)
Sample Program main () { int i; float val; char ww; }
Inside Memory ww val 001111111 00110000 00000000 i Cache, Ram, HDD
Comments Comments of a C program can be enclosed within a pair of delimiters /* and */. The symbol // will comment out a subsequent text terminated at the end of a line. /* This is a comment */ /* This is a comment across multiple lines */ printf(”Hello, world\n”);// This is a comment (terminated at the end of line)