Computer Architecture & Programming Languages PDF
Document Details
Uploaded by LovelyForesight7334
Tags
Summary
This document provides a comprehensive overview of fundamental computer architecture concepts, including details of the Von Neumann model, memory units (primary and secondary), and various types of programming languages.
Full Transcript
Module 1 Basics of Computer architecture: Von-Neumann Architecture-Processor, Memory, Input and Output devices. Types of Programming Languages: System Software, Application Software, Compilers, Interpreters, High level and Low-level languages. Introduction to structured programming: Algori...
Module 1 Basics of Computer architecture: Von-Neumann Architecture-Processor, Memory, Input and Output devices. Types of Programming Languages: System Software, Application Software, Compilers, Interpreters, High level and Low-level languages. Introduction to structured programming: Algorithm, flowcharts and Pseudo-code -Examples Computer Is an electronic device that accepts data from the user ,process the data by performing calculations and operations on it and generate desired output. Hardware : Physical part of the computer Software : set of instructions that tells the computer about the tasks to be performed and how these tasks to be performed. Data : Provided as input User : People who Interact with Computer. BASICS OF COMPUTER ARCHITECTURE Von-Neumann Architecture Von-Neumann proposed his computer architecture design in 1945 which was later known as Von-Neumann Architecture. It consisted of a Control Unit, Arithmetic, and Logical Memory Unit (ALU), Registers and Inputs/Outputs. Von Neumann architecture is based on the stored-program computer concept, where instructions, data and program data are stored in the same memory. Programs are collection of software instructions understandable by CPU. Data are information stored in computer hard disk. Von-Neumann Architecture Components of Von-Neumann Model Central Processing Unit Memory Unit Input Unit Output Unit Central Processing Unit The part of the Computer that performs the bulk of data processing operations is called the Central Processing Unit and is referred to as the CPU. The Central Processing Unit can also be defined as an electric circuit responsible for executing the instructions of a computer program. The major components of CPU : Arithmetic and Logic Unit (ALU) Control Unit (CU). A variety of registers. Arithmetic and Logic Unit (ALU) Performs arithmetic operations and conducts the comparison of information for logical decisions. In simple words, ALU allows arithmetic (add, subtract, etc.) and logic (AND, OR, NOT, etc.) operations to be carried out. Control Unit The Control Unit of a computer system controls the operations of components like ALU, memory and input/output devices. Responsible for sending/receiving control signals from and to all components CPU Registers BUSES Buses are the means by which information is shared between the registers in a multiple-register configuration system. A bus structure consists of a set of common lines, one for each bit of a register, through which binary information is transferred one at a time. Von-Neumann Architecture comprised of three major bus systems for data transfer. Von-Neumann Architecture comprised of three major bus systems for data transfer Types of Buses Bus Description Address Bus Address Bus carries the address of data (but not the data) between the processor and the memory. Data Bus Data Bus carries data between the processor, the memory unit and the input/output devices. Control Bus Control Bus carries signals/commands from the CPU. Memory Unit The memory stores binary information in groups of bits called words. The internal structure of a memory unit is specified by the number of words it contains and the number of bits in each word. Classified into two: 1. Primary Memory 2. Secondary Memory Primary Memory It is also known as the main memory of the computer system. It is used to store data and programs or instructions during computer operations. It uses semiconductor technology and hence is commonly called semiconductor memory. Relatively faster, less costly Primary memory is of two types: i. Read Only Memory (ROM) ii. Random Access Memory (RAM) RAM (Random Access Memory): It is a volatile memory. Volatile memory stores information based on the power supply. If the power supply fails/ interrupted/stopped, all the data and information on this memory will be lost. RAM is used for booting up or start the computer. It temporarily stores programs/data which has to be executed by the processor. Types of RAM :Static RAM and Dynamic RAM. ROM (Read Only It is a non-volatile memory. Memory) Non-volatile memory stores information even when there is a power supply failed/ interrupted/stopped. ROM is used to store information that is used to operate the system. As its name refers to read-only memory, we can only read the programs and data that is stored on it. It contains some electronic fuses that can be programmed for a piece of specific information. The information stored in the ROM in binary format. It is also known as permanent memory. Different types of ROM : PROM (Programmable Read Only Memory) EPROM (Erasable Programmable Read Only Memory) EEPROM (Electrically Erasable Programmable Read Only Memory) ROM Secondary Memory It is also known as auxiliary memory and backup memory. It is a non-volatile memory and used to store a large amount of data or information. The data or information stored in secondary memory is permanent, and it is slower than primary memory. A CPU cannot access secondary memory directly. The data/information from the auxiliary memory is first transferred to the main memory, and then the CPU can access it. Memory Hierarchy Memory hierarchy is arranging different kinds of storage present on a computing device based on speed of access. At the very top, the highest performing storage is CPU registers which are the fastest to read and write to. Registers. Smallest memory location in CPU. The register is usually a static RAM or SRAM in the computer’s processor that holds the data word, normally 64 or 128 bits. The essential register is the program counter register, which is found in all processors. In addition, a status word register and an accumulator are used by the majority of CPUs. Cache Memory The cache is used for storing segments of programs currently being executed in the CPU and temporary data frequently needed in the present calculations. Placed between RAM and CPU. During processing, CPU will first checks the Cache memory for required data ,if not found ,it will search the RAM Main Memory As per the memory hierarchy, the main memory is level 2. The main memory refers to the physical memory, one central storage unit in a computer system. The main memory is relatively large and fast memory used to store programs and data during computer operation. Auxiliary Memory A computer system's auxiliary memory is the lowest-cost, highest-capacity, and slowest-access storage. Auxiliary memory is used to store programs and data that are stored for long periods or are not in use right away. Magnetic Disks A magnetic disk is a circular plate constructed of metal or plastic coated with magnetized material. Magnetic Tapes A magnetic tape is a magnetic recording medium made of a thin magnetizable coating on a long, narrow strip of plastic film. APPLICATION SOFTWARE & SYSTEM SOFTWARE Software is a set of instructions or commands that tells a user how to do and what to do. Types of Software 1. System Software 2. Application Software. System Software: is the type of software that is the interface between application software and the system. System Software maintains the system resources and gives the path for application software to run. An important thing is that without system software, the system can not run. It is general-purpose software. Application Software:Application Software is a type of software that is mainly developed to perform a specific task as per the user's request. This software is usually developed with the help of High-level languages, such as C, C++, Java, etc. Some examples of Application software are MS Office, Paint, Spreadsheet, Web-browser, etc. PROGRAMMING LANGUAGES TYPES OF LANGUAGES Computer programs can be written in high and low level languages, depending on the task and the hardware being used. Computer only understood Binary language(comprising of zeros and ones) LOW LEVEL LANGUAGE (MACHINE LANGUAGE) A program written in machine language is a collection of binary digits or bits ( 0 and 1) the computer reads and interprets. Features The computer can understand the programs written in machine language directly. No translation of the program is needed. Program written in machine language can be executed very fast (Since no translation is required). Machine language is defined by the hardware of a computer. It depends on the type of the processor or processor family that the computer uses, and is thus machine-dependent. A machine- level program written on one computer may not work on another computer with a different processor. It is difficult to write a program in machine language as it has to be written in binary code. Such programs are also difficult to modify. Error occurring chance is high ASSEMBLY LANGUAGE A program written in assembly language uses symbolic representation of machine codes needed to program a particular processor (CPU) or processor family. This representation is usually defined by the CPU manufacturer, and is based on abbreviations (called mnemonics that help the programmer remember individual instructions, registers, etc. Small, English-like representation is used to write the program in assembly language Features Assembly language programs are easier to write than the machine language programs, since assembly language programs use short, English-like representation of machine code. The program written in assembly language is the source code, which has to be converted into machine code, also called object code, using translator software, namely, assembler. Each line of the assembly language program is converted into one or more lines of machine code. Hence assembly language programs are also machine-dependent. Example of Assembly Language : ADD 2, 3 LOAD A SUB A, B HIGH LEVEL LANGUAGE High level languages are written in a form that is close to human language, enabling the programmer to just focus on the problem being solved. Features Programs are easier to write, read or understand in high-level language Programs written in high-level languages is the source code which is converted into the object code (machine code) using translator software like interpreter or compiler. A line of code in high-level program may correspond to more than one line of machine code. Programs written in high-level languages are easily portable from one computer to another. Example: C, C++, Java, python SYSTEM TRANSLATORS A translator is a programming language processor that converts a computer program from one language to another. It takes a program written in source code and converts it into machine code. It discovers and identifies the error during translation. There are 3 different types of translators as follows: Compiler Intepreter Assembler COMPILER A compiler is a translator used to convert high-level language to machine language. INTERPRETER Interpreter is a translator used to convert high-level programming language to low-level programming language. Example: Python, jvm(Java Virtual Machine) ∙ ASSEMBLER An assembler is a translator used to translate assembly language to machine language. ALGORITHM AND FLOWCHART ALGORITHM Algorithm A set of finite rules or instructions to be followed in calculations or other problem-solving operations. Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning. Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs. It may or may not take input. Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well. It should produce at least 1 output. Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time. Feasible: The algorithm must be simple, generic, and practical, such that it can be executed with the available resources. It must not contain some future technology or anything. Language Independent: The Algorithm designed must be language-independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be the same, as expected. Input: An algorithm has zero or more inputs. Each that contains a fundamental operator must accept zero or more inputs. Output: An algorithm produces at least one output. Every instruction that contains a fundamental operator must accept zero or more inputs. Definiteness: All instructions in an algorithm must be unambiguous, precise, and easy to interpret. By referring to any of the instructions in an algorithm one can clearly understand what is to be done. Every fundamental operator in instruction must be defined without any ambiguity. Finiteness: An algorithm must terminate after a finite number of steps in all test cases. Every instruction which contains a fundamental operator must be terminated within a finite amount of time. Infinite loops or recursive functions without base conditions do not possess finiteness. Effectiveness: An algorithm must be developed by using very basic, simple, and feasible operations so that one can trace it out by using just paper and pencil. GENERAL RULES Step Numbers should be written. First step in algorithm is Start and last statement is Stop To read a value from user : Write the statement “Read” To write a value as output : Write the statement “Print or Display” Write an algorithm to read two numbers and display the numbers Step 1: START Step 2: Read the two numbers and assign the values to variables A and B. Step 3: Display A and B Step 4 : STOP Write an algorithm to find the sum of 3 numbers Step 1: START Step 2: Read the three numbers and assign the values to variables A, B and C Step 3: Add values in A , B and C and assign the result to sum Step 4: Display sum. Step 6 : STOP Write an algorithm to find the sum and average of 3 numbers Step 1: START Step 2: Read the three numbers and assign the values to variables A, B and C Step 3: Add values in A , B and C and assign the result to sum Step 4: Sum is divided by 3 and assign the result to avg Step 5: Display sum, avg Step 6 : STOP Write an algorithm to calculate the Interest of a Bank Deposit Step 1: START Step 2: Read Amount and assign the value to variable Amount. Step 3: Read Years and assign the value to variable years. Step 4: Read Rate and assign the value to variable Rate. Step 5: Calculate the interest with formula, Interest=Amount*Years*Rate/100 Step 6 : Print Interest Step 7: STOP Write an algorithm to find the largest of 2 numbers Step 1: START Step 2: Read the two numbers and assign the value to variables A and B. Step 3: Check whether A greater than B if true then Print A is larger otherwise Print B is Larger Step 4:STOP. Write an algorithm to find the largest of 3 numbers Step 1: START Step 2: Read the three numbers and assign the values to variables A, B & C Step 3: Check whether A greater than B if true go to step 3.1 otherwise go to step 4 Step 3.1: Check whether A greater than C, if true Print A otherwise Print C Step 3.2: Go to Step 5 Step 4: Check whether B greater than C, if true Print B otherwise Print C Step5: STOP Write an algorithm to print the first n natural Step 1 : START numbers Step 2 : Read limit of numbers ,assign the value to variable n Step 3 : i=1 Step 4 : Repeat steps 4.1 and 4.2 till i less than or equal to n Step 4.1 Print i Step 4.2 Increment i by 1 Step 5 : STOP Write an algorithm to print odd numbers upto n. Step 1 : START Step 2 : Read limit of numbers ,assign the value to variable n Step 3 : i=0 Step 4 : Repeat steps 4.1 and 4.2 till i less than or equal to n Step 4.1 Print i Step 4.2 Compute i=i+2 Step 5 : STOP Write an algorithm to find the sum of n natural Step 1 : START numbers Step 2 : Read limit of numbers ,assign the value to variable n Step 3 : Assign sum=0 and i=1 Step 4 : Repeat steps 4.1 and 4.2 till i less than equal to n Step 4.1 : Calculate sum=sum+i Step 4.2 : Increment i by 1 Step 5 : Print sum Step 6 : STOP FLOW CHART ❑ Symbols used: i. Terminal ✔ Used to indicate the beginning (START), ending (STOP) and passes (HALT) in the program logic flow ✔ First and last symbol ii. Input/Output ✔ Denotes any function of an I/O device in the program iii. Processing ✔ represents arithmetic and data movement instructions ✔ For e.g.: a= b+6 a=c iii. Decision ✔ Used as decision symbols and is used to indicate a point at which a decision has to be made and a branch to one of two or more alternative points is possible v. Flow lines ✔ To indicate the flow of operation vi. Connector “exit to” “entry from” Draw a flowchart to display the sum and average of 3 numbers Draw a flowchart to calculate & display interest Flowchart to find the largest of two numbers. Draw a flowchart to display the largest of three numbers Draw a flowchart to find the sum of n natural numbers QUESTIONS : ALGORITHM Write an algorithm to check whether number is odd or not. Step1 : START Step2 :Read the number and assign the value to the variable n Step 3:Check whether the remainder of n divided by 2 is 0 if true print n is even Otherwise print n is odd. Step 4: STOP Write an algorithm to check whether a person is eligible for voting or not. Step1 : START Step2 :Read the age and assign the value to the variable X. Step 3:Check whether the X is greater than or equal to 0 if true print the person is eligible for voting Otherwise print the person is not eligible for voting Step 4: STOP Write an algorithm to check whether the number is prime or not Step1 :Start Step 2: Read the number and assign the value to the variable n Step 3: Assign i=2 Step 4:Repeat steps 4.1 and 4.2 till i less than or equal to n/2 Step 4.1 : check whether remainder of n divided by i equal to 0,if true go to step 6 otherwise go to step 4.2 Step 4.2 :i=i+1 Step 5:Print number is prime and go to step 7 Step 6:Print number is not prime Step 7:STOP Write an algorithm to print the even numbers from 1 to n. Step 1 : START Step 2 : Read limit of numbers ,and assign the values to variable n Step 3 : Assign sum=0 and i=2 Step 4 : Repeat steps 4.1 and 4.2 till i