Q
APS105 Lecture 2 Notes
Last Lecture : Introduction to the course
Today : O Introduce Basic Computer Structure
② write a
simple (program that
takes input from the user and
prints output
To context how C
give a on
your
program
Sits in the computer system , let's
& introduce basic computer structure
A
sequence of instructions executed performed by computer
or the
Software
-
Applications
e
g. Games ,
.
your C-program
operating
↓
UNIX
syn now
Operating System (OS) provides : an interface between
applications and computer hardware .
↓
↑ executes instructions
②
Hardware
native /machine code
-
in
(in Os and Is) e g add C
·
.
.
numbers
#uni
g
Devices
% connects the
#Memory
computer system
to the user/world .
/ &
Keyboard
Input
e :
stores data and g
.
.
programs
we want to execute. Instructions
output monitor
:
in can be sent to CPU
programs
for execution.
How is the data and programs/instructions
stored ?
Data and programs are encoded in
binary (0and).
⑤
We develop a
program in a
programming language ,
not Os and Is . When we
develop a
program in C,
we start
by
D Edit ② Compile ③ Run
& hello .
back to
editting I
any change
in c file >
-
requires compilation
not only
again ,
running
Write a C that takes from the user the
program in
number of pizzas and outputs how slices
, many
we have in total ?
Assumption : 1 pizza = 8 slices
I
# include < stdio h > .
>
-
standard
library providing
to
access
printf and
scanf
int main (void)3 >
-
every (program
has a main
-
-
input ↓on where it starts
·mil
main
for them
memory
printf("Enter number of pizzas : ") ;
↑
text
displays on screen
inputgot
input
i n is
man
scant ("o"
T the user entered
format specifer expects int
output input = * 8; - store in output in main
8
the value
input *
memory
printf("We have ices from % d pizzas In
pas -
imports
prints input
output output) ;
prints
newline
rehn Ostopste programa
⑤
In
binary :
Small ruit : a bit (either 0 or 1)
Byte (B) : 8 bits
kiloByle (kB) : 1024 B
Mega Byte (MB) : 1024 KB
Giga Byle (9B) : 1024 MB
For example to
represent decimal number
,
a as
binary
Decimal Number Binary Number (Os or 1s)
1 bit -
representsI
000habits
I
O
I 001 21biny #s
2
-
represent a
4 #S
O 1 I
3
I zzbity
3 bits
4 100 >
- -
represent
7
5 10 I 8 #s
6 110
#
bits
23
7
11 I
bits
represent o
n -
e Ebits 3
represent
.
g
.
0-2
2 -
1
255
28 #S
⑥
Data and main stored in
programs in
memory are
binary
.
How are all these Os and Is
organized ?
Information is
organized into cells. Each cell hold
Each address , hence
7 Byte . cell has an the
"
memory is
"byle-addressable " Addresses too are
represented in binary
.
on .
addresses 32-bits
using ,
many different
= 23 addresses
,
each address accesses
1 byte of information .
Total
memory space is
232 * 1
byle = 22 . 210. 20
.1 byte
#B
#MB
4 G B(too little)
In modern computers ,
addresses are 64-bits .
But don't all what 64 bits address
they use can