Network Theory
Network Theory
Network Theory
Example:
If the instruction involves an operation to be performed by the ALU, the operands need to be
fetched either from the memory or from the general purpose register. If the operand is
available in the memory it has to be fetched by sending its address to the MAR and initiating
a read cycle. When the operand has been read from the memory into the MDR, it is
transferred from the MDR to the ALU. Then ALU performs the desired operation. If the
result has to be stored in memory, then it is sent to MDR. The address of the location where
the result is to be stored is sent the MAR and a write cycle is initiated. PC must be
incremented to point to next instruction.
What is a Bus? Explain single bus and multiple Bus structures used to interconnect
functional units in a computer system.
To form an operational system the different parts of computer must be connected in some
organized way. When a word of data is transferred between units, all its bits are transferred in
parallel that is the bits are transferred simultaneously over many wires or lines, one bit per
line.
Group of lines that serves as a connecting path for several devices is called a bus. In
addition to the lines that carry the data, the bus must have lines for address and control
purposes.
The simplest way to interconnect functional units is to use a single bus. All units are
connected to this bus. Because the bus can be used for only one transfer at a time, only two
units can actively use the bus at any given time. The main virtue of the single-bus structure is
its low cost and its flexibility for attaching peripheral devices.
How to prevent high speed processor from being locked to a slow input/output device
during data transfer?
Some electromechanical devices, such as keyboards and printers, are relatively slow. Others
like magnetic or optical disks are considerably faster. Because all these devices must
communicate with each other over a bus, an efficient transfer mechanism that can be used to
smooth out the difference in timing among processors, memories, and external devices is
necessary.
A common approach is to include buffer registers with the devices to hold the
information during transfers. To illustrate this technique, consider the transfer of an encoded
character from a processor to a character printer .The processor sends the character over the
bus to the printer buffer. Since the buffer is an electronic register, this transfer requires
relatively little time. Once the buffer is loaded, the printer can start printing without further
2 Sudhamani M J, Assistant Professor, Department of CSE , RNSIT
18CS34-Computer Organization 2019
intervention by the processor. The bus and the processor are no longer needed and can be
released for other activity. Thus buffer registers smooth out timing differences among
processors, memories, and I/O devices. This allows the processor to switch rapidly from one
device to another interweaving its processing activity with data involving several I/O devices.
What are the factors used to judge the performance of a computer? Explain any 3 of
them.
Following are the factors used to judge the performance of a computer:
The most important measure of the performance of a computer is how quickly it can execute
programs. The speed with which a computer executes programs is affected by the design of
its hardware and its machine language instructions. Because programs are usually written in
a high-level language, performance is also affected by the compiler that translates programs
into machine language. The total time required to execute the program is called elapsed time.
This elapsed time is a measure of the performance of the entire computer system. It is
affected by the speed of the processor, the disk and the printer etc.
2) TOTAL ELAPSED TIME: Let T is the processor time required to execute a program
that has been prepared in some high-level language. The compiler generates a machine
language object program that corresponds to the source program. Assume that complete
execution of the program requires the execution of N machine language instructions. The
number N is the actual number of instruction executions and is not necessarily equal to the
number of machine instructions in the object program. Suppose that the average number of
basic steps needed to execute one machine instruction is S, where each basic step is
completed in one clock cycle. If the clock rate is R cycles per second, the program execution
time T is given by
This is often referred to as the basic performance equation. To achieve high performance, the
computer designer must seek ways to reduce the value of T.
SPEC rating of 50 means that the computer under test is 50 times as fast as the
UltraSPARC10 for this particular benchmark. Let SPECi be the rating for program I in the
suite. The overall SPEC
rating for the computer is given by
= (∏ )
Write the basic performance equation? Explain the role of parameters on the
performance of the computer. (5M)
Let 'T' be the processor time required to execute a program that has been prepared in
some high-level language. The compiler generates a machine language object program that
corresponds to the source program. The number N is the actual number of instruction
execution and is not necessarily
equal to the number of machine instructions in the object program. If the clock rate is R
cycles per second, the program execution time is given by
∗
=
This is often referred to as the basic performance equation.
To achieve high performance,
Reduce the value of T which means reducing N&S and increasing R.
N is reduced if the source program is compiled into fewer machine instructions.
S is reduced if the instructions have a smaller number of basic steps to perform or if
the execution of the instructions is overlapped.
R can be increased by using a high frequency clock.
N, S and R are not independent parameters changing one may affect another.
Introducing a new feature in the design of a processor will lead to improved
performance only if the overall result is to reduce the value of T.
There are two possibilities for increasing the clock rate ‘R’.
1. Improving the IC technology makes logical circuit faster, which reduces the time
needed to complete a basic step. This allows the clock period P, to be reduced and the
clock rate R to be increased.
2. Reducing the amount of processing done in one basic step also makes it possible to
reduce the clock period P.
a) Processor clock – Processor circuits are controlled by a timing signal called a clock.
The clock defines regular time intervals, called clock cycles. To execute a machine
instruction, the processor divides rhea action to be performed into sequence of basic
steps, such that each step can be completed in one clock cycle. The length P of one
clock cycle is an important parameter that affects processor performance. Its inverse
the clock rate, R=1/P which is measured in cycles per second.
b) Clock rate – the clock rate is the inverse of processor clock, P.
R=1/P
c) Elapsed time – The total time required executing the program.
d) Processor time – The amount of the time taken by the processor to execute a program
excluding I/O time needed by a program.
What is byte addressability? Explain 2ways that byte addresses are assigned across
words. (Or) Explain a) Big endian assignment b) Little endian assignment
A byte is 8 bits, but the word length ranges from 16 to 64 bits. Byte addressable memory is
the one where, successive addresses refer to successive memory locations in the memory.
Byte locations have addresses 0, 1, 2… Thus, if the word length of the machine is 32 bytes,
successive words are located at addresses 0, 4, 8 ..., with each word consisting of 4 byte.
The two ways that byte addresses can be assigned across words are
i) Big Endian assignment - The name Big endian is used when lower byte addresses are
used for the most significant bytes (the leftmost bytes) of the word.
ii) Little Endian assignment – The name Little endian is used for the opposite ordering,
where the lower byte addresses are used for the less significant bytes (the rightmost
bytes) of the word.
In both the cases byte addresses 0, 4, 8 . . . are taken as the addresses of successive words in
the memory and are the addresses used when specifying memory read and write operations
for words. In addition to this, it is also necessary to specify the labelling of bits within a byte
or word. The same ordering is used for labelling bits within a byte, that is, b7, b6, …., b0,from
left to right.
What is word alignment of a m/c? What are the consecutive addresses of aligned words
for 16, 32 and 64 bit word length m/c? Give consecutive addresses for each case. (5M)
If words in memory begin at address that is a multiple of the number of bytes in a word it is
called as word alignment of a m/c.
The number of bytes in a word is a power of 2. Hence 16 bit word consists of 2 byte locations
within it. 32 bit word consists of 4 byte locations and 64 bit word consists of 8 bytes in each
location.
contents be read. The memory reads the data stored at that address and sends them to the
processor.
The store operation transfers an item of information from the processor to a specific
memory location, destroying the former contents of that location. The processor sends the
address of the desired location to the memory, together with the data to be written into that
location.
Show how the operation C=A+B can be implemented in a single accumulator computer
by
i) 3-address instruction ii) 2-address instruction iii) 1-address instruction . (10M)
Using 1-address instruction: Here m/c instructions specify only one memory operand.
When a second operand is needed it is understood implicitly to in a unique location. A
processor register Accumulator is usually used for this purpose.
Thus C=A+B can be implemented as below:
to fetch and execute instructions, one at a time, in the order of increasing addresses. This is
called straight line sequencing.
During the execution of each instruction the PC is incremented by 4 to point to the
next instruction. Thus, after the Move instruction at location i+8 is executed, the PC contains
the value i+12, which is the address of the first instruction of the next program segment.
Executing the next instruction is a two phase procedure .In the first phase called instruction
fetch, the instruction is fetched from the memory location whose address is in the PC. This
instruction is placed in the instruction register (IR) in the processor. At the start of the second
phase, call instruction execute the instruction in IR is examined to determine which operation
is to be performed. The specified operation is then performed by the processor. This involves
fetching operands from the memory or from processor or from the processor registers,
performing an arithmetic or logic operation, and storing the result in the destination location.
The processor keeps track of information about the various operations for use by subsequent
conditional branch instructions.
This is accomplished by recording the required information in individual bits, often called the
conditional code flags. These flags are usually grouped together in a special processor
register called the condition code register or status register. Individual condition code flags
are set to 1 or cleared to 0,depending on the outcome of the operations performed. Four
commonly used flags are
The N and the Z flags indicate whether the result of an arithmetic or logic operation is
zero or negative. Then N and Z flags may also be affected by instructions that transfer data
such as Move, Load or Store. This makes it possible for a later conditional branch instruction
to cause a branch based on the sign and value of the operand that was moved.
The V flag indicates whether the overflow has taken place. Overflow occurs when the
result of arithmetic operation is outside the range of values that can be represented by the no
of bits available for the operands. The processor sets the V flag to allow the programmer to
test whether overflow has occurred and branch to an appropriate routine that corrects the
problem. Instructions
such as BranchIfOverflow are provided for this purpose.
The C flag is set to 1 if a carry occurs from the most significant bit position during an
arithmetic operation.This flag makes it possible to perform arithmetic operations on operands
that are longer than the word length of the processor.
The instruction Branch>0 is an example of the branch instruction that tests one or
more conditional flags.It causes a branch if the value tested is neither negative nor equal to
zero. That is, branch is taken if neither N nor Z is 1.Many other conditional branch
instructions are provided to enable a variety of conditions to be tested. The conditions are
given as logic expressions involving the condition code flags.
Define an addressing mode. Explain the following addressing modes with example:
Indirect, Index, Relative and Auto increment. (5M)
The different ways in which the location of an operand is specified in an instruction
are referred to as addressing mode
1. Relative addressing:- X(PC) can be used to address location that is X bytes away
from the location presently pointed to by the program counter. The effective address is
determined by the index mode using the program counter in place of general purpose register
Ri. This mode can be used to access data operands. But, it’s most common use is to specify
the target address in branch instructions. An instruction such as
Branch>0 loop
Causes program execution to go to the branch target location identified by the name LOOP if
the branch condition is satisfied. This location can be computed by specifying it as an offset
from the current value of the program counter.
2. Auto increment mode:-The effective address of the operand is the contents of a register
specified in the instruction. After accessing the operand, the contents of this register are
automatically to point to the next item in a list,(Ri)+
Move N, R1
Move #NUM1, R2
Clear R0
LOOP Add (R2)+,R0
Decrement R1
Branch>0 LOOP
Move R0, SUM
The auto increment mode is used in the program.
3. Index mode:-The effective address of the operand is generated by adding the constant
value to the contents of the register. The register may be either a special register provided for
this purpose, or may be any one of a set of a general purpose registers in the processor. In
either case, it is referred as index register. Index mode symbolically represented as X
(Ri) where X denotes the constant value contained in the instruction and Ri is the name of the
register involved. The effective address of the operand is given by EA =X+[Ri].
4. Indirect mode: The effective address of the operand is the contents of the register or
memory location whose address appears in the instruction.
Write a program that can evaluate the expression (A*B) + (C*D) in a single
accumulator processor. Assume that the processor has load, store, multiply and add
instruction and all values fit in the accumulator. (5M)
LOAD A
MUL B
STORE RESULT
LOAD C
MUL D
ADD RESULT
STORE RESULT
Explain all the generic addressing modes with assembler syntax. -12M.
Explanations:
A second register may be used to contain the offset X, in which case we can write the index
mode as
(Ri,Rj)
The effective address is the sum of the contents of Ri and Rj. The second register is generally
called the base register, and the addressing mode is called Base with index mode.
Another version of index mode uses two register plus a constant.
X(Ri,Rj)
The effective address is the sum of the constant X and the contents of Ri and Rj. The
addressing mode is called Base with index and offset mode.
Relative mode-The effective address is determined by the index mode using the
program counter in place of general-purpose register Ri. This mode can be used to
access data operands. But, it’s most common use is to specify the target address in
branch instructions. An instruction such as
Branch>0 LOOP
causes program execution to go to the branch target location identified by the
name LOOP if the branch condition is satisfied.
Auto increment mode-The effective address of the operand is the contents of a
register Specified in the instruction. After accessing the operand, the contents of the
register are automatically incremented to point to the next item in a list. The auto
increment mode is written as
(Ri)+
Auto decrement mode-The contents of a register specified in the instruction are first
Automatically decremented and then used as a effective address of the operand.
The auto decrement mode is written as
- (Ri)
In this mode, operands are accessed in descending address order.
The difference between index mode, base with index mode, and base with index and
offset Mode ?
INDEX MODE
The effective address of the operand is generated by adding a constant value to the contents
of a register. The register may be either a special register provided for this purpose, or may
be any one of a set of general purpose registers in the processor. In either case, it is referred
to as index register. The index mode is symbolically represented as: x (Ri) where x denotes
the constant value contained in the instruction and Ri is the name of the register involved.
The effective address of the operand is given by
EA=x + [Ri]
The contents of the index register are not changed in the process of generating the effective
address. In an assembly language program, the constant x may be given either as an explicit
number or as a symbolic name representing a numerical value.
EQU informs the assembler about the value of SUM. ORIGIN tells the assembler where in
the memory to place the data block that follows. In this case the location specified has the
address 204.
The DATAWORD directive is used to inform the assembler that this location is to be loaded
with the value 100. It states that the data value 100 is to be placed in the memory word at
address 204.
The label is assigned a value equal to the address of that location. The RESERVE directive
declares that the memory block of 400 bytes is to be reserved for data and the name NUM1 is
to be associated with address 208.The second ORIGIN directive specifies that the instruction
of the object program are to be loaded in the memory starting at address 100.
For a simple example of i/o operations involving keyboard and display device, write an
assembly language program that reads 1 line from keyboard, stores it in memory buffer
and echos it back to the display
Explain the usage of datain, dataout registers and sin, sout status control flags in i/o
devices.
Consider the problem of moving a character code from the keyboard to the processor.
Striking key stores the corresponding character code in an 8-bit buffer register associated
with the keyboard. This register is DATAIN. To inform the processor that a valid character is
in DATAIN, a status control flag, SIN, is set to 1. A program monitors SIN, and when SIN is
set to 1, the processor reads the contents of DATAIN. When the character is transferred to the
processor, SIN is automatically cleared to 0. If a second character is entered at the keyboard,
SIN is again set to 1 and the process repeats.
An analogous process takes place when characters are transferred from the processor
to the display buffer register, DATAOUT, and a status control flag, SOUT are used for this
transfer. When SOUT equals 1, the display is ready to receive a character .under program
control, the processor monitors SOUT and when SOUT is set to 1, the processor transfers a
character code to DATAOUT. The transfer of a character to a DATAOUT clears SOUT to 0;
when the display device is ready to
receive a second character, SOUT is again set to 1.
Write the sequence for READWAIT and WRITEWAIT for pgm controlled I/O.
In order to perform I/O transfers, we need machine instructions that can check the state of
status flags and transfer the data between the processor and the I/O device. These instructions
are similar in format to those used for moving data between the processor and the memory.
For example, the processor can monitor the keyboard status flag SIN and transfer a character
from DATAIN to reg. R1 by the following sequence of operations:
READWAIT Branch to READWAIT if SIN=0
Input from DATAIN to R1
The Branch operation is usually implemented by two machine instructions. The first
instruction tests the status flag and second performs the branch. Although the details vary
from computer to computer, the main idea is that the processor monitors the status flag by
executing a short wait loop and proceeds to transfer the input data when SIN is set to 1 as a
result of a key being struck. The input operation resets SIN to 0.
An analogous sequence of operations is used for transferring output to the display.
An example is
The Testbit instruction tests the state of one bit in the destination location, where the bit
position to be tested is indicated by the first operand. if the bit tested is equal to 0, then the
condition of the branch instruction is true, and a branch is made to the beginning of the wait
loop. When the device is ready, i.e, when the bit tested becomes equal to 1, the data are read
from the input buffer or written into the output buffer.
Explain the operation of stack with an example. Give any three differences between
stack and queue.
A stack is a list of data elements usually words or bytes with accessing restriction that
elements can be added or removed at one end of the list only. This end is called top of the
stack and the other end is called bottom. This structure is sometimes referred to as a
pushdown stack. Data stored in the memory of the computer can be organized as stack, with
successive elements occupying successive memory locations.
Above figure shows a stack of word data items in the memory of the computer. It contains
numerical values with 43 at bottom and -28 at the top. A processor register is used to keep
track of the address of the element of the stack that is at the top at any given time. This
register is called stack pointer(SP).
Subtract #4,SP
Move NEWITEM,(SP)
where the subtract instruction subtracts the source operand 4 from the destination operand
contained in SP and places the result in SP. These two instructions move the word from
location NEWITEM onto the top of the stack, decrementing the stack pointer by 4 before the
move.
Move (SP),ITEM
Add #4,SP
These two instructions move the top value from the stack into location item and then
increment the stack pointer by 4 so that it points to the new top element.
what is a subroutine linkage? Explain with an example subroutine linkage using linkage
registers.
It is possible to include the block of instructions (subroutine) at the required place in the
program. So as to save space one copy of the subroutine is placed in the memory, and any
program which requires this subroutine will branch to its starting memory location. This is
known as calling of subroutine which is done by a branch operation called as call instruction.
After execution of the subroutine the control should return back to the program which called
it and this is done by executing a Return statement. Since the subroutine may be called from
diff. places in the calling program, provision must be made to return to the appropriate
location. While the call instruction is being executed, the PC will be updated with the starting
address of the subroutine and it will no longer contain the location of the next instruction
which has to be executed once the return statement is encountered. Hence the contents of the
PC have to be saved before it is updated and enable correct returning of execution to the
calling program. The return address is hence saved in a register called as link register. When
the task of the subroutine is completed, the Return instruction returns to the calling program
by indirectly branching through the link register.
The way which the computer makes it possible to call and return from subroutines is
referred to as its subroutine linkage method.
Hence
The call instruction performs following operations-
Store contents of PC in link register.
Branch to the staring address of the subroutine.
The Return instruction performs following operations
Branch to the address contained in the link register.
Following figure illustrates the same.
What are different operations performed during call instruction and return
instruction?
In a program it is necessary to perform a particular subtask more than once on different data
values. Such a subtask is called as SUBROUTINE.
Only one copy of the instructions that constitute the subroutine is placed in memory to save
space, and any program that requires the use of subroutine simply branches to its starting
location. This is called as calling the subroutine and the instruction that performs this is called
CALL INSTRUCTION.
The operations are: a) store the contents of the PC in the link register
b) Branch to the target address specified by the instruction
After the program is executed, the subroutine is said to return to the program that called it by
executing a RETURN INSTRUCTION.
The operations are: a) branch to the address contained in the link register
Consider the following possibilities for saving the return address of a subroutine
i. in a processor register
ii. in a memory location
iii. on a stack
Which of the following possibilities support the subroutine nesting and which supports
subroutine recursion? Why?
A common programming practice, called subroutine nesting, is to have one subroutine call
another. In this case the return address of the second call is also stored in the link register
destroying its previous contents. Hence it is essential to save the contents of the link register
in some other location before calling another subroutine. Otherwise the return address of the
first subroutine will be lost.
Subroutine nesting can be carried out to any depth. Eventually the last subroutine
called completes its computations and returns to the subroutine that called it. The return
address needed for this first return is the last one generated in the nested call sequence. That
is, return addresses are generated and used in a last -in –first- out order. This suggests that the
return address associated with subroutine calls should be pushed onto a stack. Many
processors do this automatically as one of the operations performed by the Call instruction. A
particular register is designated as the stack pointer .SP, to be used in this operation .The
stack pointer points to the stack called the processor stack and loads the subroutine address
into the PC. The return instruction pops the return address from the processor stack into the
PC.
Thus
a) Processor register supports neither nesting nor recursion.
b) Memory location supports nesting, because different Call instructions will save the
return address at different memory locations. But Recursion is not supported.
c) Stack supports both nesting and recursion.
Explain how the parameters are passed to a subroutine? WAP to add a list of N-
numbers stored in a memory, which calls a subroutine namely LISTADD. Trace the
program with suitable example.
When calling a subroutine, a program must provide to the subroutine the parameters, that is, the
Operands or the addresses to be in the computation. Later the subroutine returns the other
parameters, in this case, the result of the computation. This exchange of information between a
calling program and a subroutine is referred to as parameter passing. Parameter passing may
be accomplished in several ways. The parameters may be placed in registers or in memory
locations, where they can be accessed by the subroutine. Alternatively, the parameters may be
placed on the processor stack used for saving the return address.
The size of the list n, contained in memory location N and the address NUM1 of the first
number are passed through the registers R1 and R2. The sum computed by the subroutine is
passed back to the calling program through register R0. After the return operation is
performed by the subroutine, the sum is stored in the memory location SUM by the calling
program.
If many parameters are involved, there may not be enough general-purpose registers
available for passing them to the subroutine. Using a stack, on the other hand, is highly
flexible; a stack can handle a large number of parameters. The parameters passed to this
subroutine are the address of the first number in the list and the number of entries. The
subroutine performs the addition and returns the computed sum. The parameters are pushed
onto the processor stack pointed to by register SP.
25 Sudhamani M J, Assistant Professor, Department of CSE , RNSIT
18CS34-Computer Organization 2019
b) Following program adds a list N-numbers stored in a memory. Uses stack to pass the
parameters.
What is stack frame? Illustrate the use of stack frame in the mechanism for
implementing subroutine?
The locations constitute a private works space for the subroutine, created at the time the
subroutine is entered and freed up when then subroutine return control to the calling program.
Such space is called a stack frame.
In addition to the stack pointer (SP), it is useful to have another pointer register, called
the frame pointer (FP), for convenient access to the parameters passed to the subroutine and
to the local memory variables used by the subroutine. These local variables are only used
within the subroutine so it is appropriate to allocate space for them in the stack frame
associated with the subroutine.
We assume that 4 parameters are passed to the subroutine; three local variables are
used in the subroutine and registers needs to be saved because they will also be used within
the subroutine. After these instructions are executed both SP and FP point to the saved FP
contents. Space for the three local variables is now allocated on the stack by executing the
instruction .finally the contents of the processor registers are saved by pushing them on to the
stack at this point the stack frame has been set up. The subroutine now executes its task.
When the task is completed the subroutine pops the saved values into those registers remove
the local variables from the stack frame by executing the instructions. The calling program is
responsible for removing the parameters from the stack frame, some of which may be results
passed back by the subroutine. This stack pointer now points to the old of the stack and we
are back to where we started.
The logical shift right instruction, LShiftR , works in the same manner except that it shifts to
the right , the following figure demonstrates the right shift operation . .
2. Arithmetical Shifts
A 2's-complement binary number representation reveals that shifting a number one bit
position to the left is equivalent to multiplying it by 2; and shifting it to the right is equivalent
to dividing it by 2.
Of course, overflow may occur while shifting left and the remainder is lost while shifting
right. Another important observation is that on a right shift the sign bit must be repeated as
the fill-in bit for the vacated positions. This requirement on right shifting distinguishes
arithmetic shifts from the logical shifts in which the fill-in bit is always 0. Otherwise, the two
types of shifts are very similar.
An example of the arithmetic shift i.e., AShiftR , is shown in the figure.
3. Rotate Operations
In the shift operations, the bits shifted out of the operand are lost, except for the last
bit shifted out which is retained in the carry flag C. To preserve all bits, a set of rotate
instructions can be used. They move the bits that are shifted out of one end of the operand
back to the other end. Two versions of both the left and right rotate instructions are usually
provided. In one version, the bits of the operand are simply rotated. In other version, the
rotation includes the C flag. The following figure shows the left and right rotation operations
with and without the C flag being included in the rotation.