Computer Arithmetic and Input Output Organzation
Computer Arithmetic and Input Output Organzation
Introduction:
• The EX-OR gate provides 0 as output when the signs are identical. It is
1 when the signs are different.
• A + B is computed for the following and the sum is stored in EA:
1. When the signs are same and addition operation is required.
2. When the signs are different and subtract operation is required.
• The carry in E after addition indicates an overflow if it is 1 and it
is transferred to AVF, the add overflow flag
• A-B = A+ B’+1 computed for the following:
• 1. When the signs are different and addition operation is required.
• 2. When the signs are same and subtract operation is required. No
overflow can occur if the numbers are subtracted and hence AVF is
cleared to Zero.
• A 1 in E indicates that A ≥ B and the number in A is the correct result.
If this number in A is zero, the sign AS must be made positive to avoid a
negative zero.
• A 0 in E indicates that A< B. For this case it is necessary to take the
2’s complement of the value in A.
• In the algorithm shown in flow chart, it is assumed that A register
has circuits for micro operations complement and increment.
• Hence two complement of value in A is obtained in 2, micro operations..
• In other paths of the flow chart, the sign of the result is the same as the sign
of A, so no change in AS is required.
• However, when A < B, the sign of the result is the complement
of original sign of A.
• Hence the complement of AS stored in AS.
• Final Result: As and A
Multiplication Algorithms:
• Multiplication of two fixed-point binary numbers in signed-magnitude
representation is done with process of successive shift and adds operations.
• This process is best illustrated with a numerical example as follows:
Division Algorithm:
• Division of two fixed-point binary numbers in signed magnitude
representation is performed with paper and pencil by a process of successive
compare, shift and subtract operations.
• Binary division is much simpler than decimal division because here the
quotient digits are either 0 or 1.
• The division process is described in Figure
Example of Division Operation:
Hardware Implementation
Division Operation using Pen and Paper:
• The divisor is compared with the five most significant bits of the dividend.
• Since the 5-bit number is smaller than B, we again repeat the same process.
• Now the 6-bit number is greater than B, so we place a 1 for the quotient bit
in the sixth position above the dividend.
• Now we shift the divisor once to the right and subtract it from the
dividend.
• The difference is known as a partial remainder because the division could
have stopped here to obtain a quotient of 1 and a remainder equal to the
partial remainder.
Hardware Implementation for Signed-Magnitude Data
• In hardware implementation for signed-magnitude data in a digital
computer, it is convenient to change the process slightly.
• Instead of shifting the divisor to the right, two dividends, or partial
remainders, are shifted to the left, thus leaving the two numbers in the
required relative position.
• Subtraction is achieved by adding A to the 2's complement of B.
• End carry gives the information about the relative magnitudes.
• The hardware required is identical to that of multiplication.
• Comparing a partial remainder with the divisor continues the process.
• If the partial remainder is greater than or equal to the divisor, the
quotient bit is equal to 1.
• The divisor is then shifted right and subtracted from the partial remainder. If
the partial remainder is smaller than the divisor, the quotient bit is 0 and no
subtraction is needed.
• The divisor is shifted once to the right in any case. Obviously the result
gives both a quotient and a remainder.
• Register EAQ is now shifted to the left with 0 inserted into Qn and the
previous value of E is lost.
• The example is given in Figure to clear the proposed division process.
• The divisor is stored in the B register and the double-length dividend is
stored in registers A and Q.
• The dividend is shifted to the left and the divisor is subtracted by adding its
2's complement value.
• End carry(E) gives the information about the relative magnitudes.
• If E = 1, it signifies that A ≥ B. The quotient bit 1 is inserted into Qn and the
partial remainder is shifted to left to the process.
• If E = 0, it signifies that A < B. So the quotient in Qn remains a 0.
• The value of B is added to restore the partial remainder in A to restore to its
previous value.
• The partial remainder is shifted to the left and the process is repeated again
until all quotient bits are formed.
• The remainder is then found in register A and the quotient is in register Q.
• Before showing the algorithm in flowchart form, we have to consider the
sign of the result and a overflow condition.
Considering the sign of the result and a Overflow condition.
Considerin Normal
g the sign Division
of the Process
result and a
overflow
condition.
• Initially, the dividend is in A & Q and the divisor is in B.
• Sign of result is transferred into Q, to be the part of quotient. Then a
constant is set into the SC to specify the number of bits in the quotient.
• Since an operand must be saved with its sign, one bit of the word will be
inhabited by the sign, and the magnitude will be composed of n -1 bits.
• The condition of divide-overflow is checked by subtracting the divisor in B
from the half of bits of the dividend stored in A.
• If A ≥ B, DVF is set and the operation is terminated before time.
• If A < B, no overflow condition occurs and so the value of the dividend
is reinstated by adding B to A.
Peripheral Devices:
The Input / output organization of computer depends upon the size of computer
and the peripherals connected to it.
The I/O Subsystem of the computer, provides an efficient mode of communication
between the central system and the outside environment
Input/output devices attached to the computer are called Peripheral devices.
The most common input output devices are:
i) Monitor
ii) Keyboard
iii) Mouse
iv) Printer
v) Magnetic tapes
Input Devices
Output Devices
ASCII(American Standard Code for Information
Interchange)- Alphanumeric Characters:
• Input/output devices that communicate with people and the computer are
usually involved in the transfer of Alphanumeric Information to and from
the device and the computer.
• The standard binary code for the alphanumeric characters is ASCII
• It uses 7 bits to code 128 characters.
• ASCII code contains 94 characters that are printable and 34 characters that
are nonprinting characters used for various control functions.
• Among 94, 26 used for uppercase letters, 26 used for lowercase letters,10
are used for numerical and 32 are used for special characters.
• 34 control characters are used for routing and arranging the printed text in a
prescribed format
• 3 types of control characters:
1. Format Effectors (control the layout of printing includes BS-Back
space,HT-Horizontaltab,CR-Carriage Return)
2. Information Separators(used to separate data into paragraphs & pages
includes RS-record seperator and FS-file seperator)
3. Communication control characters (useful for transmission of text
between remote terminals includes STX-Start of text, ETX-End of text)
• The I/O Bus consists of data lines, address lines and control lines.
• The I/O bus from the processor is attached to all peripherals interface.
• To communicate with a particular device, the processor places a device
address on address lines.
• Each Interface decodes the address and control received from the I/O
bus, interprets them for peripherals and provides signals for the
peripheral controller.
• It is also synchronizes the data flow and supervises the transfer between
peripheral and processor.
• Each peripheral has its own controller. For example, the printer controller
controls the paper motion, the print timing
• The processor provides a function code in the control lines.
• The control lines are referred as I/O command.
• The commands are as following:
• Control command- A control command is issued to activate the peripheral
and to inform it what to do.
• Status command- A status command is used to test various status conditions
in the interface and the peripheral.
• Data Output command- A data output command causes the interface to
respond by transferring data from the bus into one of its registers.
• Data Input command- The data input command is the opposite of the data
output.
• In the block diagram fig. (a), the data bus carries the binary information
from source to destination unit.
• Typically, the bus has multiple lines to transfer an entire byte or word.
• The strobe is a single line that informs the destination unit when a valid data
word is available.
• The timing diagram fig. (b) the source unit first places the data on the data
bus.
• The information on the data bus and strobe signal remain in the active state
to allow the destination unit to receive the data.
Data Transfer Initiated by Destination Unit(Destinaation initiated strobe
signal for data transfer)
• In this method, the destination unit activates the strobe pulse, to informing
the source to provide the data.
• The source will respond by placing the requested binary information on the
data bus.
• The data must be valid and remain in the bus long enough for the destination
unit to accept it.
• When accepted the destination unit then disables the strobe and the source
unit removes the data from the bus
Disadvantage of Strobe Signal:
The disadvantage of the strobe method is that, the source unit initiates the
transfer has no way of knowing whether the destination unit has actually
received the data item that was places in the bus.
Similarly, a destination unit that initiates the transfer has no way of knowing
whether the source unit has actually placed the data on bus. The Handshaking
method solves this problem
Handshaking
• The handshaking method solves the problem of strobe method by
introducing a second control signal that provides a reply to the unit that
initiates the transfer.
Principle of Handshaking:
• The basic principle of the two-wire handshaking method of data transfer is
as follow:
• One control line is in the same direction as the data flows in the bus from the
source to destination.
• It is used by source unit to inform the destination unit whether there a valid
data in the bus.
• The other control line is in the other direction from the destination to the
source.
• It is used by the destination unit to inform the source whether it can accept
the data. The sequence of control during the transfer depends on the unit that
initiates the transfer.
Source Initiated Transfer using Handshaking:
• The sequence of events shows four possible states that the system can be at
any given time.
• The source unit initiates the transfer by placing the data on the bus and
enabling its data valid signal.
• The data accepted signal is activated by the destination unit after it accepts
the data from the bus.
• The source unit then disables its data accepted signal and the system goes
into its initial state .
Destination Initiated Transfer Using Handshaking:
• The name of the signal generated by the destination unit has been changed to
ready for data to reflects its new meaning.
• The source unit in this case does not place data on the bus until after it
receives the ready for data signal from the destination unit.
• From there on, the handshaking procedure follows the same pattern as in the
source initiated case.
• The only difference between the Source Initiated and the Destination
Initiated transfer is in their choice of Initial sate
• Advantage of the Handshaking method:
• The Handshaking scheme provides degree of flexibility and reliability
because the successful completion of data transfer relies on active
participation by both units.
• If any of one unit is faulty, the data transfer will not be completed. Such an
error can be detected by means of a Timeout mechanism which provides an
alarm if the data is not completed within time.
• The peripheral device transfers bytes of bytes of data one at a time when
they are available.
• When a byte of data is available, the device places it in the I/O bus and
enables data valid line.
• The interface accepts the data into its data register and enables data accepted
line.
• The interface sets a bit in the status register that is referred as Flag bit(F).
• A program is written for the computer too check for flag in status register to
determine if a byte has placed in the data register by the I/O device.
• This is done by reading the status register to a CPU register and checking
the value of flag bit.
• If F=1, CPU reads the data from data register.
• If F=0, CPU/interface disables the data accepted line.
• A flowchart of the program is written for CPU is shown below
• Here the device is sending a sequence of bytes that must be stored in
memory.
• The transfer of data requires three instructions:
Flowchart:
Drawback of the Programmed I/O :
• The main drawback of the Program Initiated I/O was that the CPU has to
monitor the units all the times when the program is executing.
• Thus the CPU stays in a program loop until the I/O unit indicates that it is
ready for data transfer.
• This is a time consuming process and the CPU time is wasted a lot in
keeping an eye to the executing of program.
• To remove this problem an Interrupt facility and special commands are used.
•
Interrupt-Initiated I/O :
• In this method an interrupt facility called an interrupt command is used to
inform the device about the start and end of transfer.
• In the meantime the CPU executes other program. When the interface
determines that the device is ready for data transfer it generates an Interrupt
Request and sends it to the computer.
• When the CPU receives such an signal, it temporarily stops the execution of
the program and branches to a service program to process the I/O transfer
and after completing it returns back to task, what it was originally
performing.
• In this type of IO, computer does not check the flag. It continue to perform
its task.
• Whenever any device wants the attention, it sends the interrupt signal
to the CPU.
• CPU then deviates from what it was doing, store the return address from PC
and branch to the address of the subroutine.
• There are two ways of choosing the branch address:
• Vectored Interrupt
• Non-vectored Interrupt
• In vectored interrupt the source that interrupts
the CPU provides the branch information. This
information is called interrupt vectored.
• In non-vectored interrupt, the branch address is
assigned to the fixed address in the memory.