0% found this document useful (0 votes)
2 views16 pages

Computer Organization-Notes-Module2

The document discusses basic input/output operations in computer organization, highlighting the importance of synchronizing data transfer between processors and I/O devices. It explains the use of stacks and queues for data management, detailing how subroutines operate, including parameter passing and stack frames. Additionally, it covers logic, shift, and rotate instructions for manipulating data at the bit level.

Uploaded by

Ramananda Mallya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Computer Organization-Notes-Module2

The document discusses basic input/output operations in computer organization, highlighting the importance of synchronizing data transfer between processors and I/O devices. It explains the use of stacks and queues for data management, detailing how subroutines operate, including parameter passing and stack frames. Additionally, it covers logic, shift, and rotate instructions for manipulating data at the bit level.

Uploaded by

Ramananda Mallya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

COMPUTER ORGANIZATION

MODULE – 2

BASIC INPUT/OUTPUT OPERATIONS: -

We now examine the means by which data are transferred between the memory of a
computer and the outside world. Input/Output (I/O) operations are essential, and the way they
are performed can have a significant effect on the performance of the computer.

Consider a task that reads in character input from a keyboard and produces character
output on a display screen. A simple way of performing such I/O tasks is to use a method
known as program-controlled I/O. The rate of data transfer from the keyboard to a computer
is limited by the typing speed of the user, which is unlikely to exceed a few characters per
second. The rate of output transfers from the computer to the display is much higher. It is
determined by the rate at which characters can be transmitted over the link between the
computer and the display device, typically several thousand characters per second. However,
this is still much slower than the speed of a processor that can execute many millions of
instructions per second. The difference in speed between the processor and I/O devices
creates the need for mechanisms to synchronize the transfer of data between them.

Bus

Processor DATAIN DATAOUT

SIN SOUT

Keyboard Display

Fig a Bus connection for processor, keyboard, and display

The keyboard and the display are separate device as shown in fig a. the action of
striking a key on the keyboard does not automatically cause the corresponding character to be
displayed on the screen. One block of instructions in the I/O program transfers the character
into the processor, and another associated block of instructions causes the character to be
displayed.

Striking a key stores the corresponding character code in an 8-bit buffer register
associated with the keyboard. Let us call this register DATAIN, as shown in fig a. 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 processor
repeats.
An analogous process takes place when characters are transferred from the processor
to the display. A 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.

In order to perform I/O transfers, we need machine instructions that can check the
state of the status flags and transfer 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 register R1 by the following sequence of operations.
STACKS AND QUEUES: -
A computer program often needs to perform a particular subtask using the familiar
subroutine structure. In order to organize the control and information linkage between the
main program and the subroutine, a data structure called a stack is used. This section will
describe stacks, as well as a closely related data structure called a queue.

Data operated on by a program can be organized in a variety of ways. We have


already encountered data structured as lists. Now, we consider an important data structure
known as a stack. A stack is a list of data elements, usually words or bytes, with the accessing
restriction that elements can be added or removed at one end of the list only. This end is
called the top of the stack, and the other end is called the bottom. Another descriptive phrase,
last-in-first-out (LIFO) stack, is also used to describe this type of storage mechanism; the last
data item placed on the stack is the first one removed when retrieval begins. The terms push
and pop are used to describe placing a new item on the stack and removing the top item from
the stack, respectively.

Fig b shows a stack of word data items in the memory of a computer. It contains
numerical values, with 43 at the 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 the stack pointer (SP). It could be one of the general-purpose registers or a
register dedicated to this function.
Fig b A stack of words in the memory
0
…. Stack
pointer …. register
…. SP
Current -28
17
739 Stack
….
….
BOTTOM …. Bottom element
43
….
…. 2k-1
….

Another useful data structure that is similar to the stack is called a queue. Data are
stored in and retrieved from a queue on a first-in-first-out (FIFO) basis. Thus, if we assume
that the queue grows in the direction of increasing addresses in the memory, which is a
common practice, new data are added at the back (high-address end) and retrieved from the
front (low-address end) of the queue.
There are two important differences between how a stack and a queue are
implemented. One end of the stack is fixed (the bottom), while the other end rises and falls as
data are pushed and popped. A single pointer is needed to point to the top of the stack at any
given time. On the other hand, both ends of a queue move to higher addresses as data are
added at the back and removed from the front. So two pointers are needed to keep track of the
two ends of the queue.

Another difference between a stack and a queue is that, without further control, a
queue would continuously move through the memory of a computer in the direction of higher
addresses. One way to limit the queue to a fixed region in memory is to use a circular buffer.
Let us assume that memory addresses from BEGINNING to END are assigned to the queue.
The first entry in the queue is entered into location BEGINNING, and successive entries are
appended to the queue by entering them at successively higher addresses. By the time the
back of the queue reaches END, space will have been created at the beginning if some items
have been removed from the queue. Hence, the back pointer is reset to the value
BEGINNING and the process continues. As in the case of a stack, care must be taken to
detect when the region assigned to the data structure is either completely full or completely
empty.

SUBROUTINES: -
In a given program, it is often necessary to perform a particular subtask many times
on different data-values. Such a subtask is usually called a subroutine. For example, a
subroutine may evaluate the sine function or sort a list of values into increasing or decreasing
order.

It is possible to include the block of instructions that constitute a subroutine at every


place where it is needed in the program. However, to save space, only one copy of the
instructions that constitute the subroutine is placed in the memory, and any program that
requires the use of the subroutine simply branches to its starting location. When a program
branches to a subroutine we say that it is calling the subroutine. The instruction that performs
this branch operation is named a Call instruction.

After a subroutine has been executed, the calling program must resume execution,
continuing immediately after the instruction that called the subroutine. The subroutine is said
to return to the program that called it by executing a Return instruction.

The way in which a computer makes it possible to call and return from subroutines is
referred to as its subroutine linkage method. The simplest subroutine linkage method is to
save the return address in a specific location, which may be a register dedicated to this
function. Such a register is called the link register. When the subroutine completes its task,
the Return instruction returns to the calling program by branching indirectly through the link
register.

The Call instruction is just a special branch instruction that performs the following
operations

 Store the contents of the PC in the link register


 Branch to the target address specified by the instruction
The Return instruction is a special branch instruction that performs the operation
 Branch to the address contained in the link register

Fig a illustrates this procedure


Memory Memory
Location Calling program location Subroutine SUB
….
….
200 Call SUB 1000 first instruction
204 next instruction ….
…. ….
…. Return
….

1000

204
PC

Link 204

Call Return

Fig b Subroutine linkage using a link register

SUBROUTINE NESTING AND THE PROCESSOR STACK:-


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 addresses associated with subroutine calls should be pushed onto a stack. A particular
register is designated as the stack pointer, SP, to be used in this operation. The stack pointer
points to a stack called the processor stack. The Call instruction pushes the contents of the PC
onto 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.

PARAMETER PASSING:-
When calling a subroutine, a program must provide to the subroutine the parameters,
that is, the operands or their addresses, to be used in the computation. Later, the subroutine
returns other parameters, in this case, the results 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 purpose of the subroutines is to add a list of numbers. Instead of passing the
actual list entries, the calling program passes the address of the first number in the list. This
technique is called passing by reference. The second parameter is passed by value, that is, the
actual number of entries, n, is passed to the subroutine.

THE STACK FRAME:-


Now, observe how space is used in the stack in the example. During execution of the
subroutine, six locations at the top of the stack contain entries that are needed by the
subroutine. These locations constitute a private workspace for the subroutine, created at the
time the subroutine is entered and freed up when the subroutine returns control to the calling
program. Such space is called a stack frame.

Fig a A subroutine stack frame example.

SP Saved [R1]
(stack pointer) Saved [R0]
Stack Localvar3
frame Localvar2 for
Localvar1
FP Saved [FP] called
(frame pointer) Return address subroutine
Param1
Param2
Param3
Param4 Old TOS

fig b shows an example of a commonly used layout for information in 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 four parameters are passed to the subroutine, three local
variables are used within the subroutine, and registers R0 and R1 need to be saved because
they will also be used within the subroutine.

The pointers SP and FP are manipulated as the stack frame is built, used, and
dismantled for a particular of the subroutine. We begin by assuming that SP point to the old
top-of-stack (TOS) element in fig b. Before the subroutine is called, the calling program
pushes the four parameters onto the stack. The call instruction is then executed, resulting in
the return address being pushed onto the stack. Now, SP points to this return address, and the
first instruction of the subroutine is about to be executed. This is the point at which the frame
pointer FP is set to contain the proper memory address. Since FP is usually a general-purpose
register, it may contain information of use to the Calling program. Therefore, its contents are
saved by pushing them onto the stack. Since the SP now points to this position, its contents
are copied into FP.

Thus, the first two instructions executed in the subroutine are

Move FP, -(SP)


Move SP, FP

After these instructions are executed, both SP and FP point to the saved FP contents.
Subtract #12, SP

Finally, the contents of processor registers R0 and R1 are saved by pushing them
onto the stack. At this point, the stack frame has been set up as shown in the fig.

The subroutine now executes its task. When the task is completed, the subroutine
pops the saved values of R1 and R0 back into those registers, removes the local variables
from the stack frame by executing the instruction.

Add #12, SP

And pops the saved old value of FP back into FP. At this point, SP points to the
return address, so the Return instruction can be executed, transferring control back to the
calling program.

LOGIC INSTRUCTIONS:-
Logic operations such as AND, OR, and NOT, applied to individual bits, are the
basic building blocks of digital circuits, as described. It is also useful to be able to perform
logic operations is software, which is done using instructions that apply these operations to
all bits of a word or byte independently and in parallel. For example, the instruction

Not dst

SHIFT AND ROTATE INSTRUCTIONS:-


There are many applications that require the bits of an operand to be shifted right or
left some specified number of bit positions. The details of how the shifts are performed
depend on whether the operand is a signed number or some more general binary-coded
information. For general operands, we use a logical shift. For a number, we use an arithmetic
shift, which preserves the sign of the number.

Logical shifts:-
Two logical shift instructions are needed, one for shifting left (LShiftL) and another
for shifting right (LShiftR). These instructions shift an operand over a number of bit positions
specified in a count operand contained in the instruction. The general form of a logical left
shift instruction is

LShiftL count, dst

(a) Logical shift left LShiftL #2, R0

R0 0

0 0 1 1 1 0 . . . 0 1 1
before :

after: 1 1 1 0 . . . 0 1 1 00

(b) Logical shift right LShiftR #2, R0


C

R0 C

Before: 0 1 1 1 0 . . . 0 1 1 0

1
0 0 0 1 1 1 0 . . . 0
After:

( c) Arithmetic shift right AShiftR #2, R0

R0 C

Before: 1 0 0 1 1 . . . 0 1 0 0

1 1 1 0 0 1 1 . . . 0 1
After:

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 into 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 the other version, the
rotation includes the C flag.

(a) Rotate left without carry RotateL #2, R0

R0

Before: 0 0 1 1 1 0 . . . 0 1 1

1 1 1 0 . . . 0 1 1 0 1
C

After:

(b) Rotate left with carry RotateLC #2, R0

C R0

0 1 1 1 0 . . . 0 11
Before: 0

1 1 1 0 . . 0 1 1 0 0
after:

(c ) Rotate right without carry RotateR #2, R0

Before: 0 1 1 1 0 . . . 0 1 1 0

1 1 0 1 1 1 0 . . . 0 1
After:

(d) Rotate right with carry RotateRC #2, R0

R0 C

Before: 0 1 1 1 0 . . . 0 1 1 0
R0

after: 1 0 0 1 1 1 0 . . . 0 1

ENCODING OF MACHINE INSTRUCTIONS:-


We have introduced a variety of useful instructions and addressing modes. These
instructions specify the actions that must be performed by the processor circuitry to carry out
the desired tasks. We have often referred to them as machine instructions. Actually, the form
in which we have presented the instructions is indicative of the form used in assembly
languages, except that we tried to avoid using acronyms for the various operations, which are
awkward to memorize and are likely to be specific to a particular commercial processor. To
be executed in a processor, an instruction must be encoded in a compact binary pattern. Such
encoded instructions are properly referred to as machine instructions. The instructions that
use symbolic names and acronyms are called assembly language instructions, which are
converted into the machine instructions using the assembler program.

We have seen instructions that perform operations such as add, subtract, move, shift,
rotate, and branch. These instructions may use operands of different sizes, such as 32-bit and
8-bit numbers or 8-bit ASCII-encoded characters. The type of operation that is to be
performed and the type of operands used may be specified using an encoded binary pattern
referred to as the OP code for the given instruction. Suppose that 8 bits are allocated for this
purpose, giving 256 possibilities for specifying different instructions. This leaves 24 bits to
specify the rest of the required information.

Let us examine some typical cases. The instruction


Add R1, R2

Has to specify the registers R1 and R2, in addition to the OP code. If the processor has 16
registers, then four bits are needed to identify each register. Additional bits are needed to
indicate that the Register addressing mode is used for each operand.
The instruction
Move 24(R0), R5

Requires 16 bits to denote the OP code and the two registers, and some bits to express that
the source operand uses the Index addressing mode and that the index value is 24.
The shift instruction
LShiftR #2, R0

And the move instruction


Move #$3A, R1

Have to indicate the immediate values 2 and #$3A, respectively, in addition to the 18
bits used to specify the OP code, the addressing modes, and the register. This limits the size
of the immediate operand to what is expressible in 14 bits.
Consider next the branch instruction
Branch >0 LOOP

Again, 8 bits are used for the OP code, leaving 24 bits to specify the branch offset.
Since the offset is a 2’s-complement number, the branch target address must be within 223
bytes of the location of the branch instruction. To branch to an instruction outside this range,
a different addressing mode has to be used, such as Absolute or Register Indirect. Branch
instructions that use these modes are usually called Jump instructions.
In all these examples, the instructions can be encoded in a 32-bit word. Depicts a
possible format. There is an 8-bit Op-code field and two 7-bit fields for specifying the source
and destination operands. The 7-bit field identifies the addressing mode and the register
involved (if any). The “Other info” field allows us to specify the additional information that
may be needed, such as an index value or an immediate operand.

But, what happens if we want to specify a memory operand using the Absolute
addressing mode? The instruction

Move R2, LOC

(a) One-word instruction

Opcode Source Dest Other info

(b) Two-Word instruction

Opcode Source Dest Other info

Memory address/Immediate operand

(c ) Three-operand instruction

Op code Ri Rj Rk Other info

Requires 18 bits to denote the OP code, the addressing modes, and the register. This
leaves 14 bits to express the address that corresponds to LOC, which is clearly insufficient.

And #$FF000000. R2

In which case the second word gives a full 32-bit immediate operand.

If we want to allow an instruction in which two operands can be specified using the
Absolute addressing mode, for example

Move LOC1, LOC2


Then it becomes necessary to use tow additional words for the 32-bit addresses of the
operands.

This approach results in instructions of variable length, dependent on the number of


operands and the type of addressing modes used. Using multiple words, we can implement
quite complex instructions, closely resembling operations in high-level programming
languages. The term complex instruction set computer (CISC) has been used to refer to
processors that use instruction sets of this type.

The restriction that an instruction must occupy only one word has led to a style of
computers that have become known as reduced instruction set computer (RISC). The RISC
approach introduced other restrictions, such as that all manipulation of data must be done on
operands that are already in processor registers. This restriction means that the above addition
would need a two-instruction sequence

Move (R3), R1
Add R1, R2

If the Add instruction only has to specify the two registers, it will need just a portion
of a 32-bit word. So, we may provide a more powerful instruction that uses three operands

Add R1, R2, R3

Which performs the operation

R3 [R1] + [R2]

A possible format for such an instruction in shown in fig c. Of course, the processor
has to be able to deal with such three-operand instructions. In an instruction set where all
arithmetic and logical operations use only register operands, the only memory references are
made to load/store the operands into/from the processor registers.

RISC-type instruction sets typically have fewer and less complex instructions than
CISC-type sets. We will discuss the relative merits of RISC and CISC approaches in Chapter
8, which deals with the details of processor design.
ORGANIZATION OF MICROCONTROLLER

A simple microcontroller is as shown in figure. It consists of a processor core, serial I/O port,
parallel I/O port, counter / timer, and memory (RAM & ROM). If the internal memory is not
sufficient, there will be a provision to use external memory.
Parallel I/O ports are used to perform parallel communication (between
peripherals and processor core).
Serial I/O ports are basically used to perform serial communication because all
the devices may not be parallel compatible.
Timers are used to generate timing signals at appropriate time intervals and to
count the number of pulses coming on input line if required.
Internal memory is used to store program and data.

EMBEDDED PROCESSOR: Application specific microcontroller can be called embedded


controllers or embedded processor. The block diagram of embedded processor is shown in
figure
Usually embedded system includes some Analog – devices. To communicate with such
devices analog to digital and digital to analog converters are incorporated on chip.

EMBEDDED SYSTEMS: By using some few embedded controllers, a system can be


developed to perform a given task, and then such system is called embedded system.
Examples of embedded systems are Digital camera, microwave oven, ATM, etc.

DIGITAL CAMERA In a digital camera, an array of optical sensor is used to capture


images. Since the charge is an analog quantity, it is converted into digital format using analog
to digital (A / D) converters. The digitized image is now considered as a 2-d matrix having m
x n pixels and each pixel is given a decimal or hex decimal equivalent number. The processor
processes the digitized image data to generate images represented in standard formats suitable
for use in computers, printers, and display devices. Some of the processing tasks done on an
image are: contrast stretching, brightness modification, smoothing (low pass filtering),
sharpening (high pass filtering) etc. The processed images are stored in a image storage
device. A higher resolution image takes more memory space simply because the numbers of
pixels are more. Also, an uncompressed image takes more space in memory than a
compressed image. The image is displayed on a liquid crystal display (LCD) screen in the
camera. A standard interface provides a mechanism for transferring images to a computer or
a printer. This may be serial or parallel interface or a connector for a standard bus such as
PCI or USB. There are other electromechanical parts such as switches to be operated by the
user, motor to rotate the camera for focusing purpose etc. The system controller must be
capable of generating signals to coordinate and control all such activities.

MICROWAVE OVEN This appliance is based on a magnetron unit, which generates


microwaves used to heat food in a confined space. Using the power levels and the heating
time a parameters, user can have many options for cooking different dishes.

The specification for an oven may include the following options:


 Manual selection of power level and cooking time.
 Manually selected sequence of different cooking steps.
 When the user specifies the type of food (for example, vegetable, or meat) and the
weight of the food, automatic selection of cooking steps.
 Appropriate time and power level computation by the controller when type of food
and weight of the food is specified by user.
The oven includes an output display that can show:
 Time of they day.
 Decrementing clock timer when cooking (showing actual cooking time)
 Information messages to the user.

The oven should produce an audio alert signal when the cooking operation is completed. The
oven should have an exhaust fan (for cooling the magnetron) and a light bulb inside. A switch
should be provided which turns the magnetron off is case; the door of the oven is open. All
these function can be controlled by the controller or processor.

The microwave oven needs some input / out put capability to communicate with the user.
This includes.

 Input keys: Consisting of a number pad having digits 0 to 9 for selected time etc. and
function keys such as reset, start, stop, and auto defrost, clock set, auto cooking, fan
control etc. Some of the functions can be multiplexed to reduce the total number of
keys to be provided. For example, by pressing a key once or twice, different function
can be implemented.
 Visual output in the form of a liquid crystal display (LCD)
 A small speaker that produces the beep tone.

You might also like