Вы находитесь на странице: 1из 39

EEEB114: Principle of Programming for

Engineers
Topic 1: Introduction to Computer and Programming
Objectives
In this chapter you will learn about:
Overview of PC components
Computer Software
C programming language
C program at a glance
Overview of PC Component
Computer Hardware Components
Input / Output Devices

Input Device
1s and 0s
Accepts information
Information
from the user and
transforms it to digital
codes that the
computer can process
Input / Output Devices

Output Device
1s and 0s

Information
An interface by which
the computer conveys
the output to the user
Memory
Memory cells: individual storage
location in memory
Address: the relative position of a
memory cell in the computers main
memory
Contents: the information stored in a
memory cell
Computer only understands binary
digits- bits (1 or 0). Hence, the content
stored are actually bits. Bit

1 Byte (B)= 8 bits (b) | 01110011 |


Byte
Main Memory
A semiconductor device which stores the
information necessary for a program to run.
2 types
RAM (Random Access Memory)
Contains instruction or data needed for a program to
run
Got erased when the computer is turned off (volatile).
ROM (Read Only Memory)
Contains information that is necessary for the
computer to boot up
The information stays there permanently even when
the computer is turned off (non-volatile).
Secondary Storage Devices
Why?
To store permanent/semi-permanent data
Memory is small
Store the software components or data
needed for the computer to execute its tasks.
Could be read only or writable.
Example: Hard drive, CD ROM, flash drive,
floppy disks (???)
Central Processing Unit (CPU)
Generally contains 3 things:
Control Unit
Coordinates computers activities (what to do and the order)
Aritmetic Logic Unit (ALU)
performs arithmetic operation and comparison
Register
High speed memory locations to
store current instructions and data
Network Devices
Connect a computer to the other computers.
Enable the users to access data or execute
programs remotely.
Example: modem, Ethernet card
Computer Software
Operating System (OS)
Software that control interaction of user and computer
hardware
Part of OS is stored in ROM chip:
so that it is available immediately after computer is
switched on
Contains instruction to load the rest of the OS code into
memory from disk (booting)
Application Software
Software used for specific task
For e.g: Word processing, accounting etc
What is Programming?
Programming is instructing a computer to do
something for you with the help of a programming
language
In programming, we deal with two kind of things:
Data - representing 'objects' we want to
manipulate
Procedures -'descriptions' or 'rules' that define
how to manipulate data.
Programming Language
Formal Language used to communicate to
a computer.
A programming language contains
instructions for the computer to perform a
specific action or a specific task:
'Calculate the sum of the numbers from 1 to 10
'Print I like programming
'Output the current time'
Programming Language
Can be classified into as a special-purpose and
general-purpose programming languages.
Special-purpose : is design for a particular type of
application
Structured Query Language (SQL)
General-purpose : can be used to obtain solutions
for many types of problems
Machine Languages
Assembly Languages
High-Level Languages
Machine Language
The only language that the processor actually 'understands
Consists of binary codes: 0 and 1
Example: 00010101
11010001
01001100
Each of the lines above corresponds to a specific task to be
done by the processor.
Programming in machine code is difficult and slow since it
is difficult to memorize all the instructions.
Mistakes can happen very easily.
Processor and Architecture dependent
Assembly Language
Enables machine code to be represented in words and
numbers.
Example of a program in assembler language:
LOAD A, 9999
LOAD B, 8282
SUB B
MOV C, A
LOAD C, #0002
DIV A, C
STORE A, 7002

Easier to understand and memorize (called Mnemonics),


compared to machine code but still quite difficult to use.
Processor and Architecture dependent
High-Level Language
Use more English words. They try to resemble English
sentences. Therefore, it is easier to program in these
languages.
The programming structure is problem oriented - does
not need to know how the computer actually executes the
instructions.
Processor independent - the same code can be run on
different processors.
Examples: Basic, Fortran, Pascal, Cobol, C, C++, Java
A high level language needs to be analyzed by the
compiler and then compiled into machine code so that it
can be executed by the processor.
Steps for high level programming
myprog.c

myprog.obj

myprog.exe
Steps for high level programming
Some computers require users to ask OS to carry out
the steps separately
But most high-level language compilers comes as part
of an Integrated Development Environment (IDE)
IDE: software package combining a word processor,
compiler, linker, loader, and tools for finding errors
Example C IDE: Code::Blocks, Dev-C++
IDE Example (Code::Blocks)
C Programming Language
C Programming Language
Developed by Dennis Ritchie at Bell Laboratories
in the 1972
In cooperation with Ken Thomson it was used for
Unix systems
The C Language was only vaguely defined, not
standardized, so that almost everyone had his own
perception of it, to such an extend that an urgent
need for a standard code was creeping up
C Programming Language
In 1983, the American National Standards
Institute (ANSI) set up X3J11, a Technical
Committee to draft a proposal for the ANSI
standard, which was approved in 1989 and
referred to as the ANSI/ISO 9899 : 1990 or
simply the ANSI C, which is now the global
standard for C.
This standard was updated in 1999; but
there is no compiler yet
C Program at a Glance
Elements of C
preprocessor directive a C program line beginning with #
that provides an instruction to the preprocessor
preprocessor a system program that modifies a C program prior to
its compilation
library a collection of useful functions and symbols that
may be accessed by a program
Function main main function where program execution
begins (every c program has one)
declarations the part of a program that tells the compiler
the names of memory cells in a program
Executable statements program lines that are converted
to machine language instructions and executed by the
computer
Reserved words words that has special meaning in C
etc
A Simple Program in C

#include <stdio.h>

int main()
{
printf("I like programming in C.\n");
return 0;
}
A Simple Program in C - explanation
Preprocessor directive

#include <stdio.h>
standard Library, input-output, header-file

Begin of program

int main()
{ Start of Segment

Function for printing text

printf("I like programming in C.\n");


return 0; Insert a new line End of statement

} End of Segment
C Output

I like programming in C.
Why learn programming?
Why learn programming?

Image source :http://cdn.techgyd.com/2015/02/steve-jobs.png


Why engineers-to-be need to learn programming?
Why engineers-to-be need to learn programming?

Programming
References
Hanly and Koffman, Problem Solving and Program
Design in C
The internet
Appendices
ANSI C Reserved Words
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while