You are on page 1of 20

Fundamentals: 1

P. P. Chakrabarti

1 09-01-03 P.P.Chakrabarti, IIT Kharagpur


A computer (Level 0 Version)

Input Central
Output
Peripherals Processing
Peripherals
Unit (CPU)

Main
Memory

Storage
Peripherals
2 09-01-03 P.P.Chakrabarti, IIT Kharagpur
Memory: Address and Values

3 09-01-03 P.P.Chakrabarti, IIT Kharagpur


CPU: A first cut

PC
R1
IR
R2
ALU MAR
R3 MDR
R4 FLAGS

4 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Instruction Set Program

? Start
? Read M
0: Start
? Write M
1: Read 10
? Load Data, M
? Copy M1, M2 2: Read 11
? Add M1, M2, M3 3: Add 10, 11, 12
? Sub M1, M2, M3 4: Write 12
? Compare M1, M2, M3 5: Halt
? Jump L
? J_Zero M, L
? Halt

5 09-01-03 P.P.Chakrabarti, IIT Kharagpur


High-Level Programs
0: Start
Variables x, y; 1: Read 20
Begin 2: Read 21
Read (x); 3: Compare 20, 21, 22
Read (y); 4: J_Zero 22, 7
If (x >y) then Write (x) 5: Write 20
else Write (y); 6: Jump 8
End. 7: Write 21
8: Halt

6 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Examples of Software
? Read an integer and ? A Word-processor
determine if it is a prime ? A C language Compiler
number. ? Windows 2000 operating
? A Palindrome recognizer system
? Read in airline route ? Finger-print recognition
information as a matrix and ? Chess Player
determine the shortest time
journey between two ? Speech Recognition
airports ? Language Recognition
? Telephone pole placement ? Discovering New Laws in
problem Mathematics
? Patriot Missile Control ? Automatic drug discovery

7 09-01-03 P.P.Chakrabarti, IIT Kharagpur


First C program - 1
#include <stdio.h>
main ()
{
printf ("Hello, World! \n") ;
}

8 09-01-03 P.P.Chakrabarti, IIT Kharagpur


First C program - 2
#include <stdio.h>
main ()
{
printf ("Hello, World! ") ;
printf ("Hello \n World! \n") ;
}

9 09-01-03 P.P.Chakrabarti, IIT Kharagpur


First C program - 3
#include <stdio.h>
main ()
{
printf ("Hello, World! \n") ;
printf ("Hello \n World! \n") ;
printf ("Hell\no \t World! \n") ;
}

10 09-01-03 P.P.Chakrabarti, IIT Kharagpur


First Program: Reading
? #include <stdio.h>
main ()
{
int num_of_students ;
scanf ("%d", &num_of_students) ;
printf ("%d\n", num_of_students) ;
}

11 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Second C program - 1
#include <stdio.h>
main ()
{
int x;
int y;
x=1;
y=3;
printf("x = %d, y= %d\n", x, y);
}
12 09-01-03 P.P.Chakrabarti, IIT Kharagpur
Variables in Memory
Instruction executed Memory location allocated
to a variable X
X = 10
T
i X = 20 10
m
e
X = X +1

X = X*5

13 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables in Memory
Memory location allocated
Instruction executed to a variable X

X = 10
T
i X = 20 20
m
e
X = X +1

X = X*5

14 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables in Memory
Memory location allocated
Instruction executed to a variable X

X = 10
T
i X = 20 21
m
e
X = X +1

X = X*5

15 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables in Memory
Memory location allocated
Instruction executed to a variable X

X = 10
T
i X = 20 105
m
e
X = X +1

X = X*5

16 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables (contd.)

X = 20
X
Y=15 20

X = Y+3 ? Y

Y=x/6

17 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables (contd.)

X = 20
X
Y=15 20

X = Y+3 15 Y

Y=x/6

18 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables (contd.)

X = 20
X
Y=15 18

X = Y+3 15 Y

Y=x/6

19 09-01-03 P.P.Chakrabarti, IIT Kharagpur


Variables (contd.)

X = 20
X
Y=15 18

X = Y+3 3 Y

Y=X/6

20 09-01-03 P.P.Chakrabarti, IIT Kharagpur

You might also like