You are on page 1of 10

UNIT - I

Block diagram of a computer CPU


Arithmetic and Logic unit (ALU)

Input unit

Control unit
Memory unit

Outp ut unit

1. Input unit: This is the receiving section of the computer. It obtains information from various input devices and places this information at the disposal of the other units. Most information is carried into computers today through keyboards and mouse devices. Information can also be entered by speaking to your computer and by scanning images. 2.Output unit: This is the shipping section of the computer. It takes information that has been processed by the computer and place it on various output devices to make the information available for use. Most information output from computers today is displayed on screens, printed on paper. 3.Memory unit: This is the warehouse section of the computer. It retains information that has been entered through the input devices. This memory unit also retains processed information until that information can be placed on output devices, by the output devices. This Memory unit is also called memory or primary memory. 4.Arithmetic and Logic unit (ALU) : This is manufacturing unit of the computer. It is responsible for performing calculations such as addition, subtraction, division and multiplication. It contains decision mechanisms to find the logical relation between two variables. 5.Control unit: The control unit controls all the component activities of the computer. It sends command and control signals and finds the sequence of instructions to be executed. 6.Central processing unit: Control unit, memory unit and ALU constitute central processing unit

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 1

UNIT - I
OPERATING SYSTEM (OS) An operating is a program which connects the user and the electronic hardware in a computer. It has a set of programs which supervise the activities of a computer and activate the operations of the hardware components such as main memory, disk drives, keyboard, monitor, printer and so on.
key board Mouse Disk drives Monitor

Operating system

user

Applicatio n programs
Three major stages of evolution of OS: 1. Batch processing: performing one task or job at a time. 2. Multiple processing: it involves simultaneous operation of many jobs on the computer. 3. Time sharing system: this OS allow many users to share the computer at a time. PROGRAMMING LANGUAGES There are 3 types of programming languages 1. Machine languages: i) These are the low-level languages directly used by the computer. ii) The instructions of these languages consists of stings of binary digits 0 and 1. iii) These languages do not require translators because machine code will be directly understood by the computer. iv)These languages are machine dependent. 2. Assembly languages: i) Programming in low-level languages is very difficult. Therefore middle-level languages are developed. ii) The instructions of these languages consists mnemonics. Mnemonics are the English like abbreviations to represent the elementary operations of the computer. Example: LOAD A ADD B STORE C iii) Assembly languages require translator programs, called assemblers. Assemblers convert assembly language programs machine level languages. 3. High-level languages: i) To write complex programs in assembly languages is difficult. So high-level languages are developed. ii) In these programs single statements accomplish, that particular task. Example: C = A + B; iii) Translator programs called compilers convert high-level language programs to machine language. iv) PASCAL, FORTRAN,C and C++ are the high level languages.

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 2

UNIT - I
Assembler, Interpreter, Compiler, Loader, Linker

Assembler:
Assembler is software that converts a program written in assembly language into machine code. There is usually one-to-one correspondence between simple assembly statements and machine language instructions. Since the machine language is dependent on the processor architecture, assembly language programs also defer for different architecture.

Interpreter:
Interpreter performs line by line execution of the source code. Interpreter reads source code line by line, converts it into machine understandable form, executes the line, and then proceeds with the next line. Some languages that uses interpreter are BASIC and PYTHON

Compiler:
A program written in high level language has to be converted to a language that computer can understand i.e. binary form. Compiler is software that translates the program written in high level language to machine language. The program written in high level language is called source code and the compiled program is called object code. The compilation process generally involves two parts. Breaking down the source code into small pieces and constructing the object code. The compiler also reports syntax errors, if any in the source program.
Source code

Assembler Interpreter Compiler

Object code

Linker:
A linker is a program that link several object modules and libraries to form a single executable program.

Loader:
Loaders are a part of operating system that brings an executable file residing on disk into memory and starts it running.

Source program
Compiler

Object code Linker

Memory

Loader

Executable code

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 3

UNIT - I

Number systems
There are four types of number systems ,depending on the number of digits used(radix), to represent a number. The base or radix of a number system is defined as the number of digits that it uses to represent the number. s.no 1. 2. 3. 4. Name of number system Decimal number system Binary number system Octal number system Hexadecimal number system Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Numbers used 0 to 9 0 and 1 0 to 7 0 to 9,A,B,C,D,E,F octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Radix or base 10 2 8 16

hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 4

UNIT - I

Binary to decimal 1101012 = ( )10

Octal to decimal 4688 = ( )10

Hexadecimal to decimal ABC16 = ( )10

Decimal to binary
12510 = ( 1111101) 2

Decimal to Octal
123410 = ( 2322)8

Decimal to Hexadecimal 123410 = ( 4D2 ) 16

Hexadecimal to Binary
10AF16 = ( )2

Octal to Binary
7058 = ( )2

Technique: Convert each Technique: Convert each hexadecimal Octal digit to a 3-bit digit to a 4-bit equivalent binary equivalent binaryCBIT Notes Prepared by T. Ratna Reddy. Associate Professor, representation representation

Octal to Hexadecimal 10768 =( )16


Technique: Use Mobile No: 9985 666778 Page 5 binary as an intermediary

UNIT - I

Floating point representation To convert a decimal fraction to another base b, repeated multiplication by base b is done instead of division. Let us take an example that converts a decimal fraction 0.687510 to binary. Decimal to binary Multiplication process integer part 0.6875 X 2 = 1.375 1 0.375 X2 = 0.750 0 0.75X 2 = 1.5 1 0.5X 2 = 1.0 1 Therefore 0.687510 = 0.10112 Input/output

Algorithms and flow charts:


Processing Algorithm is a step by step process to do a particular task. The steps must be clear and definite. By following the steps one should get the final result. Flow chart is the pictorial representation of an algorithm. Flow chart uses various geometrical figures to represent the operations and arrows to show the direction of flow. Following are the commonly used symbols in flowcharts. Start/stop

Checking/decision making

Looping Connector Arrows to represent direction of flow

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 6

UNIT - I
CH AR AC TE RS US ED IN C
Aph abe ts:
The words, which are defined by user, are user-defined words. They can be for variable name function name so on.

Valid
abhilash sum product abc123 ab__12__cd hyderabad (first 8 are recognized) Uppercase letters A to Z

Invalid
23abc _2cd P.V.N. rao Rama rao ab,cd ab-cd auto

Rules of user defined words


1. It must start with an alphabet. 2. Maximum number of characters should not excess 8 (excess are ignored). 3. Second character on wards alphabets, digits or underscores can be used. 4. No special characters are allowed expect underscore. 5. It cannot be a reserved word.

Lowercase letters Numbers: 0 to 9

a to z

Special characters: + - * / \ % |~? !, . ; : & # $ ^ < > = ( ) [ ] { } _ KEY WORDS char double unsigned continue extern if void while switch goto else const

int short for auto struct volatile enum

float signed break static union default

long do case return sizeof register MEMORY CONCEPTS AND DATATYPES Data type is defined as the type of value that can be stored in a variable EXAMPLE

int a;
Variable a is of type int we can store only integer values in a but not float.

Keywords serve as basic building blocks for program statements. Each keyword has a special meaning in C. All these keywords are in lower case letters. As capital or upper case letters and lower case letters are significant in C, all these keywords must be used in lower cases. These key words names should not be used in function names or variable names or identifiers. Keep this list with you for reference, whenever you write programs. No gap should be left in between the letters of a single key word, while using. These key words are also called as reserved words or vocabulary for the language.

float b;
Variable b is of type float we can store only integer values in a but not int.

USER DEFINED WORDS

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 7

UNIT - I
There are several data types in C language.
int 5. double (long float): It takes 8B of memory space. First 52 bits are integer part and next 12 bits are for fractional part. Decimal point is assumed after 52th bit. It is not stored in memory. 6.long double: It takes 10B of memory space. First 65 bits are integer part and next 15 bits are for fractional part. Decimal point is assumed after 65th bit. char

Int (2B)

long unsigned (4B) (2B)

1.int: It takes 2B of memory space that is 16 bits. First bit is sign bit and remaining 15 are magnitude bits. 1 010 1100 0101 0010 sign magnitude
signed char

If the sign bit is zero it is +ve magnitude. If the sign bit is 1 it is -ve magnitude. Maximum integer value is 215 1 = 32767. Minimum integer value is -215 = -32768 Thus integer ranges from 32768 to 32767. 2. long int: To represent a value more than 32767 long is used. It is an extension to Integer it takes 4B of memory space that is 32 bits. First bit is sign bit and remaining 31 are magnitude bits. Maximum value of long integer value is 231 1

unsigned char

(1B)

(1B)

7. unsigned char: It takes 1B of memory space that is 8 bits. There is no sign bit, all 8 are magnitude bits. Maximum value is 28 1 = 255.minimum value is 0. Range of ASCII values is from 0 to 255 8. signed char(or) char: It takes 1B of memory space that is 8 bits. There is one sign bit and 7 are magnitude bits are magnitude bits. Maximum value is 27 1 = 127. Minimum value is 27 = -128

3. unsigned int : It takes 2B of memory space that is 16 bits. There is no sign bit is sign bit. All 32 bits are magnitude bits. Maximum value unsigned integer is 216 1 = 65535. Minimum value of unsigned integer is 0.
We cannot represent ve values in unsigned character

Type casting
Conversion of one data type to some other data type is known as type casting. That is Conversion of int to float, float to int, int to char so on is called type casting.

1. Implicit type casting


Type casting is done by system.

1. int a = 10.8;
float float value is type casted to int so a = 10, .8 is ignored. 2. float b = 25; int value is type casted to float so b = 25.0 3. char ch = 65; int value is type casted to char so that ch = A. 4. int k = z;

float (4B)

double long double (8B) (10B)

4. float : It takes 4B of memory space. First 26 bits


are integer part and next 6 bits are for fractional part. Decimal point is assumed after 26th bit. It is not stored in memory

xxxxxxxx..xxx ^ xxxxxx
x 0 or 1 26 6

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 8

UNIT - I
character is type casted to int so k = 90. ASCII value of z.

2. Explicit type casting.


Type casting is done by programmer. 1. int a = 7, b = 2; printf (%f, (float)a/b); = 7.0/2 = 3.5 Variable a is of type, it is type casted to float so a becomes 7.0 . The value of a continues to be 7 in the rest of the program. Thus type casting is not for entire program a/b is 3. (float)a/b = 3.5 a/(float) b = 7/2.0 = 3.5 2. float a = 9.8 , b = 5.9; printf (%d, (int)a%(int)b); = 9 %5 = 4 Variables a and b of type float. They are type casted to int. They become 9 and 5. a % b is error since %is integer operator. So they must be type casted to int. int a; It is declaration statement. (int) a is type casting.

int float char string

%d %f %c %s

Examples 1. printf(%d,x); to display integer value 2. printf(%f,a); to display float value 3. printf(the result is %d,x);
scanf() Function scanf() function is used to read/input values of variables using the standard input device(keyboard). It is an input function. It is call by address function. We must send address to scanf but not variable It has the following form scanf(format string,&v1,&v2,&vn); Where v1, v2, are variables whose values are to be read from the keyboard.

Examples 1. scanf(%d,&x); to read integer value 2. scanf(%f,&a); to read float value 3. scanf(%c,&ch); to read char value 4. scanf(%s,name); to read a string 5. scanf(%d%f,&x,&a); to read an integer value and a float value.

Basic Input and output functions


printf() Function print() function is used to display a string or values of variables using the standard output device(monitor). It has the following forms

printf(control string); printf(control string,v1,v2,vn); where v1,v2 are variables whose values are to be displayed on the screen. Control string is the format string which represents the format specification data type format specifier

// To find the sum of two numbers #include <stdio.h> void main() { int x,y,sum; printf("Enter two numbers\n"); scanf("%d%d",&x,&y); sum = x+y; printf("the sum of %d and %d is %d\n, x,y,sum); }

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778 Page 9

UNIT - I

S. No 1. 2. 3.

Data Type char Int int

Format specifier %c %i %d

Remark Signed character Signed integer Signed integer in decimal number system Unsigned integer in octal number system Unsigned integer in decimal number system Unsigned integer in hexadecimal number system Unsigned integer in hexadecimal number system Signed long Signed short Unsigned long Unsigned short Signed single precision Signed single precision in e format(exponent) Signed single precision in E format(exponent) Signed value either in e or f format Signed value either in E or F format Signed double precision float string

4. 5.

unsigned int unsigned int unsigned int unsigned int long int short int unsigned long unsigned short float float float float float double string type

%o %u

6.

%x

7.

%X

8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.

%ld %hd %lu %hu %f %e %E %g %G %lf %s

Notes Prepared by T. Ratna Reddy.

Associate Professor, CBIT

Mobile No: 9985 666778Page 10