UNIT - 1
Functional blocks of a computer, Data representation
Q1) What is computer architecture explain?
A1)
A computer system is a machine that simplifies complicated tasks. It should maximize performance and reduce costs as well as power consumption. The different components in the Computer System Architecture are Input Unit, Output Unit, Storage Unit, Arithmetic Logic Unit, Control Unit, etc.
A diagram that shows the flow of data between these units is as follows −
The input data travels from the input unit to ALU. Similarly, the computed data travels from ALU to the output unit. The data constantly moves from the storage unit to ALU and back again. This is because stored data is computed before being stored again. The control unit controls all the other units as well as their data.
Details about all the computer units are −
The input unit provides data to the computer system from the outside. So, it links the external environment with the computer. It takes data from the input devices, converts it into machine language, and then loads it into the computer system. Keyboard, mouse, etc. are the most commonly used input devices.
The output unit provides the results of the computer process to the users i.e it links the computer with the external environment. Most of the output data is in the form of audio or video. The different output devices are monitors, printers, speakers, headphones, etc.
The storage unit contains many computer components that are used to store data. It is traditionally divided into primary storage and secondary storage. Primary storage is also known as the main memory and is the memory directly accessible by the CPU. Secondary or external storage is not directly accessible by the CPU. The data from secondary storage needs to be brought into the primary storage before the CPU can use it. Secondary storage contains a large amount of data permanently.
All the calculations related to the computer system are performed by the arithmetic logic unit. It can perform operations like addition, subtraction, multiplication, division, etc. The control unit transfers data from the storage unit to the arithmetic logic unit when calculations need to be performed. The arithmetic logic unit and the control unit together form the central processing unit.
This unit controls all the other units of the computer system and so is known as its central nervous system. It transfers data throughout the computer as required including from the storage unit to the central processing unit and vice versa. The control unit also dictates how the memory, input-output devices, arithmetic logic unit, etc. should behave.
Q2) Explain CPU(Central processing unit)
A2)
Central Processing Unit (CPU) consists of the following features −
CPU itself has the following three components.
Memory or Storage Unit
This unit can store instructions, data, and intermediate results. This unit supplies information to other units of the computer when needed. It is also known as the internal storage unit or the main memory or the primary storage or Random Access Memory (RAM).
Its size affects speed, power, and capability. Primary memory and secondary memory are two types of memories in the computer. Functions of the memory unit are −
Control Unit
This unit controls the operations of all parts of the computer but does not carry out any actual data processing operations.
Functions of this unit are −
ALU (Arithmetic Logic Unit)
This unit consists of two subsections namely,
Arithmetic Section
The function of the arithmetic section is to perform arithmetic operations like addition, subtraction, multiplication, and division. All complex operations are done by making repetitive use of the above operations.
Logic Section
The function of the logic section is to perform logic operations such as comparing, selecting, matching, and merging data.
Q3) Explain memory and its types in detail
A3)
A memory is just like a human brain. It is used to store data and instructions. Computer memory is the storage space in the computer, where data is to be processed and instructions required for processing are stored. The memory is divided into a large number of small parts called cells. Each location or cell has a unique address, which varies from zero to memory size minus one. For example, if the computer has 64k words, then this memory unit has 64 * 1024 = 65536 memory locations. The address of these locations varies from 0 to 65535.
Memory is primarily of three types −
Cache Memory
Cache memory is a very high-speed semiconductor memory that can speed up the CPU. It acts as a buffer between the CPU and the main memory. It is used to hold those parts of data and program which are most frequently used by the CPU. The parts of data and programs are transferred from the disk to cache memory by the operating system, from where the CPU can access them.
Advantages
The advantages of cache memory are as follows −
Disadvantages
The disadvantages of cache memory are as follows −
Primary Memory (Main Memory)
Primary memory holds only those data and instructions on which the computer is currently working. It has a limited capacity and data is lost when power is switched off. It is generally made up of semiconductor devices. These memories are not as fast as registers. The data and instruction required to be processed resides in the main memory. It is divided into two subcategories RAM and ROM.
Characteristics of Main Memory
Secondary Memory
This type of memory is also known as external memory or non-volatile. It is slower than the main memory. These are used for storing data/information permanently. CPU directly does not access these memories, instead, they are accessed via input-output routines. The contents of secondary memories are first transferred to the main memory, and then the CPU can access it. For example, disk, CD-ROM, DVD, etc.
Characteristics of Secondary Memory
Q4) Explain bus topology
A4)
Bus Topology
CSMA: It is a media access control used to control the data flow so that data integrity is maintained, i.e., the packets do not get lost. There are two alternative ways of handling the problems that occur when two nodes send the messages simultaneously.
Advantages of Bus topology:
Disadvantages of Bus topology:
Q5) Explain hard disk drive
A5)
Hard Disk Drive (HDD)
What is a hard disk drive?
Hard disk drives are non-volatile magnetic storage devices capable of remembering vast amounts of data.
An electromagnet in the read/write head changes the disk’s surface with either a positive or negative charge, this is how binary 1 or 0 is represented.
The read/write head is then capable of detecting the magnetic charges left on the disk’s surface, this is how data is read.
The disk surface is divided into concentric circles (tracks) and sectors (wedges). Dividing the surface in this way provides physical addresses to remember where data is saved.
A circuit board carefully co-ordinates the rotating disk and swinging actuator arm to allow the read/write head to access any location very quickly.
Typical HDD capacities are measured in Terabytes (TB).
They can be installed inside a computer or purchased in a portable (external) format.
Typical applications for hard disk drives
Benefits of hard disk drives
Drawbacks of hard disk drives
Q6) Explain RAM in detail
A6)
Random Access Memory (RAM)
What is RAM?
RAM is a computer’s primary memory. It is a very fast solid-state storage medium that is directly accessible by the CPU.
Any open programs or files on a computer are temporarily stored in RAM whilst being used.
Being volatile, any data stored in RAM will be lost when power is removed. This makes RAM unsuitable for the long-term permanent storage of data – that is the role of an HDD or SSD instead.
Data is copied from secondary storage (HDD, SSD) to RAM as and when it is needed. This is because using an HDD as the primary memory would cause a computer to perform much slower (an HDD or SSD is not directly accessible to the CPU, and isn’t as fast as RAM).
RAM is a relatively expensive storage device and typical capacities are measured in Gigabytes (GB).
Computers operating with a capacity of RAM above the recommended minimum will benefit from better performance and multitasking.
There are two types of RAM (SRAM and DRAM), each with its advantages and disadvantages.
Typical applications of RAM
Benefits of RAM
Drawbacks of RAM
Static RAM (SRAM)
Data on SRAM does not require refreshing.
However, the technology is bulkier meaningless memory per chip.
Dynamic RAM (DRAM)
The most common type of RAM in use.
The data needs to be continually refreshed otherwise it fades away.
Continually refreshing the data takes time and reduces performance speeds.
Q7) What is a programming language?
A7)
We assume you are well aware of English Language, which is a well-known Human Interface Language. English has a predefined grammar, which needs to be followed to write English statements correctly. Likewise, most of the Human Interface Languages (Hindi, English, Spanish, French, etc.) are made of several elements like verbs, nouns, adjectives, adverbs, propositions, and conjunctions, etc.
Similar to Human Interface Languages, Computer Programming Languages are also made of several elements. We will take you through the basics of those elements and make you comfortable to use them in various programming languages. These basic elements include −
We will explain all these elements in subsequent chapters with examples using different programming languages. First, we will try to understand the meaning of all these terms in general, and then, we will see how these terms can be used in different programming languages.
This tutorial has been designed to give you an idea about the following most popular programming languages −
A major part of the tutorial has been explained by taking C as a programming language and then we have shown how similar concepts work in Java and Python. So after completion of this tutorial, you will be quite familiar with these popular programming languages.
Q8) What are the types of programming language?
A8)
A programming language defines a set of instructions that are compiled together to perform a specific task by the CPU (Central Processing Unit). The programming language mainly refers to high-level languages such as C, C++, Pascal, Ada, COBOL, etc.
Each programming language contains a unique set of keywords and syntax, which are used to create a set of instructions. Thousands of programming languages have been developed till now, but each language has its specific purpose. These languages vary in the level of abstraction they provide from the hardware. Some programming languages provide less or no abstraction while some provide higher abstraction. Based on the levels of abstraction, they can be classified into two categories:
The image which is given below describes the abstraction level from the hardware. As we can observe from the below image that the machine language provides no abstraction, assembly language provides less abstraction whereas high-level language provides a higher level of abstraction.
Low-level language
The low-level language is a programming language that provides no abstraction from the hardware, and it is represented in 0 or 1 forms, which are the machine instructions. The languages that come under this category are the Machine level language and Assembly language.
Machine-level language
The machine-level language is a language that consists of a set of instructions that are in the binary form 0 or 1. As we know that computers can understand only machine instructions, which are in binary digits, i.e., 0 and 1, so the instructions given to the computer can be only in binary codes. Creating a program in a machine-level language is a very difficult task as it is not easy for the programmers to write the program in machine instructions. It is error-prone as it is not easy to understand, and its maintenance is also very high. A machine-level language is not portable as each computer has its machine instructions, so if we write a program on one computer will no longer be valid on another computer.
The different processor architectures use different machine codes, for example, a PowerPC processor contains RISC architecture, which requires different code than an intel x86 processor, which has a CISC architecture.
Assembly Language
The assembly language contains some human-readable commands such as mov, add, sub, etc. The problems which we were facing in machine-level language are reduced to some extent by using an extended form of machine-level language known as assembly language. Since assembly language instructions are written in English words like mov, add, sub, so it is easier to write and understand.
As we know that computers can only understand machine-level instructions, so we require a translator that converts the assembly code into machine code. The translator used for translating the code is known as an assembler.
The assembly language code is not portable because the data is stored in computer registers, and the computer has to know the different sets of registers.
The assembly code is not faster than machine code because the assembly language comes above the machine language in the hierarchy, so it means that assembly language has some abstraction from the hardware while machine language has zero abstraction.
Q9) Differences between Machine-Level language and Assembly language
A9)
The following are the differences between machine-level language and assembly language:
Machine-level language | Assembly language |
The machine-level language comes at the lowest level in the hierarchy, so it has zero abstraction level from the hardware. | The assembly language comes above the machine language means that it has less abstraction level from the hardware. |
It cannot be easily understood by humans. | It is easy to read, write, and maintain. |
The machine-level language is written in binary digits, i.e., 0 and 1. | The assembly language is written in simple English language, so it is easily understandable by the users. |
It does not require any translator as the machine code is directly executed by the computer. | In assembly language, the assembler is used to convert the assembly code into machine code. |
It is a first-generation programming language. | It is a second-generation programming language. |
Q10) Explain compiler and interpreter in detail
A10)
What is Compiler?
A compiler is a computer program that transforms code written in a high-level programming language into machine code. It is a program that translates the human-readable code to a language a computer processor understands (binary 1 and 0 bits). The computer processes the machine code to perform the corresponding tasks.
A compiler should comply with the syntax rule of that programming language in which it is written. However, the compiler is only a program and cannot fix errors found in that program. So, if you make a mistake, you need to make changes in the syntax of your program. Otherwise, it will not compile.
What is an Interpreter?
An interpreter is a computer program, which covers each high-level program statement into the machine code. This includes source code, pre-compiled code, and scripts. Both compiler and interpreters do the same job which is converting higher-level programming language to machine code. However, a compiler will convert the code into machine code (create an exe) before the program run. Interpreters convert code into machine code when the program is run.
KEY DIFFERENCE
Difference between Compiler and Interpreter
Basis of difference | Compiler | Interpreter |
Programming Steps |
|
|
Advantage | The program code is already translated into machine code. Thus, it code execution time is less. | Interpreters are easier to use, especially for beginners. |
Disadvantage | You can't change the program without going back to the source code. | Interpreted programs can run on computers that have the corresponding interpreter. |
Machine code | Store machine language as machine code on the disk | Not saving machine code at all. |
Running time | Compiled code run faster | Interpreted code run slower |
Model | It is based on the language translation linking-loading model. | It is based on Interpretation Method. |
Program generation | Generates output program (in the form of exe) which can be run independently from the original program. | Do not generate an output program. So they evaluate the source program every time during execution. |
Execution | Program execution is separate from the compilation. It is performed only after the entire output program is compiled. | Program Execution is a part of the Interpretation process, so it is performed line by line. |
Memory requirement | Target programs execute independently and do not require the compiler in the memory. | The interpreter exists in the memory during interpretation. |
Best suited for | Bounded to the specific target machine and cannot be ported. C and C++ are a most popular a programming language which uses compilation model. | For web environments, where load times are important. Due to all the exhaustive analysis is done, compiles take a relatively larger time to compile even small code that may not be run multiple times. In such cases, interpreters are better. |
Code Optimization | The compiler sees the entire code upfront. Hence, they perform lots of optimizations that make code run faster | Interpreters see code line by line, and thus optimizations are not as robust as compilers |
Dynamic Typing | Difficult to implement as compilers cannot predict what happens at turn time. | Interpreted languages support Dynamic Typing |
Usage | It is best suited for the Production Environment | It is best suited for the program and development environment. |
Error execution | Compiler displays all errors and warning at the compilation time. Therefore, you can't run the program without fixing errors | The interpreter reads a single statement and shows the error if any. You must correct the error to interpret the next line. |
Input | It takes an entire program | It takes a single line of code. |
Output | Compliers generate intermediate machine code. | The interpreter never generates any intermediate machine code. |
Errors | Display all errors after, compilation, all at the same time. | Displays all errors of each line one by one. |
Pertaining Programming languages | C, C++, C#, Scala, Java all use complier. | PHP, Perl, Ruby uses an interpreter. |