Microprocessor
Introduction
Analog data representation
Discrete
Digital data representation
Digital Computer
Embedded System
Numbers System
Arithmetic operations
Subtraction
Addition
Minuend: 101101
Augend: 101101
Subtrahend: –100111
Addend: + 100111
Difference: 000110
Sum: 1010100
Division
Multiplication
Dividend: 110111
Divisor: 1100
Subtraction using 2’s complement
Perform subtraction using 2’s complement.
Let M = 1010100; N = 1000100;
(a) Perform M-N:
M 1010100
2’s complement of N = 0111100
end carry -> 1 0010000 Answer: 10000
In case (a) the answer is positive and equal to M – N, which is directly obtained by
discarding the end carry
(b) Perform N-M:
N= 1000100
2’s complement of M = 0101100
No carry -> 1 1 1 0 0 0 0
Answer: – 10000 = – (2’s complement of 1110000)
In case (b) the answer is negative and equal to -(N – M). This case is detected from the
absence of an end carry.
Subtraction using 1’s complement
(a) If an end carry occurs, add 1 to the least significant digit (end-around carry).
(b) If an end carry does not occur, take the 1’s complement of the number obtained in step 1 and
place a negative sign in front.
Comparison between 1’s and 2’s Complements
• Consider the subtraction of the two equal binary numbers 1100 - 1100 = 0.
Using l’s complement:
Complement again to obtain - 0000.
Using 2’s complement:
Signed Binary Numbers
• The negative number may be represented in any one of three different ways:
(i) sign-magnitude (ii) sign-1’s complement (iii) sign-2’s complement
• One bit is for sign
representation
• n bits are for
magnitude
representation
Comparison between 1’s and 2’s Complements
• The 2’s complement is advantageous in that it requires only one arithmetic
addition operation. The l’s complement requires two arithmetic additions when an
end-around carry occurs.
• The l’s complement has the additional disadvantage of possessing two arithmetic
zeros.
Adders
• A combinational circuit that performs the addition of two bits is called a half-adder.
Half-Adder Truth table
Full-Adder Truth table
• One that performs the addition of three bits (two A B Cin Cout
significant bits and a previous carry) is a full-adder.
B A
Cout
Cin
ab+(axorb)c
A
B
Cout
Cin
Binary Parallel Adder
• Performs the addition of two binary numbers which consist of n bits.
ci+1=a.b+(axorb)c
Design of Arithmetic Circuit
F=A+0+1
F = A + 0 + 0 = A,
= A+1
All 1’s = 2’s complement of 1 (-1). A+(-1)+1 = A
F = A + (-1) + 0
= A -1
• A circuit is to be made to produce the true/complement, one/zero element.
True/complement, one/zero circuit
Yi = 0,
Yi = Bi.
Yi = �� .
Yi = Bi + �� = 1.
Logic diagram of arithmetic circuit
Function table for the arithmetic circuit
Effect of output carry in the arithmetic circuit
Design of Logic Circuit
Consider the Boolean function that generates the output sum in a full-adder circuit:
The input carry Ci in each stage can be made to be equal to 0. The result would be:
EX-OR
Logic operations in one stage of arithmetic circuit
Equivalence
NOT
• The input to each full-adder circuit is changed from Ai, to Ai + Bi. This result would be
OR function of A and B
Equivalence
• Let us investigate the possibility of ORing each input Ai with some Boolean
function Ki.
If the variable Ki = Bi’, we obtain an output:
Logic diagram of arithmetic logic unit (ALU)
Function table for the ALU
Overflow
• Assume 3 bits are used to represent the unsigned number
4 -> 100
5 -> 101+
9 <- 1 0 0 1
• The result occupies 4 bits
• When two numbers of n digits each are added and the sum occupies n + 1 digits,
we say that an overflow occurs.
• This is true for binary numbers or decimal numbers whether signed or unsigned.
• A result of n + 1 bits cannot be accommodated in a register of standard length n.
For this reason, many computers check for the occurrence of an overflow.
Overflow with signed numbers
• 3 bits are used to represent the magnitude numbers and 1 bit is used to represent sign
5th 4th 5th 4th
C -> 0 1 C -> 1 0
4 -> 0100 - 4 -> 1100
5 -> 0101+ - 5 -> 1011+
9 <- 1001 - 9 <- 10111
The carry-out occurs at nth bit The carry-out occurs at n+1 th bit
(MSB of the number representation) (Sign bit)
• The binary answer is incorrect and the algorithm for adding binary numbers represented
in 2’s complement as stated previously fails to give correct results when an overflow
occurs.
• An overflow condition can be detected by observing the occurrence of either carry
into the sign-bit position or the carry out of the sign-bit position.
Detection of overflow
5th 4th
C -> 01
4 -> 0100
5 -> 0101+
9 <- 1001
5th 4th
C -> 10
- 4 -> 1100
- 5 -> 1011+
- 9 <- 10111
§ The parallel adder performs addition for n-1 bits and one Full adder (FA) performs addition
of nth bit (Sign bit).
§ The exclusive-OR of the carry out of full-adder ‘Cn’ and the carry out of the full-adder ‘Cn +
1’ gives the overflow indication.
Tri-state buffer
• Two of the states are signals equivalent to binary 1 and 0 as in conventional gates.
• The third state is called a high-impedance state.
• The high-impedance state behaves as if the output is disabled or “floating,” which
means that it cannot affect or be affected by an external signal at the terminal.
Status Register
1. Bit C is set if the output carry of the
ALU is 1. It is cleared if the output carry
is 0.
2. Bit S is set if the highest-order bit of
the result in the output of the ALU (the
sign bit) is 1. It is cleared if the highest-
order bit is 0.
3. Bit Z is set if the output of the ALU
contains all 0’s, and cleared otherwise. Z
= 1 if the result is zero, and Z = 0 if the
result is nonzero.
4. Bit V is set if the exclusive-OR of carries C8 and C9 is 1, and cleared otherwise. This is the condition
for overflow when the numbers are in sign-2’s-complement representation For the 8-bit ALU, V is set
if the result is greater than 127 or less than - 128.
Binary cell
• A binary cell capable of storing one bit of information.
• A flip-flop is capable of storing any binary information
RS Flip-Flop
D flip-flop
JK Flip-Flop
• A JK flip-flop is a refinement of the RS flip-flop in that the indeterminate state of the
RS type is defined in the JK type.
Binary unit with write control
Registers
• A register is a group of flip-flops that can store one bit of information using a binay cell.
Register with parallel load using S-R flip-flops
Register with parallel load using D flip-flops
Binary unit with read and write control
0/1
Register with read and write control
Input
1–n
bits
Select
1st bit nth bit
Read/Write
1–n
bits
Output
The Memory Unit
• A memory unit is a collection of storage registers together with the associated
• circuits needed to transfer information in and out of the registers.
• An address register with n bits can specify up to 2 k
memory words.
• For example, 10 bits of address register can have
1024 locations in the memory unit.
2k location
with one
byte (8bit)
data
k bits for
address
8 bit
data
• The memory unit accepts the address from the MAR and opens the paths needed to
select the word stored in the specified address.
Read Operation:
1. Transfer the address bits of the selected word into MAR.
2. Activate the read control input.
3. The binary information presently stored in memory register 42 is transferred into
MBR.
Write Operation:
1. Transfer the address bits of the selected word into MAR.
2. Transfer the data bits of the word into MBR.
3. Activate the write control input.
4. The data bits from MBR are stored in memory register 42.
Decoder
• The three inputs are decoded into
eight outputs, each output
representing one of the minterms
of the 3-input variables.
Address decoding
1 byte (8bits)
1 byte (8bits)
1 byte (8bits)
1 byte (8bits)
Processor Unit
Instruction Register
A B D F Cin H
Processor Unit
• There are 16 selection variables in the unit, and their function is specified by a control
word.
• The control word is partitioned into six fields, each designated by a letter name
(A, B, Cin, D, F, H).
• The three bits of A select a source register for the input to the left side of the ALU.
• The three bits of B select a source register for the input to the right side of the ALU.
• The D field selects a destination register.
• The F field, together with the bit in Cin, selects a function for the ALU.
• The H field selects the type of shift in the shifter unit.
A field B field
Data selection for A Reg Data selection for B Reg
F field with Cin = 0 F field with Cin = 1
Arithmetic operation Arithmetic operation
H field
Shifting operation
D field
Destination register selection
Control word decoding Assembly
Language/
Opcode/Machine language Mnemonics
000 001 001 001 0 000 Add input data to R1 ADD R1, In
A B D F Cin H
011 010 011 010 1 000 Subtract R2 to R3 SUB R2, R3
100 000 101 000 0 000 Transfer R4 to R5 MOV R5, R4
Circulate-right R1 with carryCRC R1
001 001 001 100 0
101
Machine Language
• The number of bits that form the “word” of a microprocessor is fixed for that
particular processor. These bits define a maximum number of combinations.
• For example, an 8-bit microprocessor can have at most 2 8 = 256 different
combinations.
• However, in most microprocessors, not all of these combinations are used. Certain
patterns are chosen and assigned specific meanings.
• Each of these patterns forms an instruction for the microprocessor.
• The complete set of patterns makes up the microprocessor’s machine language.
Assembly Language
• Entering the instructions using hexadecimal is quite easier than entering the binary
combinations. However, it still is difficult to understand what a program written in
hexadecimal does.
• So, each company defines a symbolic code for the instructions. These codes are
called “mnemonics”.
• The mnemonic for each instruction is usually a group of letters that suggest the
operation performed.
• For example, 00111100 translates to 3C in hexadecimal (OPCODE)
• Its mnemonic is: “INR A”.
• INR stands for “increment register” and A is short for accumulator.
• Another example, 1000 0000 translates to 80 H (OPCODE)
• Its mnemonic is “ADD B”
• “Add register B to the accumulator and keep the result in the accumulator”
• It is important to remember that a machine language and its associated assembly
language are completely machine-dependent. In other words, they are not
transferable from one microprocessor to a different one.
• The assembly language gets translated into machine language in two ways:
(i) Hand assembly: The programmer translates into opcode manually.
(ii) Assembler: A set program that translates the assembly code into opcode
automatically.
High-Level Language
• The programming languages that are intended to be machine-independent are called
high-level languages such as C, C++, Java etc.
• The Compiler or interpreter are programs that accept high-level language instructions
(Source code) and translate them into machine language (Object code) compatible
with the microprocessor used in the system.
Microprocessor
• The word comes from the combination micro and processor.
• Micro represents the size of the device which performs the operations.
• Processor means a device that processes certain operations on binary numbers.
Definition of the Microprocessor:
The microprocessor is a programmable device that takes in numbers, performs
on them arithmetic or logical operations according to the program stored in
memory and then produces other numbers as a result.
• Programmable device: The microprocessor can perform different sets of operations
on the data it receives depending on the sequence of instructions supplied in the
given program. By changing the program, the microprocessor manipulates the data
in different ways.
• Instructions: Each microprocessor is designed to execute a specific group of
operations. This group of operations is called an instruction set. This instruction set
defines what the microprocessor can and cannot do.
• Takes in: The data that the microprocessor manipulates must come from somewhere.
It comes from what is called “input devices”. These are devices that bring data into
the system from the outside world. These represent devices such as a keyboard, a
mouse, switches, and the like.
Numbers: The microprocessor can understand binary numbers.
• A binary digit is called a bit (which comes from binary digit).
• The microprocessor recognizes and processes a group of bits together. This group
of bits is called a “word”.
• The number of bits in a Microprocessor’s word, is a measure of its “abilities”.
Arithmetic and Logic Operations:
• Every microprocessor has arithmetic operations such as add and subtract as part of
its instruction set.
• Most microprocessors will have operations such as multiply and divide.
• Some of the newer ones will have complex operations such as square root.
• In addition, microprocessors have logic operations as well. Such as AND, OR,
XOR, shift left, shift right, etc.
Stored in memory :
• When a program is entered into a computer, it is stored in memory. Then as the
microprocessor starts to execute the instructions, it brings the instructions from
memory one at a time.
Produces:
• For the user to see the result of the execution of the program, the results must be
presented in a human readable form.
• The results must be presented on an output device.
• This can be the monitor, paper from the printer, a simple LED or many other forms.