Sie sind auf Seite 1von 17

UNIT 1 BASIC STRUCTURE OF COMPUTER

1.Draw functional block diagram of a computer and explain


the function of each block in brief.
Ans=A computer can process data, pictures, sound and graphics.
They can solve highly complicated problems quickly and
accurately. A computer as shown in Fig performs basically five
major computer operations or functions irrespective of their size
and make. These are
1) It accepts data or instructions by way of input,
2) It stores data,
3) It can process data as required by the user,
4) It gives results in the form of output, and
5) It controls all operations inside a computer.
We discuss below each of these Computer operations

Fig : Basic computer Operations

1. Input: This is the process of entering data and programs in to


the computer system. You should know that computer is an
electronic machine like any other machine which takes as inputs
raw data and performs some processing giving out processed
data. Therefore, the input unit takes data from us to the computer
in an organized manner for processing.

2. Storage: The process of saving data and instructions permanently is


known as storage. Data has to be fed into the system before the actual
processing starts. It is because the processing speed of Central Processing
Unit (CPU) is so fast that the data has to be provided to CPU with the same
speed. Therefore the data is first stored in the storage unit for faster access
and processing. This storage unit or the primary storage of the computer
system is designed to do the above functionality. It provides space for
storing data and instructions.

The storage unit performs the following major functions:


All data and instructions are stored here before and after processing.
Intermediate results of processing are also stored here.

3. Processing: The task of performing operations like arithmetic and


logical operations is called processing. The Central Processing Unit (CPU)
takes data and instructions from the storage unit and makes all sorts of
calculations based on the instructions given and the type of data provided.
It is then sent back to the storage unit.

4. Output: This is the process of producing results from the data for
getting useful information. Similarly the output produced by the computer
after processing must also be kept somewhere inside the computer before
being given to you in human readable form. Again the output is also stored
inside the computer for further processing.

5. Control: The manner how instructions are executed and the


above operations are performed. Controlling of all operations like
input, processing and output are performed by control unit. It
takes care of step by step processing of all operations inside the
computer.
FUNCTIONAL UNITS
In order to carry out the operations mentioned in the previous
section the computer allocates the task between its various
functional units. The computer system is divided into three
separate units for its operation. They are
1) arithmetic logical unit
2) control unit.
3) central processing unit.

Arithmetic Logical Unit (ALU) Logical Unit


Logical Unit :After you enter data through the input device it is
stored in the primary storage unit. The actual processing of the
data and instruction are performed by Arithmetic Logical Unit.
The major operations performed by the ALU are addition,
subtraction, multiplication, division, logic and comparison. Data
is transferred to ALU from storage unit when required. After
processing the output is returned back to storage unit for further
processing or getting stored.
Control Unit (CU)
The next component of computer is the Control Unit, which acts
like the supervisor seeing that things are done in proper fashion.
Control Unit is responsible for co ordinating various operations
using time signal. The control unit determines the sequence in
which computer programs and instructions are executed. Things
like processing of programs stored in the main memory,
interpretation of the instructions and issuing of signals for other
units of the computer to execute them. It also acts as a switch
board operator when several users access the computer
simultaneously. Thereby it coordinates the activities of computers
peripheral equipment as they perform the input and output.
Central Processing Unit (CPU)
The ALU and the CU of a computer system are jointly known as
the central processing unit. You may call CPU as the brain of any
computer system. It is just like brain that takes all major
decisions, makes all sorts of calculations and directs different

parts of the computer functions by activating and controlling the


operations.

1) What is addressing mode? Explain various types


of addressing modes with example.
Ans=Addressing mode is the way of addressing a memory
location in instruction. Microcontroller needs data or operands on
which the operation is to be performed. The method of specifying
source of operand and output of result in an instruction is known
as
addressing
mode.
There are various methods of giving source and destination
address in instruction, thus there are various types of Addressing
Modes. Here you will find the different types of Addressing Modes
that are supported in Micro Controller 8051. Types of Addressing
Modes are explained below
Types Of Addressing Modes:
Following are the types of Addressing Modes:

Register Addressing Mode

Direct Addressing Mode

Register Indirect Addressing Mode

Immediate Addressing Mode

Index Addressing Mode


Explanation:

1.

Register Addressing Mode: In this addressing


mode, the source of data or destination of result is
Register. In this type of addressing mode the name of
the register is given in the instruction where the data to
be read or result is to be stored.
Example: ADD A, R5 ( The instruction will do the
addition of data in Accumulator with data in register R5)

2.

Direct Addressing Mode: In this type


of Addressing Mode, the address of data to be read is
directly given in the instruction. In case, for storing
result the address given in instruction is used to store
the result.
Example: MOV A, 46H ( This instruction will move the
contents of memory location 46H to Accumulator)

3.

Register Indirect Addressing Mode: In Register


Indirect Addressing Mode, as its name suggests the
data is read or stored in register indirectly. That is, we
provide the register in the instruction, in which the
address of the other register is stored or which points to
other register where data is stored or to be stored.
Example: MOV A, @R0 ( This instruction will move the
data to accumulator from the register whose address is
stored in register R0 )
4.
Immediate Addressing Mode : In
Immediate Addressing Mode , the data immediately
follows the instruction. This means that data to be used
is already given in the instruction itself.
Example: MOV A, #25H ( This instruction will move the
data 25H to Accumulator. The # sign shows that
preceding term is data, not the address.)

5.

Index Addressing Mode: Offset is added to the base


index register to form the effective address if the memory
location .This Addressing Mode is used for reading lookup
tables in Program Memory. The Address of the exact location of
the table is formed by adding the Accumulator Data to the base
pointer.
Example: MOVC, @A+DPTR ( This instruction will move the
data from the memory to Accumulator; the address is made by
adding the contents of Accumulator and Data Pointer

2) Explain big endian and little endian asiigment with


examples.
Ans=
Big Endian / Little Endian
When transferring binary data between computers, it is important that
both systems use the same data representations, or the information will
be meaningless. While it might appear to many that nothing could be
simpler than binary integer numbers, there are at least two different
formats for storing twos complement integers. The difference depends
upon the order in which the bytes of an integer are stored in
memory. The Big Endian format stores the most significant bytes (the
bytes containing the high order or left most bits) in the lowest address
with the following bytes in sequentially higher addresses. The bytes
would appear in normal order when written from left to right. The Little
Endian format stores the least significant byte (the byte containing the
lowest or right most bits) at the lowest address with the increasingly
significant bytes stored at increasing addresses.
For example, consider how the decimal number 258 (0100000010 in
binary) would be stored in as a 16 bit binary number.

0000000 0000001 Big


1
0
Endian
0000001 0000000 Little
0
1
Endian
When transferring binary integers over a network, it is important to
ensure that the sending and receiving systems use the same format or
that a conversion is done. If a Big Endian computer sent the above
binary number to a Little Endian computer without conversion, it would
be interpreted as 513.
To avoid problems in a heterogeneous network, binary numbers are
converted to Network Standard Format (Big Endian) before
transmission. The functions:

htons
htonl

Host to Network Short


Host to Network Long

can be used to convert binary data to network standard format.

4)what is subroutine ?explain it by examples?


Ans=In computer programming, a subroutine is a sequence of
program instructions that perform a specific task, packaged as a
unit. This unit can then be used in programs wherever that
particular task should be performed. Subprograms may be
defined within programs, or separately in libraries that can be
used by multiple programs. In different programming languages, a

subroutine may be called a procedure, a function, a routine,


a method, or a subprogram. The generic term callable unit is
sometimes used.[1]
The name subprogram suggests a subroutine behaves in much
the same way as a computer program that is used as one step in
a larger program or another subprogram. A subroutine is often
coded so that it can be started (called) several times and from
several places during one execution of the program, including
from other subroutines, and then branch back (return) to the next
instruction after the call, once the subroutine's task is
done. Maurice Wilkes, David Wheeler, and Stanley Gill are
credited with the invention of this concept, which they termed
a closed subroutine,[2][3] contrasted with an open
subroutine or macro.[4]
Subroutines are a powerful programming tool,[5] and the syntax of
many programming languages includes support for writing and
using them. Judicious use of subroutines (for example, through
the structured programming approach) will often substantially
reduce the cost of developing and maintaining a large program,
while increasing its quality and reliability.[6] Subroutines, often
collected into libraries, are an important mechanism for sharing
and trading software. The discipline of object-oriented
programming is based onobjects and methods (which are
subroutines attached to these objects or object classes).
In the compiling method called threaded code, the executable
program is basically a sequence of subroutine calls.
Advantages
The advantages of breaking a program into subroutines include:

Decomposing a complex programming task into simpler


steps: this is one of the two main tools of structured
programming, along with data structures

Reducing duplicate code within a program

Enabling reuse of code across multiple programs

Dividing a large programming task among various


programmers, or various stages of a project

Hiding implementation details from users of the subroutine

Improving traceability (i.e. most languages offer ways to


obtain the call trace which includes the names of the involved
subroutines and perhaps even more information such as file
names and line numbers); by not decomposing the code into
subroutines, debugging would be impaired severely

Disadvantages
Invoking a subroutine (versus using in-line code) imposes
some computational overhead in the call mechanism.
The subroutine typically requires standard housekeeping code
both at entry to, and exit from, the function (function prologue and
epilogue usually saving general purpose registers and return
address as a minimum).

5.Explain the difference between Stack and Queue.


Ans=

Main Difference Stack vs Queue


In Computer Science, stack and queue are two abstract data
types that are simple data structures that use pointers to
represent dynamic sets. However, a difference can be noted
between them based on their implementations. Basic
operations of inserting and deleting elements are supported
by both stack and queue. The main difference between Stack
and Queue is that a stack implements Last In First Out or
LIFO policy, whereas a queue implements First In First Out
or FIFO policy.

In a stack, operations on data can be performed only at the


top of the stack.
In a queue, both ends of the queue are accessible for
operations. An insertion takes place at the tail of the queue,
and a deletion can be made at the head.
Behaviour
A stack is an LIFO data structure, where the element that was
added last to the stack is the first element to be removed. The
removal is in reverse order to the order of addition.
A queue is an FIFO data structure, where the element that was
added first to the queue will be the first element to be
removed. Order of insertion and removal are the same.
Basic Operations

In a stack, an element is inserted at the top of the stack and


removed from the top as well.
But in a queue, an element is inserted at the end of a queue
and is removed from the front.
Capacity
A stack has a bounded capacity.
A queue can be of bounded capacity, but is usually
implemented without a specific capacity.
Wastage of Memory Space
Since a stack only needs one pointer to keep track of the top
of the stack, there is no wastage of memory space.
A queue needs two pointers front and rear to keep track of
both ends of the queue. Therefore, there is wastage of
memory space.

OR
NO STACK

QUEUE

Objects are inserted and removed at


the same end.

Objects are inserted and removed


from different ends.

In stacks only one pointer is used. It


points to the top of the stack.

In queues, two different pointers are


used for front and rear ends.

In stacks, the last inserted object is first In queues, the object inserted first is
to come out.
first deleted.

Stacks follow Last In First Out (LIFO)


order.

Queues following First In First Out


(FIFO) order.

Stack operations are called push and


pop.

Queue operations are called


enqueue and dequeue.

Stacks are visualized as vertical


collections.

Queues are visualized as horizontal


collections.

Collection of dinner plates at a wedding People standing in a file to board a


reception is an example of stack.
bus is an example of queue.

7.What is Stack and Queue ?


Ans=

What is Stack

A stack is

a linear data structure that serves as a collection elements.


Only one end of the structure is accessible to perform
operations on elements, and it is commonly referred to as
the top. Two principal operations can be performed on a
stack; push and pop. An insert operation performed on a stack
is called push and a delete operation performed on a stack is
called pop.
The push operation adds an element to the top of the
collection. Performing a pop operation removes an element
that is at the top of the collection. Since the elements that are
removed from the stack are in reverse order to the order of
their addition, the structure is known to follow Last In First Out
or an LIFO approach. Given this implementation, the lowest
elements have been on the stack for the longest.

A stack is considered as a restricted data structure due to the


small number of operations that can be performed on a stack.
Additionally, a peek operation can be implemented to return
the value of the top element without modifying the element.
Also, implementations of a stack often have an Is
Empty function to check whether the stack is empty. In
environments that rely heavily on stacks, functions like delete,
swap/exchange and rotate may also be provided. But these are
not essential for the basic functionality of a stack.
A stack has a bounded capacity. If the stack is full, it goes into
an overflow state, which means there is not enough space for
more elements to be pushed onto the stack. If the stack is
empty, and there are no elements to pop, the stack is in an
underflow state.
A stack can be easily implemented using arrays or linked lists
in most high-level programming languages.

Stacks are applicable in areas such as evaluating


arithmetic
expressions,
run-time
memory

management, tree traversal, syntax parsing, etc.

What is Queue
A queue is a linear data structure that also serves as a
collection of elements. Both ends of a queue are accessible for
performing operations on elements and are typically
called head and tail. Two principal operations can be
performed on a queue; enqueue and dequeue. Enqueue is the
insertion operation while dequeue is the deletion operation
performed on a queue.
When an element is enqueued, it is added to the tail of the
queue. Performing adequeue operation will remove an
element from the head of the queue. Since the enqueued
elements are always dequeued in the same order as they were

enqueued, the structure is said to implement a First In First


Out or FIFO approach.
Similar to a stack, a queue is also a restricted data
structure given the small number of operations that can be
carried out. In addition, a peek operation can be implemented
in a queue, which will return the value of the element at the
head of the queue without dequeuing it. Other primitive
operations
on
a
queue
may
includeIsEmpty, IsFull,
and display. The IsEmpty function checks whether the queue is
empty and IsFull check if the queue is full. The display function
can be used to present the content of the queue. But again,
these functions are not critical for the implementation of a
queue.
Unlike a stack, queues can be implemented to have a
bounded capacity or with no specific capacity. An overflow
state of a queue occurs when an element is enqueued to a full
queue, and an underflow state occurs when an element is
dequeued, but the queue is empty.
The type of queue may differ on how enqueuing and
dequeuing operations are performed on elements. Circular
queue, priority queue, and double-ended queue are the
special types of queues.
Using arrays and linked lists, queues can be efficiently
implemented in high-level programming languages.
Queues are applicable in many areas such as simulations,
batch processing in operating systems, scheduling algorithms,

buffering requests, multiprogramming platform systems, etc.

Das könnte Ihnen auch gefallen