UNIT - I. Block diagram of a computer. Arithmetic and Logic unit (ALU) Control. unit. Memory unit

Similar documents
Sources: On the Web: Slides will be available on:

The programming language C. sws1 1

Informatica e Sistemi in Tempo Reale

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Number Representation

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

2011, The McGraw-Hill Companies, Inc. Chapter 3

I PUC - Computer Science. Practical s Syllabus. Contents

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

C++ Programming Language

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Pemrograman Dasar. Basic Elements Of Java

CSI 333 Lecture 1 Number Systems

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Computer Programming Tutorial

The string of digits in the binary number system represents the quantity

B.Sc.(Computer Science) and. B.Sc.(IT) Effective From July 2011

The C Programming Language course syllabus associate level

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Lecture 11: Number Systems

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Chapter 1: Digital Systems and Binary Numbers

Copyright 2012 Pearson Education, Inc. Chapter 1 INTRODUCTION TO COMPUTING AND ENGINEERING PROBLEM SOLVING

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Numbering Systems. InThisAppendix...

So far we have considered only numeric processing, i.e. processing of numeric data represented

Management Challenge. Managing Hardware Assets. Central Processing Unit. What is a Computer System?

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 4: Computer Codes

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Chapter One Introduction to Programming

DNA Data and Program Representation. Alexandre David

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

1 Classical Universal Computer 3

Lecture 7: Programming for the Arduino

C++ Language Tutorial

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Keil C51 Cross Compiler

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Useful Number Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

MICROPROCESSOR AND MICROCOMPUTER BASICS

Base Conversion written by Cathy Saxton

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Chapter 6: Programming Languages

Programming in Java Course Technology, a part of Cengage Learning.

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Fundamentals of Programming

2 SYSTEM DESCRIPTION TECHNIQUES

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Computer Organization

Introduction to programming

Systems I: Computer Organization and Architecture

How To Write Portable Programs In C

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Beyond the Mouse A Short Course on Programming

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Programming Languages CIS 443

Solution for Homework 2

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Introduction to Java

Fast Arithmetic Coding (FastAC) Implementations

Programming Microcontrollers in C

3. Convert a number from one number system to another

Introduction to Python

CPEN Digital Logic Design Binary Systems

CS 106 Introduction to Computer Science I

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CS 241 Data Organization Coding Standards

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Chapter 2: Elements of Java

Moving from CS 61A Scheme to CS 61B Java

COMPSCI 210. Binary Fractions. Agenda & Reading

Lecture 2. Binary and Hexadecimal Numbers

JavaScript: Control Statements I

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Transcription:

Block diagram of a computer CPU Arithmetic and Logic unit (ALU) Input unit Control Outp ut unit Memory 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

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

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

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 Name of number system Numbers used Radix or base 1. Decimal number system 0 to 9 10 2. Binary number system 0 and 1 2 3. Octal number system 0 to 7 8 4. Hexadecimal number system 0 to 9,A,B,C,D,E,F 16 Decimal binary octal hexadecimal 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778 Page 4

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 Octal to Binary Octal to Hexadecimal 10AF16 = ( )2 7058 = ( )2 Technique: Convert each hexadecimal Technique: Convert each 10768 digit to a 4-bit equivalent binary Octal digit to a 3-bit =( )16 Notes representation Prepared by T. Ratna Reddy. Associate equivalent Professor, binary CBIT Mobile Technique: No: 9985666778 Use Page 5 representation binary as an intermediary

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.6875 10 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.6875 10 = 0.1011 2 Input/output Algorithms and flow charts: 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. Processing Checking/decision making Looping Connector Arrows to represent direction of flow Start/stop Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778 Page 6

abhilash sum product abc123 Valid ab 12 cd hyderabad (first 8 are recognized) Uppercase letters A to Z Numbers: 0 to 9 Special characters: 23abc _2cd Invalid P.V.N. rao Rama rao ab,cd ab-cd auto Lowercase letters a to z 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. 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 underscore s can be used. 4. No special characters are allowed expect underscore. 5. It cannot be a reserved word. + - * / \ % ~?!,. ; : & # $ ^ < > = ( ) [ ] { } _ KEY WORDS int float char double long short signed unsigned while do for break continue switch case auto static extern goto return struct union if else sizeof volatile default void const register enum 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. USER DEFINED WORDS 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. float b; Variable b is of type float we can store only integer values in a but not int. Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778 Page 7

There are several data types in C language. int Int long unsigned (2B) (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 If the sign bit is zero it is +ve magnitude. If the sign bit is 1 it is -ve magnitude. Maximum integer value is 2 15 1 = 32767. Minimum integer value is -2 15 = -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 2 31 1 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 2 16 1 = 65535. Minimum value of unsigned integer is 0. We cannot represent ve values in unsigned character float 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 52 th 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 65 th bit. signed char (1B) char unsigned char (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 2 8 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 2 7 1 = 127. Minimum value is 2 7 = -128 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 value is type casted to int so a = 10,.8 is ignored. float double long double (4B) (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 26 th bit. It is not stored in memory xxxxxxxx..xxx ^ xxxxxx x 0 or 1 26 6 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 ; Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778 Page 8

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. 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 int %d float %f char %c string %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. // 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

S. Data Format Remark No Type specifier 1. char %c Signed character 2. Int %i Signed integer 3. int %d Signed integer in decimal number system 4. unsigned int %o Unsigned integer in octal number system 5. unsigned int %u Unsigned integer in decimal number system 6. unsigned int 7. unsigned int %x Unsigned integer in hexadecimal number system %X Unsigned integer in hexadecimal number system 8. long int %ld Signed long 9. short int %hd Signed short 10. unsigned %lu Unsigned long long 11. unsigned %hu Unsigned short short 12. float %f Signed single precision 13. float %e Signed single precision in e format(exponent) 14. float %E Signed single precision in E format(exponent) 15. float %g Signed value either in e or f format 16. float %G Signed value either in E or F format 17. double %lf Signed double precision float 18. string type %s string Notes Prepared by T. Ratna Reddy. Associate Professor, CBIT Mobile No: 9985 666778Page 10