Microprocessors Notes - 2018
Microprocessors Notes - 2018
CHAPTER ONE
Moore’s Law
Moore revisited his prediction in 1975 to say that “component density would double
every 18 months”
1
2
Microprocessor
A microprocessor incorporates all the functions of central processing unit (CPU) that
has been integrated on a single integrated circuit. Literally, a microprocessor is a
“CPU on a chip”. It is a semiconductor device consisting of electronic logic circuits
manufactured by using a LSI or VLSI technique.
At the heart of all personal computers and most workstations sits a microprocessor.
Microprocessors also control the logic of almost all digital devices, from clock radios
to fuel-injection systems for automobiles.
The key features of a microprocessor are Arithmetic Logic Unit (ALU), Registers and
Control Unit (CU). There is usually an interface provided to link the processor to
memory and I/O devices through a strip of wires called a bus. There are three types
of busses:
1. Address Bus: The address bus is used to identify the memory location or I/O
device the processor intends to communicate with.
2. Data Bus: Data bus is used by the CPU to get data from / to send data to the
memory or the I/O devices. The width of a microprocessor is used to classify
the microprocessor.
3. Control Bus: may be used to indicate when a valid address is on the address
bus, which direction data are to be transferred over the data bus (in/out),
when external devices can read/write data on the data bus and when valid
read/write data are on the data bus.
The ALU is responsible for all the calculations and logic operations that take place in
the processor while the registers serve as temporary memory locations. The timing
and control unit coordinates all the activities in the processor.
The first microprocessor was 4004 and was developed by Intel in 1971 to be used for
a calculator.
2
3
Figure 1.2: A block diagram of a Microprocessor interfaced with memory and I/O
devices
3
4
Bits
Nibble
A group of four bits handled as a single lump. Examples are 1110, 0010, and 1001
Byte
A byte is simply a collection of 8 bits. Whether they are ones or zeros. Examples are
00000000, 10000101, and 11111111
Word
A number of bits can be collected together to form a ‘word’. Unlike a byte, a word
does not have a fixed number of bits in it. The length of the word or the number of
bits in the word depends on the microprocessor being used. If the microprocessor
accepts binary data in groups of 32 at a time then the word in this context would
include 32 bits. If a different microprocessor uses data in smaller handfuls, say 16 at
a time, then the word would have a value of 16 bits. The most likely values are 8, 16,
32 and 64 bits but no value is excluded.
Long word
In some microprocessors where a word is taken to mean say 16 bits, a long word
would mean a group of twice the normal length, in this case 32 bits.
4
5
Gigabyte (Gb)
Instruction set: The set of instructions that the microprocessor can execute.
Clock speed: Given in megahertz (MHz), the clock speed determines how many
instructions per second the processor can execute.
The technologies used may be transistor-transistor logic (TTL) which is widely used;
complementary-metal-oxide semiconductor (CMOS) which is a choice for portable
computers and other battery-powered devices because of its low power
consumption; and emitter-coupled logic (ECL) which is used in situations where the
need for its greater speed offsets the fact that it consumes the most power.
This is based on the width of data a particular processor can process. The commonly
used formats are 4-bit, 8-bit, 16-bit, 32-bit, or 64-bit. Four-bit processors are
inexpensive and are only good for simple control applications. The wider the data
format, the faster the device.
5
6
Examples of CISC processors: Motorola 68000 family, and AMD and Intel x86 CPUs.
Examples of RISC processors: ARM, AVR, MIPS, PA-RISC, PIC, Power Architecture, and
SPARC.
CISC Characteristics
RISC Characteristics
The RISC architecture has simple, hard-wired instructions which often take only one
or a few clock cycles to execute. RISC machines feature a small and fixed code size
with comparatively few instructions and few addressing modes. As a result,
execution of instructions is very fast, but the instruction set is rather simple.
6
7
7
8
CHAPTER TWO
It is a 16-bit microprocessor
It has a 20-bit address bus and therefore can access up to 1,048,576 memory
locations (220 bytes).
Address ranges from 00000H to FFFFFH
Its word size is 16 bits and double word size is 4 bytes.
It is a 40 pin dual in line package
It has a multiplexed address and data bus AD0 – AD15 and A16 – A19
It is designed to operate in two modes, Minimum and Maximum
It fetches up to 6 instruction bytes from memory and queues them in order
to speed up instruction execution (pipelining).
8
9
AD15±AD0 - ADDRESS DATA BUS: These lines constitute the time multiplexed
memory/IO address and data bus.
ALE - Address Latch Enable. A HIGH on this line causes the lower order 16-bit address
bus to be latched that stores the addresses and then, the lower order 16bit of the
address bus can be used as data bus.
READY: READY is the acknowledgement from the addressed memory or I/O device
that it will complete the data transfer.
INTR -INTERRUPT REQUEST: is a level triggered input which is sampled during the
last clock cycle of each instruction to determine if the processor should enter into an
interrupt acknowledge operation. A subroutine is vectored to via an interrupt vector
lookup table located in system memory. It can be internally masked by software
resetting the interrupt enable bit. INTR is internally synchronized. This signal is active
HIGH.
INTA -Interrupt Acknowledge from the MP
NMI -NON-MASKABLE INTERRUPT: an edge triggered input which causes an interrupt
request to the MP. A subroutine is vectored to via an interrupt vector lookup table
located in system memory. NMI is not maskable internally by software.
RESET: causes the processor to immediately terminate its present activity. The signal
must be active HIGH for at least four clock cycles. It restarts execution
MN/MX: MINIMUM/MAXIMUM: indicates what mode the processor is to operate in.
The two modes are discussed in the following sections.
M/IO: Differentiates between the Memory and I/O operation. A LOW on this pin
indicated I/O operation and a HIGH indicated a Memory Operation
HOLD: The 8086 has a pin called HOLD. This pin is used by external devices to gain
control of the busses.
HLDA: When the HOLD signal is activated by an external device, the 8086 stops
executing instructions and stops using the busses. This would allow external devices
to control the information on the 8086 MINIMUM AND MAXIMUM MODES of
operation
MN/MX
9
10
Minimum mode
The 8086 processor works in a single processor environment known as Minimum
mode. All control signals for memory and I/O are generated by the microprocessor.
Maximum mode
This mode is desirable when a coprocessor exists in the system, that is,
multiprocessor environment. Control signals for memory and I/O are generated by
an external BUS Controller.
The Intel 8086 and 8088 microprocessors are the basis of most modern
microprocessors. The 8086 processor consists of two internal units: the Bus Interface
Unit (BIU) and the Execution Unit (EU).
10
11
The BIU generates the 20-bit physical memory address and facilitates
communication between the EU and the memory or Input/output circuits. To speed
up execution, 6-bytes of instruction are fetched in advance and kept in a 6-byte
Queue while other instructions are being executed in the EU. Therefore after
execution, the next instruction is directly fetched from the instruction queue in First-
In-First-Out (FIFO) without having to wait for the external memory to send the
instructions. When there is a jump instruction, the microprocessor must flush out
the queue. When a jump instruction is executed BIU again fetches information from
the new location in the memory. In this situation EU must wait until the BIU starts to
fetch the new instruction. This is known as branch penalty.
Execution Unit – EU
The execution unit contains the arithmetic and logic unit (ALU) that performs
arithmetic and logical operations. The EU has eight registers – AX, BX, CX, DX, SP, BP,
SI, and DI for storing data during program execution. A decoder in the EU translates
instructions fetched from memory into a series of actions to be carried out by the
EU. There is also a 16-bit flag register of which nine are active. During execution, the
EU may test the status and control flags and update these flags based on results of
execution.
11
12
1. Informing B.I.U (bus interface unit) from where to fetch instruction of data
and where to store the data.
2. Decodes the op-codes which is fetched from queue register and then execute
that instruction.
2.2 Registers
Registers are located inside the CPU therefore they are much faster than memory.
Registers are a collection of flip-flops. Accessing a memory location requires the use
of a system bus which takes much longer than accessing data in a register.
The general purpose registers are AX, BX, CX, and DX. These four are made of two
separate 8-bit registers, for example if AX= 0011000000111001B, then
AH=00110000B and AL=00111001B. The most significant byte is represented by “H”
and the least significant byte is represented by “L”. The same applies to all the other
3 registers.
BX - Base Register usually contains a data pointer used for based, based indexed or
register indirect addressing.
12
13
SP – Stack Pointer is used to hold the offset address of the data stored at the top of
the stack segment. SP is used along with the SS register to decide the address at
which data is to be pushed or popped during the PUSH and POP instructions.
A stack is a section of memory set aside to store addresses and data while
subprogram executes. The Stack Segment Register is used to hold the upper 16 bits
of the starting address for the program stack. Items are added and removed from
one end of the structure that is it is processed in Last in First out (LIFO) manner. The
most recent addition to the stack is called the top of the stack. Stack is used by CALL
instruction to keep return address for procedure, RET instruction gets value from the
stack and returns the offset. RET instruction can also be used to return to the
operating system.
PUSH stores 16 bit value in the stack and POP gets 16 bit value from the stack.
BP – Base Pointer is used to hold the offset address of the data to be read from or
written into the stack
SI – Source Index is used to hold the offset address of the source data segment while
executing string instructions.
DI – Destination Index is used to hold the offset address of the destination data in
extra segment, while executing the string instructions.
13
14
Segment Registers
The four segment registers in 8086 processor are Code Segment (CS), Data Segment
(DS), Stack Segment (SS), and Extra Segment (ES). These are generally used to hold
the upper 16 bits of the starting address of four memory segments that the 8086 is
working with at a particular time.
1. CS Register: This register contains the initial address of the code segment.
This address plus the offset value contained in the instruction pointer (IP)
indicates the address of an instruction to be fetched for execution.
2. SS Register: The stack segment register contains the initial address of the
stack segment. The address plus the value contained in the stack pointer (SP)
is used for stack operations.
3. DS Register: The data segment register contains the initial address of the
current data segment. This address together with the offset value in
instruction causes a reference to specific location in the data segment. By
default, the processor assumes that all data referenced by the general
registers (AX, BX, CX, DX) and index registers (SI, DI) are located in the data
segment.
4. ES Register: Extra segment is used by some string operations. The extra
segment register contains the initial address of the extra segment string
instructions always use the ES and DI registers to calculate the physical
address for the destination. The processor also assumes by default, that the
DI register references the ES segment in string manipulation instructions.
14
15
There are special combinations of segment registers and general registers that point
to important addresses:
CS: IP - points to the address where the processor will fetch the next byte of
code.
SS:SP – points to the address top of the stack ( the most recently pushed
byte)
DS: SI – is often used to point to string data that is about to be copied to
ES:DI.
ES: DI – is typically used to point to the destination for a string copy.
The table below however offers other possible combinations of segment and offset
registers.
Segment Register CS DS ES SS
Offset register(s) IP SI,DI,BX SI, DI, BX SP, BP
Table 2.1: Segment and offset registers combination
Flag Register
15
16
These flags are set or reset by the EU on the basis of the results of some arithmetic
operations. The six conditional flags are Carry Flag (CF), Parity Flag (PF), Auxiliary Flag
(AF), Zero Flag (ZF), Sign Flag (SF), and the Overflow Flag (OF).
Carry Flag
The carry flag will be set to 1 if the addition of two 16-bit binary numbers produces a
carry out of the MSB position. If no carryout of MSB is produced by the addition,
then the carry flag will be zero.
1000011101001110
1001100100001001
0010000001010111
A carry is generated at the Most Significant Bit (MSB) so the carry flag will set, that is
CF=1.
Parity Flag
PF=1 if the low byte of a result has an even number of 1’s (Even parity)
16
17
1000011101001110
1001100100001001
0010000001110111
The lower 8 bits of the result (01110111) has 6 1’s (Even parity) as such PF = 1.
1000011101001110
1001100100001001
0010000001110111
Zero Flag
1000000000000000
1000000000000000
0000000000000000
Sign Flag
After the execution of arithmetic or logical operation, if the most significant bit
(MSB) result is 1, then the sign flag will be set otherwise it will be reset.
If the value of MSB is 1, then it indicates a negative number. If the value of MSB is 0,
it means the number is positive.
17
18
Control Flags
The control flags are Trap Flag (TF), Interrupt Flag (IF) and Direction Flag (DF). These
flags are used to enable or disable certain operations of the processor.
Trap Flag
Interrupt Flag
If the Interrupt Flag is zero (IF = 0) then INTR pin is disabled. If the Interrupt Flag, IF
=1, then INTR pin is enabled.
Direction Flag
18
19
address range 0000016 to FFFFF16. The 8086 can access any two consecutive bytes as
a word of data. The lower-addressed byte is the least significant byte of the word,
and the higher- addressed byte is its most significant byte. The starting and end
address of each segment is given in the table 2.1 below:
Segment Starting address End Address
1st Segment 00000 H 0FFFF H
2nd Segment 10000 H 1FFFF H
3rd Segment 20000 H 2FFFF H
4th Segment 30000 H 3FFFF H
---------- -------- ---------
---------- -------- ---------
16th Segment F0000 H FFFFF H
Table 2.1: Starting and ending address of segments.
Memory segments can overlap or two or more segments could even coincide. This is
indicated in the figure 2.4 below:
19
20
Example 1
CS:IP
438B:2467
To derive the 20-bit Physical Address of memory from a given logical address,
1. Multiply Segment register by 10H ( or shift it to left by four bit)
2. Add it to the offset
Example 2
If CS = 002AH, and IP = 0023H, write the logical address that they represent, then
map it to Physical address.
002A : 0023
Example 3
Ex: If CS=24F6H and IP=634AH, determine:
a) The logical address
b) The offset address
c) The physical address
d) The lower range of the code segment
e) The upper range of the code segment
Solution
a) The logical address is; 24F6:634A
b) The offset address is; 634A
c) The Physical address is; 24F60+634A= 2B2AA
20
21
d) The lower range of the code segment: 24F6:0000 => 24F60+0000 =24F60
e) The upper range of the code segment: 24F6:FFFF => 24F60+FFFF=34F5F
Exercise
With reference to the contents of the following registers:
CS = 1111 H, DS = 3333 H, SS = 2526 H, IP = 1232 H, SP = 1100 H, DI = 0020 H
Calculate the corresponding physical addresses (effective addresses) for the address
bytes in CS, DS and SS. In each case, state the corresponding logical address.
21
22
CHAPTER THREE
Programming language
Programming language is a set of rules that tells the computer what operations to
perform. This set of rules may differ from microprocessor to microprocessor or may
be interpreted differently by different microprocessors.
22
23
3.2 Micro-operations
A micro-operation is an elementary operation performed on the information stored
in one or more registers. The result of the operation may replace the previous binary
information of a register or may be transferred to another register.
There are four main types of micro-operations and these are:
Arithmetic Micro-operations: these involve operations such as addition,
subtraction, increment, decrement, add with carry, subtract with borrow,
and so on.
23
24
24
25
MOV ES, AX
ADD AL, BH
MOV AL, CX ; not possible due varying register sizes.
Exercise: Find the physical address of the memory location and its content
after the execution of the following operation. Assume DS=1512H
MOV AL, 99H
MOV [3518], AL
Physical address of DS: 3518 => 15120+3518=18638H
The memory location 18638H will contain the value 99H
Register indirect addressing: this mode is similar to the direct addressing but
the offset is specified in a base register (BX), base pointer (BP) or an index
register (SI or DI) within the 8086. The offset is usually combined with DS to
generate the 20-bit physical address.
25
26
Examples:
MOV AL, [BX] ; moves into AL the contents of the memory location
pointed to by DS:BX
MOV CL, [SI] ; move contents of DS:SI into CL
MOV [DI], AH ; move the contents of AH into DS:DI
Based addressing: In this mode, the effective address is obtained by adding a
direct or indirect displacement to the contents of either the base register BX
or Base pointer BP. The default segments used for the calculation of physical
address are DS for BX, or SS for BP
Examples:
MOV CX, [BX]+10 ; move DS:BX+10 and DS:BX+11 into CX
; PA = DS (shifted left) +BX+10
• Note that, the content of the low address will go into CL and the
high address contents will go into CH.
• There are alternative coding: MOV CX,[BX+10], MOV CX,10[BX]
• BX+10 is effective address
MOV AL,[BP]+5 ; PA = SS (shifted left) +BP+5
Indexed addressing: this mode work in similar manner to that of the based
addressing mode but the effective address is obtained by adding the
displacement to the value in an index register (SI or DI). SI and DI hold the
offset address.
Examples:
MOV DX, [SI]+5 ;PA=DS(shifted left)+SI+5
MOV CL, [DI]+20 ;PA=DS(shifted left)+DI+20
MOV AL, [SI]+1234H
26
27
Alternative coding:
MOV CL,[BX+DI+8]
MOV CL,[DI+BX+8]
27
28
Arithmetic instructions
ADDITION
ADD Sums the specified byte/word to a byte/word
ADC Sums considering also the value of the carry flag
INC Increments the specified byte or word by 1
AAA Adjusting ASCII after addition
DAA Adjusting decimal after an addition
SUBTRACTION
SUB Subtracts the specified byte or word
SBB Subtracts considering also the value of the carry flag
DEC Decrements the specified byte or word by 1
NEG Calculates the complement to 2 (Negate byte or word)
CMP Compare two bytes or words
ASS Adjusting ASCII after subtraction
DAS Adjusting decimal after subtraction
MULTIPLICATION
MUL Multiplies bytes or words without sign
IMUL Multiplies bytes or words with sign
AAM Adjusting ASCII after the multiplication
DIV Divides a word without sign by a byte, or double word without sign by a
word
IDIV Divides a word with sign by a byte, or double word with sign by a word
AAD Adjusting ASCII before the division
CBW Convert byte to word
28
29
Bit manipulation
LOGICALS
NOT Inverts each bit of a byte or word
AND AND byte or word
OR ‘Inclusive or’ byte or word
XOR ‘Exclusive or’ byte or word
TEST Follows the same operations of an AND, but doesn’t change the value of the
operands
SHIFTS
SHL/ Shifts logical/arithmetic to the left the bit of a word or of a byte
SAL
SHR Shifts to the right the bit of a word or of a byte
SAR Shifts arithmetic right the bit of a word or of a byte
ROTATES
ROL Rotates to the left the bit of a word or of a byte, puts MSB in LSF and CF
ROR Rotates to the right the bit of a word or of a byte, LSB in MSB and CF
RCL Rotates to the left the bit of a word or of a byte, MSB in CF and CF in LSB
RCR Rotates to the right the bit of a word or of a byte, LSB in CF and CF in MSB
String instructions
A string is a series of bytes or words in sequential locations of the memory. It is
normally formed from ASCII characters.
29
30
30
31
31
32
MOV Instruction
MOV destination, source ; copy source operand to destination
Types of instruction format
Instructions come as three address instructions, two address instructions, one
address instructions or zero address instructions.
Three address instructions: Computers that use this type of instruction
format use three address fields to specify either a processor register or a
memory operand.
For example: ADD R1, A, B ; R1 M[A] + M[B]
It is clear from the example that 3 addresses are specified: one register
address, and two memory addresses. Example of computer using this type of
instruction is Cyber 170.
Two address instructions: two addresses are specified in this type of
instruction format.
Example: ADD R1, A ; R1 M[A] + M[B]
It can be observed that one register as well as one memory operand are
specified. Register R1 is both the source and the destination. Most
commercial computers use this type of instruction.
One address instructions: one register, usually the Accumulator register is
used for all data manipulation.
Example: ADD B ; AC C + M[B]
All operations are done between the Accumulator and a memory operand.
Commercially available computers also use this type of instruction format.
Zero address instructions: a stack organized computer does not require an
address field for computational instructions. Due to the absence of the
address field it is known as zero address instructions.
Example: PUSH A ; STACK A
PUSH B ; STACK B
ADD ; STACK (A+B)
32
33
Mnemonic operands
Example: (8-bit)
MOV CL,55H ;move 55H into register CL
MOV DL,CL ;move/copy the contents of CL into DL (now DL=CL=55H)
MOV BH,DL ;move/copy the contents of DL into BH (now DL=BH=55H)
MOV AH,BH ;move/copy the contents of BH into AH (now AH=BH=55H)
Example: (16-bit)
MOV CX,468FH ;move 468FH into CX (now CH =46 , CL=8F)
MOV AX,CX ;move/copy the contents of CX into AX (now AX=CX=468FH)
MOV BX,AX ;now BX=AX=468FH
MOV DX,BX ;now DX=BX=468FH
MOV DI,AX ;now DI=AX=468FH
MOV SI,DI ;now SI=DI=468FH
MOV DS,SI ;now DS=SI=468FH
MOV BP,DS ;now BP=DS=468FH
33
34
XOR
XOR destination, source
Example: MOV DH,54H
XOR DH,78H
Interpretation: 54H 01010100
78H 01111000
2CH 00101100 SF=0, ZF=0, PF=0, CF=OF=0
SHIFT
SHR destination, source ;shift right
The operand is shifted right bit by bit, and for every shift the LSB will go to the CF and
MSB is filled with a zero.
Example: MOV AL,9AH
MOV CL,3 ;set number of times to shift
SHR AL,CL
Interpretation: 9AH 10011010
01001101 CF=0 (shifted once)
00100110 CF=1 (shifted twice)
00010011 CF=0 (shifted three times)
After three times of shifting AL=13H and CF=0
Note: The destination operand can be in a register or memory. Immediate
addressing mode is not possible. If the destination operand is to be shifted once only
1 can be used instead of CL.
SHL
34
35
The operand is shifted left bit by bit, and for every shift the LSB is filled with a zero
(0) and the MSB goes into CF.
Example: MOV DH,6
MOV CL,4 ;set number of times to shift
SHL DH,CL
Interpretation: 00000110
CF=0 00001100 (shifted left once)
CF=0 00011000
CF=0 00110000
CF=0 01100000 (shifted left 4 times)
Note: The destination operand can be in a register or memory. Immediate
addressing mode is not possible. If the destination operand is to be shifted once only
1 can be used instead of CL.
ROTATE INSTRUCTIONS
• ROR rotate right
Note: LSB is moved to MSB and is copied to CF. CL holds the number of rotations. If
to be rotated once, 1 is used.
35
36
Note: The operands themselves remain unchanged. The destination operand can be
in register or memory. The source operand can be in register, memory or an
immediate number. Only the CF and ZF are affected.
36
37
Steps
1. Take the 2’s complement of the subtrahend (source operand)
2. Add it to the minuend (destination operand)
3. Invert the carry
Execution steps:
AL 3F 0011 1111 0011 1111
– BH – 23 – 0010 0011 + 1100 0001 (2’s complement)
1C 0001 1100 1 0001 1100
37
38
Example: DATA7 DB 95
DATA8 DB 10
QUOT1 DB ?
38
39
REMAIN1 DB ?
; using direct mode
MOV AL,DATA7 ;AL holds numerator
SUB AH,AH ;AH must be cleared
DIV DATA8 ;divide AX by DATA8
MOV QUOT1,AL ;quotient = AL = 09
MOV REMAIN1,AH ;remainder = AH = 05
; using register addressing mode
MOV AL,DATA7 ;AL holds numerator
SUB AH,AH ;AH must be cleared
MOV BH,DATA8 ;move denominator to a register
DIV BH ;divide AX by BH
MOV QUOT1,AL ;quotient = AL = 09
MOV REMAIN1,AH ;remainder = AH = 05
; using the immediate addressing mode will give an error
MOV AL,DATA7
SUB AH,AH
DIV 10 ; immediate mode is not allowed
2. word / word
Numerator must be in AX and DX must be cleared
Denominator can be in memory or in a register.
After the division AX will have the quotient and DX will have the remainder
Example:
MOV AX,10050 ;AX holds numerator
SUB DX,DX ;DX must be cleared
MOV BX,100 ;BX is used for denominator
DIV BX ;divide AX by BX
MOV QUOT2,AX ;quotient = AX = 64H (100 )
MOV REMAIN2,DX ;remainder = DX = 32H (50)
3. word / byte
39
40
Numerator must be in AX
Denominator can be in memory or in a register.
After the division AL will have the quotient and AH will have the remainder
Example:
MOV AX,2055 ;AX holds numerator
MOV CL,100 ;BX is used for denominator
DIV CL ;divide AX by CL
MOV QUO,AL ;AL holds the quotient = AL = 14H (20)
MOV REMI,AH ;AH holds the remainder = AH = 37H (55)
CHAPTER FOUR
4.1 Memories
Memories are circuits or systems that store digital information temporally or
permanently. Semiconductor memories are mostly fabricated using the VLSI
40
41
Memory organization
If the number of segments is 2n then n-lines will be required to select the segment to
be written into. The address inputs are decoded by the address decoder to select
only one of the memory segments for either reading or writing.
For a memory device with n-bit address a memory device with n-bit address lines
and word size of m-bits, the memory has 2n words (2n x m).
Example: if n=10 and m=8, the memory is a 1024x8 bit memory or 1K bytes.
Memory Hierarchy
41
42
Cache Memory
42
43
When a program loop is executed, the CPU repeatedly refers to the set of
instructions in memory that constitute the loop. Every time a given subroutine is
called, its set of instructions are fetched from memory. Thus loops and subroutines
tend to localize the references to memory for fetching instructions. To a lesser
degree, memory references to data also tend to be localized. Table-lookup
procedures repeatedly refer to that portion in memory where the table is stored.
Iterative procedures refer to common memory locations and array of numbers are
confined within a local portion of memory. The result of all these observations is the
locality of reference property, which states that over a short interval of time, the
addresses generated by a typical program refer to a few localized areas of memory
repeatedly, while the remainder of memory is accessed relatively infrequently.
If the active portions of the program and data are placed in a fast small memory, the
average memory access time can be reduced, thus reducing the total execution time
of the program. Such a fast small memory is referred to as a cache memory. It is
placed between the CPU and main memory in the memory hierarchy. The cache is
the fastest component in the memory hierarchy and approaches the speed of CPU
components.
The fundamental idea of cache organization is that by keeping the most frequently
accessed instructions and data in the fast cache memory, the average memory
access time of a computer system can be improved considerably by use of cache.
When the CPU refers to memory and finds the word in cache, it is said to produce a
hit. If the word is not found in cache, it is in main memory and it counts as a miss.
The basic characteristic of cache memory is its fast access time. Therefore, very little
or no time must be wasted when searching for words in the cache. The
43
44
Three types of mapping procedures are of practical interest when considering the
organization of cache memory.
1. Associative mapping
The fastest and most flexible cache organization uses an associative memory. This
organization is illustrated in Figure 4.4. The associative memory stores both the
address and content (data) of the memory word. This permits any location in cache
to store any word from main memory. The diagram shows three words presently
stored in the cache. The address value of 15 bits is shown as a five-digit octal number
and its corresponding 12-bit word is shown as a four-digit octal number. A CPU
address of 15 bits is placed in the argument register and the associative memory is
searched for a matching address. If the address is found, the corresponding 12-bit
data is read and sent to the CPU. If no match occurs, the main memory is accessed
for the word. The address data pair is then transferred to the associative cache
memory. If the cache is full, an address – data pair must be displaced to make room
for a pair that is needed and not presently in the cache. The decision as to what pair
is replaced is determined from the replacement algorithm that the designer chooses
for the cache. A simple procedure is to replace cells of the cache in round-robin
order whenever a new word is requested from main memory. This constitutes a first-
in first-out (FIFO) replacement policy.
44
45
2. Direct mapping
In the general case, there are 2k words in cache memory and 2n words in main
memory. The n-bit memory address is divided into two fields: k bits for the index
45
46
field and n − k bits for the tag field. The direct mapping cache organization uses the
n-bit address to access the main memory and the k-bit index to access the cache.
The internal organization of the words in the cache memory is as shown in Figure
4.6(b). Each word in cache consists of the data word and its associated tag. When a
new word is first brought into the cache, the tag bits are stored alongside the data
bits. When the CPU generates a memory request, the index field is used for the
address to access the cache.
The tag field of the CPU address is compared with the tag in the word read from the
cache. If the two tags match, there is a hit and the desired data word is in cache. If
the two tags match, there is a hit and the desired data word is in cache. If there is no
match, there is a miss and the required word is read from main memory. It is then
stored in the cache together with the new tag, replacing the previous value. The
disadvantage of direct mapping is that the hit ratio can drop considerably if two or
more words whose addresses have the same index but different tags are accessed
repeatedly. However, this possibility is minimized by the fact that such words are
relatively far apart in the address range (multiples of 512 locations in this example).
46
47
3. Set-associative mapping.
As mentioned earlier one disadvantage of direct mapping is that two words with the
same index in their address but with different tag values cannot reside in cache
memory at the same time. Set-associative mapping is an improvement over the
direct-mapping organization in that each word of cache can store two or more words
of memory under the same index address. Each data word is stored together with its
tag and the number of tag-data items in one word of cache is said to form a set. An
example of a set-associative cache organization for a set size of two is shown in
Figure 4.7. Each index address refers to two data words and their associated tags.
Each tag requires six bits and each data word has 12 bits, so the word length is
An index address of nine bits can accommodate 512 words. Thus the size of cache
memory is 512 × 36. It can accommodate 1024 words of main memory since each
word of cache contains two data words. In general, a set-associative cache of set size
k will accommodate k words of main memory in each word of cache.
The octal numbers listed in Figure 4.7 are with reference to the main memory
content illustrated in Figure 4.6. The words stored at addresses 01000 and 02000 of
main memory are stored in cache memory at index address 000. Similarly, the words
47
48
at addresses 02777 and 00777 are stored in cache at index address 777. When the
CPU generates a memory request, the index value of the address is used to access
the cache. The tag field of the CPU address is then compared with both tags in the
cache to determine if a catch occurs. The comparison logic is done by an associative
search of the tags in the set similar to an associative memory search: thus the name
“set-associative”. The hit ratio will improve as the set size increases because more
words with the same index but different tags can reside in cache. However, an
increase in the set size increases the number of bit s in words of cache and requires
more complex comparison logic.
When a miss occurs in a set-associative cache and the set is full, it is necessary to
replace one of the tag-data items with a new value. The most common replacement
algorithms used are: random replacement, first-in, first out (FIFO), and least recently
used (LRU). With the random replacement policy the control chooses one tag-data
item for replacement at random. The FIFO procedure selects for replacement the
item that has been in the set the longest. The LRU algorithm selects for replacement
the item that has been least recently used by the CPU. Both FIFO and LRU can be
implemented by adding a few extra bits in each word of cache.
Main Memories
There are two types of primary or main memories: volatile and non-volatile. Volatile
memory is the type of memory that will lose data when the power supply to the
memory goes off. An example of volatile memory is Random Access Memory (RAM).
Non-volatile memory keeps the data in the memory even it is not powered up (e.g.
ROM).
RAM
48
49
The two most common types of RAMs are the static RAM (SRAM) and the dynamic
RAM (DRAM). Static RAMs hold the stored value in flip-flop circuits as long as the
power is on. SRAMs tend to be high-speed memories with clock cycles in the range
of 5 to 50 ns.
Dynamic RAMs store values on capacitors. They are prone to noise and leakage
problems, and are cheaper and slower than SRAMs, clocking at 50 ns to 200 ns.
However, DRAMs are much denser than SRAMs—up to four times denser in a given
generation of technology.
49
50
DRAM Operation
Address line active when bit read or written: — Transistor switch closed
(current flows)
Write: — Voltage is applied to bit line (High for 1 low for 0) then address line
is activated. Transistor allows current to flow; transfers charge to capacitor
Read: — Address line is activated – Transistor allows current to flow;
transfers charge from capacitor to bit line — Bit line fed to sense amplifier –
Compares with reference value to determine 0 or 1 — Capacitor charge must
be restored to complete the read operation
ROM
All ROMs are non-volatile, but they vary in the method used to enter (write) stored
data.
50
51
Erasable Programmable Read-Only Memories (EPROMs): also have all bits initially
in one binary state. They are programmed electrically (similar to the PROM), but all
bits may be erased (returned to the initial state) by exposure to ultraviolet (UV) light.
The packages for these components have transparent windows over the chip to
permit the UV irradiation. Electrically Erasable Programmable Read-Only Memories
(EEPROMs, E2PROM, or E-squared PROMs): may be written and erased by electrical
means. These are the most advanced and most expensive form of PROM. Unlike
EPROMs, which must be totally erased and rewritten to change even a single bit,
E2PROMs may be selectively erased. Writing and erasing operations for all PROMs
require times ranging from microseconds to milliseconds.
A recent form of EPROM and E2PROM is termed Flash memory, a name derived from
the fact that blocks of memory may be erased simultaneously. Flash memory of the
EPROM form is written using the hot-electron effect2 whereas E2PROM Flash is
written using Fowler-Nordheim (FN) tunnelling. Both types are erased using FN
tunnelling. Their large storage capacity has made this an emerging mass storage
medium. In addition, these types of memories are beginning to replace the role of
ROMs on many chips, although additional processing is required to manufacture
Flash memories in a standard CMOS technology.
Auxiliary Memory
The most common auxiliary memory devices used in computer systems are magnetic
disks and tapes. Other components used, but not as frequently, are magnetic drums,
magnetic bubble memory, and optical disks. Although the physical properties of
these storage devices can be quite complex, their logical properties can be
characterized and compared by a few parameters. The important characteristics of
any device are its access mode, access time, transfer rate, capacity, and cost.
51
52
The average time required to reach a storage location in memory and obtain its
contents is called the access time. In electromechanical devices with moving parts
such as disks and tapes, the access time consists of a seek time required to position
the read-write head to a location and a transfer time required to transfer data to or
from the device. Because the seek time is usually much longer than the transfer
time, auxiliary storage is organized in records or blocks. A record is a specified
number of characters or words. Reading or writing is always done on entire records.
The transfer rate is the number of characters or words that the device can transfer
per second, after it has been positioned at the beginning of the record.
Magnetic drums and disks are quite similar in operation. Both consist of high-speed
rotating surfaces coated with a magnetic recording medium. The rotating surface o f
the drum is a cylinder and that of the disk, a round flat plate. The recording surface
rotates at uniform speed and is not stared or stopped during access operations. Bits
are recorded as magnetic spots on the surface as it passes a stationary mechanism
called a write head. Stored bits are detected by a change in magnetic field produced
by a recorded spot on the surface as it passes through a read head. The amount of
surface available for recording in a disk is greater than in a drum of equal physical
size. Therefore, more information can be stored on a disk than on a drum of
comparable size. For this reason, disks have replaced drums in more recent computers
Virtual memory is a concept used in some large computer systems that permit the
user to construct programs as though a large memory space were available, equal to
the totality of auxiliary memory. In a virtual memory system, programmers are made
to believe that they have the total address space at their disposal. Moreover, the
address field of the instruction code has a sufficient number of bits to specify all
virtual addresses. Each address that is referenced by the CPU goes through an
address mapping from the so-called virtual address to a physical address in main
memory. Virtual memory is used to give programmers the illusion that they have a
52
53
very large memory at their disposal, even though the computer actually has a
relatively small main memory. A virtual memory system provides a mechanism for
translating program-generated addresses into correct main memory locations. This is
done dynamically, while programs are being executed in the CPU. The translation or
mapping is handled automatically by the hardware by means of a mapping table.
An address used by a programmer will be called a virtual address, and the set of such
addresses the address space. An address in main memory is called a location or
physical address. The set of such locations is called the memory space. Thus the
address space is the set of addresses generated by programs as they reference
instructions and data; the memory space consists of the actual main memory
locations directly addressable for processing. In most computers the address and
memory spaces are identical. The address space is allowed to be larger than the
memory space in computers with virtual memory.
In a multi-program computer system, programs and data are transferred to and from
auxiliary memory and main memory based on demands imposed by the CPU.
Suppose that program 1 is currently being executed in the CPU. Program 1 and a
portion of its associated data are moved from auxiliary memory into main memory
as shown in Figure 4.10. Portions of programs and data need not be in contiguous
locations in memory since information is being moved in and out, and empty spaces
may be available in scattered locations in memory.
53
54
Figure 4.10: Relation between address and memory space in a virtual memory
system
In this example, the address field of an instruction code will consist of 20 bits but
physical memory addresses must be specified with only 15 bits. Thus CPU will
reference instructions and data with a 20-bit address, but the information at this
address must be taken from physical memory because access to auxiliary storage for
individual words will be prohibitively long. (Remember hat for efficient transfers,
auxiliary storage moves an entire record to the main memory). A table is then
needed, as shown in Figure 4.11 to map a virtual address of 20 bits to a physical
address of 15 bits. The mapping is a dynamic operation, which means that every
address is translated immediately as a word is referenced by CPU.
The mapping table may be stored in a separate memory as shown in Figure 4.11 or in
main memory. In the first case, an additional memory unit is required as well as one
extra memory access time. In the second case, the table takes space from main
memory and two accesses to memory are required with the program running at half
speed. A third alternative is to use an associative memory as explained below.
54
55
55
56
The transfer of data between a fast storage device such as magnetic disk and
memory is often limited by the speed of the CPU. Removing the CPU from the path
and letting the peripheral device manage the memory buses directly would improve
the speed of transfer. This transfer technique is called direct memory access (DMA).
During DMA transfer, the CPU is idle and has no control of the memory buses.
Two control signals in the CPU that facilitate the DMA transfer are the bus request
input and bus grant output. The bus request (BR) input is used by the DMA controller
to request the CPU to relinquish control of the buses. When this input is active, the
CPU terminates the execution of the current instruction. The CPU activates the bus
grant (BG) output to inform the external DMA that the buses are in the high-
impedance state. The DMA that originated the bus request can now take control of
the buses to conduct memory transfers without processor intervention.
When the DMA terminates the transfer, it disables the bus request line. The CPU
disables the bus grant, takes control of the buses, and returns to its normal
56
57
operation. When the DMA takes control of the bus system, it communicates directly
with the memory.
4.3 Pipelining
Pipelining is a technique used that allows multiple instructions to be overlapped in
execution. This allows different parts of the hardware to work on different
instructions at the same time.
Pipeline
It is a series of stages of work to be done as required in an instruction. Each of these
stages or steps is referred to as Pipe stage. Once a stage is completed, it passes the
result to the next segment in the pipeline and fetches the next operations from the
preceding stage. When an instruction proceeds from one stage to the next, it is
temporarily stored in a pipeline latch, so it does not interfere with a previous
instruction.
The time required for moving an instruction from one stage to the next is known as a
machine cycle (one clock cycle). The execution of one instruction involves several
machine cycles as it goes through the pipeline.
A basic five-stage pipeline in a RISC machine is illustrated in figure 4.13 below. (IF =
Instruction Fetch, ID = Instruction Decode, EX = Execute, MEM = Memory access, WB
= Register write back). In the fourth clock cycle (the green column), the earliest
instruction is in MEM stage, and the latest instruction has not yet entered the
pipeline.
57
58
Advantages of pipelining
It ensures an efficient use of the processor
The time taken to execute instructions are most often reduced
Disadvantages of pipelining
It involves the addition of hardware/hardware complexity
The full potential of pipelining may not be achieved due to pipeline hazards.
Pipeline Hazards
For efficient pipelining, each stage of the instruction execution must be completed in
the same time but this is not usually the case. Pipelining hazards occur when the
next instruction cannot proceed until the previous instruction has either completed
or reached a certain point in the pipeline. The three kinds of pipelining hazards are:
structural hazards, data hazards and control hazards.
Structural hazards: these occur when a hardware component does not support the
execution of two instructions at the same time. An instance of structural hazard may
arise in a situation whereby instruction is being fetched from memory at the same
time another instruction is being written to memory.
Data hazards: these arise when a needed operand is not ready, because either the
current instruction has not finished computing it, or it has not arrived from storage.
Control hazards: they occur due to branch operations or branches in code. That is
when there is a need for a decision to be made based on the result of an instruction.
58
59
CHAPTER FIVE
5.1 Microcontrollers
Whereas a microprocessor may be viewed as ‘CPU on chip’, a microcontroller is
usually described as ‘computer on chip’. Even though microcontroller share some
features with microprocessor, they differ in many aspects.
The microcontroller has built-in ROM, RAM, I/O ports, Timers, Serial Ports and other on-chip
peripherals to execute a single and dedicated task. This means that a microcontroller
requires less hardware to build a complete system.
Microcontrollers are mainly used in products that require a degree of control to be exerted by
the user.
Memory: The memory is sometimes split into program memory and data memory. In
larger controllers, a DMA controller handles data transfers between peripheral
components and the memory.
59
60
Interrupt Controller: Interrupts are useful for interrupting the normal program flow
in case of (important) external or internal events. In conjunction with sleep modes,
they help to conserve power.
Timer/Counter: Most controllers have at least one and more likely 2-3
Timer/Counters, which can be used to timestamp events, measure intervals, or
count events. Many controllers also contain PWM (pulse width modulation) outputs
which can be used to drive motors or for safe breaking (antilock brake system, ABS).
Furthermore the PWM output can, in conjunction with an external filter, be used to
realize a cheap digital/analog converter.
Digital I/O: Parallel digital I/O ports are one of the main features of microcontrollers.
The number of I/O pins varies from 3-4 to over 90, depending on the controller
family and the controller type.
As far as digital I/O is concerned, three registers control the behaviour of the pins:
Data Direction Register (DDR): Each bidirectional port has its own DDR, which
contains one bit for each pin of the port. The functionality of a pin (input or output)
is determined by clearing or setting its bit in the DDR. Different pins of a port may be
configured differently, so it is perfectly okay to have three pins configured to output
and use the other five as inputs. After a reset, the DDR bits are generally initialized to
input. Reading the register returns its value.
Port Register (PORT): This register is used to control the voltage level of output pins.
Assuming a pin has been configured to output. If its bit in the PORT register is set,
the pin will be high; if the bit is cleared, the pin will be low. To avoid overwriting the
other bits in the port when setting a particular bit, it is generally best to use the
controller’s bit operations. Otherwise, you must use a read-modify-write access and
hence must ensure that this access is not interrupted. For output pins, reading the
register returns the value you have written. For input pins, the functionality depends
on the controller. Some controllers allow you to read the state of input pins through
the port register. Other controllers, e.g. the ATmega16, use the port bits for other
60
61
purposes if the corresponding pins are set to input, so here you will read back the
value you have written to the register.
Port Input Register (PIN): The PIN register is generally read-only and contains the
current state (high or low) of all pins, whether they are configured as output or as
input. It is used to read the state of input pins, but it can also be used to read the
state of output pins to verify that the output was taken over correctly. A write to this
register generally has no effect.
Analog I/O: Apart from a few small controllers, most microcontrollers have
integrated analog/digital converters, which differ in the number of channels (2-16)
and their resolution (8-12 bits). The analog module also generally features an analog
comparator. In some cases, the microcontroller includes digital/analog converters.
Interfaces: Controllers generally have at least one serial interface which can be used
to download the program and for communication with the development PC in
general. Parallel connections between the microcontroller and peripherals
established over I/O ports are the ideal solution for shorter distances up to several
meters. However, in other cases, when it is necessary to establish communication
between two devices on longer distances it is obviously not possible to use parallel
connections. Then, serial communication is the best solution. Many microcontrollers
also contain integrated bus controllers for the most common busses.
If for any reason (usually electrical noise in industry), the program counter "gets
stuck" at some memory location from which there is no return, the watchdog will
61
62
not be cleared, so the register’s value being constantly incremented will reach the
maximum et voila! Reset occurs!
Debugging Unit: Some controllers are equipped with additional hardware to allow
remote debugging of the chip from the PC. So there is no need to download special
debugging software, which has the distinct advantage that erroneous application
code cannot overwrite the debugger.
Interrupt: In order to prevent the microcontroller from spending most of its time
endlessly checking for logic state on input pins and registers, an interrupt is
generated. It is the signal which informs the central processor that something
demands. As its name suggests, it interrupts regular program execution. It can be
generated by different sources so when it occurs, the microcontroller immediately
stops operation and checks for the cause. If it is needed to perform some operations,
a current state of the program counter is pushed onto the Stack and the appropriate
program is executed. This process is called interrupt routine.
There are two things worth attention concerning the microcontroller power supply
circuit:
Brown out is a potentially dangerous state which occurs at the moment the
microcontroller is being turned off or when power supply voltage drops to the
lowest level due to electric noise. Since the microcontroller consists of several
circuits which have different operating voltage levels, this can cause its out of control
performance. In order to prevent it, the microcontroller usually has a circuit for
brown out reset built-in. This circuit immediately resets the whole electronics when
the voltage level drops below the lower limit.
Reset pin is usually referred to as Master Clear Reset (MCLR) and serves for external
reset of the microcontroller by applying logic zero (0) or one (1) depending on the
type of the microcontroller. In case the brown out is not built in the microcontroller,
a simple external circuit for brown out reset can be connected to this pin.
62
63
Von-Neumann/Princeton Architecture
Example: An Instruction “Read a byte from memory and store it in the accumulator”
as follows:
63
64
Harvard Architecture
Microcontrollers based on the Harvard Architecture have separate data bus and an
instruction bus. This allows execution to occur in parallel. As an instruction is being
“pre-fetched”, the current instruction is executing on the data bus. Once the current
instruction is complete, the next instruction is ready to go. This pre-fetch
theoretically allows for much faster execution than Von-Neumann architecture, on
the expense of complexity. Figure 5.3 shows the Harvard Architecture. The Harvard
Architecture executes instructions in fewer instruction cycles than the Von-Neumann
architecture. For example, the Intel MCS-51 family of microcontrollers and PIC
microcontrollers uses Harvard Architecture. The same instruction (as shown under
Von-Newman architecture) would be executed as follows:
64
65
Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt
schedule circuitry (in addition to CPU) in a single chip.
Reactive systems: are those that have an ongoing interaction with their
environment - for example, a fire-control system that constantly reacts to
buttons pressed by a pilot.
Embedded systems are those used to control specialized hardware in which
the computer system is installed - for example, the microprocessor system
used to control the fuel/air mixture in the carburettor of many automobiles.
In embedded systems the software system is completely encapsulated by the
hardware that it controls.
65
66
A special application that microcontrollers are well suited for is data logging. Stick
one of these chips out in the middle of a corn field or up in a balloon, and monitor
and record environmental parameters (temperature, humidity, rain, etc). Small size,
low power consumption, and flexibility make these devices ideal for unattended data
monitoring and recording.
66
67
PAST QUESTIONS
SECTION A
1. A microprocessor is a _______ chip integrating all the functions of a CPU of a
computer.
a. single b. double. c. all of the above d. None of the above
3. The BIU pre-fetches the instruction from memory and store them in ________.
a. queue. b. register. c. memory. d. stack.
67
68
13. The memory unit that communicates directly with the CPU is called ______?
23. For a logical circuit there are 'n' binary inputs. Then the number of different input
combinations in the truth table is
a. 2n b. 2/n c. 2n d. 2(n+1)
68
69
30. Which of these memories holds the information when the Power Supply is
switched off?
a. Static RAM b. Dynamic RAM c. EEROM d. None of the above
33. In _______ addressing mode the operand is given explicitly in the instruction.
a. Absolute. b. Immediate. c. Indirect. d. Direct.
36. _______ are instructions that copy information from one location to another
either in the processor’s internal register set or in the external main memory.
a. Data transfer instructions. b. Program control instructions.
69
70
c. Bit-operation d. Byte-operation
39. Which of the following statements correctly describe the Arithmetic logic unit?
I. perform arithmetic operations II. store data
41. Which of these two registers of the 8086 µP combine to form the address of the
next instruction?
a. SS and CS b. ES and DI c. DS and SP d. IP and CS
42. Which of these two registers of the 8086 µP combine to point to the destination
for a string copy?
a. SS and CS b. ES and DI c. DS and SP d. IP and CS
43. The pre-fetched instructions in the 8086 µP Queue are implemented by means of
_______.
a. LIFO buffer b. FIFO buffer c. Stack d. None of the above
44. The following instruction: MOV AL, 59H is specified for 8086 µP. What type of
addressing mode is used?
a. Direct addressing mode b. Register addressing mode
70
71
b. internal timer that sets the system if the software fails to operate properly.
c. internal timer that resets the system if the software fails to operate properly.
49. In 8086 µP the BIU pre-fetches instructions from memory and stores them in
________.
a. queue. b. register. c. memory. d. stack.
50. Which of the following technology can give high speed RAM?
a. TTL b. CMOS c. ECL d. NMOS
SECTION B
1. a. With the aid of a clearly labeled block diagram, explain what a microcontroller
is. [5marks]
71
72
3. Using only MOV, ADD, INC, NOT and HLT instructions, write an assembly language
program for an Intel 8086 µP that will load AL with 3FH and BL with 23H; subtract
the content of BL from AL, and keep the result in AL.
it is the average memory access time can be reduced, thus reducing the total
execution time of the program. Such a fast small memory
is a concept used in some large computer systems that permit the user to
construct programs as though a large memory space were available
Structural hazards: these occur when a hardware component does not support the
execution of two instructions at the same time. An instance of structural hazard may
arise in a situation whereby instruction is being fetched from memory at the same
time another instruction is being written to memory.
Data hazards: these arise when a needed operand is not ready, because either the
current instruction has not finished computing it, or it has not arrived from storage.
Control hazards: they occur due to branch operations or branches in code. That is
when there is a need for a decision to be made based on the result of an instruction.
72
73
5. a. List and explain the two sub-divisions of the flag register in the 8086
microprocessor. [4marks]
b. Given that AX = 874EH and BX = 9901H, determine whether ZF, CF and OF will
be set or reset after the following operations:
i) ADD AX, BX ii) XOR BX, AX [6marks]
SECTION A
1. Assembly language
a. uses alphabetic codes in place of binary numbers used in machine
language
d. None of these
73
74
a. Register b. Encoder
14. n bits in operation code imply that there are ___________ possible distinct
operators
74
75
a. 2n b. 2n c. n/2 d. n2
15. A group of bits that tell the computer to perform a specific operation is
known as __________
a. Instruction code b. Micro-operation
c. Accumulator d. Register
c. Bit-operation d. Byte-operation
21. An interface that provides a method for transferring binary information
between internal storage and external devices is called ________
a. I/O interface b. Input interface
23. The instructions which copy information from one location to another either
in the processor’s internal register set or in the external main memory are
called _______
a. Data transfer instructions. b. Program control instructions.
25. The 2s compliment form (Use 6 bit word) of the number 1010 is _______
a. 111100. b. 110110. c. 110111. d. 1011.
26. A register capable of shifting its binary information either to the right or the
left is called a ________
a. parallel register. b. serial register.
29. The memory unit that communicates directly with the CPU is called the
a. main memory b. Secondary memory
33. Which of the following statements correctly describe the Arithmetic logic
unit?
I. Perform arithmetic operations II. Store data
76
77
37. Given that the BL register contains 1111 0000, the effect of the following
instruction OR BL, 0000 1111 is to ….
a. clear BL b. store 1111 1111 in BL
c store 0000 1111 in BL d. leave BL unchanged
39. Which of the following technology can give high speed RAM?
a. TTL b. CMOS c. ECL d. NMOS
40. After reset, CPU begins execution of instruction from memory address
a. 0101H b. 8000H c. 0000H d. FFFFH
44. The memory unit that communicates directly with the CPU is called ______?
a. main memory b. Secondary memory
SECTION B
case. [8marks]
Arithmetic Micro-operations:
I. Addition
II. Subtraction
III. Increment
IV. decrement, add with carry
V. subtract with borrow
Logic Micro-operations:
I. AND operator
II. OR operator
III. XOR operator
IV. Complement/NOT operator
78
79
Shift Micro-operations: these involve logical shift (right shift/ left shift),
circular shift (right circular shift/left circular shift), and arithmetic shift
operations (right arithmetic shift/left arithmetic shift).
Register transfer micro-operations: The data transfer instructions are used to
move data between internal registers or between internal register and the
memory. The content of the source remains the same after the execution of
data transfer instructions. Flags are not affected by any of the instruction in
the group.
2. With the aid of clearly labelled block diagrams differentiate between a
microprocessor and a microcontroller. [10marks]
Microprocessor
Microcontroller
79
80
3. a. Write and explain the instruction format for Intel 8086. [6marks]
b. Consider the following MOV instructions written for an Intel 8086 µP.
I. Code segment
II. Data segment
III. Extra segment
IV. Stack segment
5. a. Explain with examples the two main categories of bits in the flag register.
[4marks]
(a) Conditional or Status Flags and
(b) Control Flags.
80
81
b. Explain the following addressing modes and give an example in each case.
[8marks]
Direct addressing:
The address of the data in memory comes immediately after the instruction operand
is a constant. The address is the offset address and this is put in a rectangular
bracket.
Example:
81
82
Exercise: Find the physical address of the memory location and its content
after the execution of the following operation. Assume DS=1512H
MOV AL, 99H
MOV [3518], AL
Physical address of DS: 3518 => 15120+3518=18638H
The memory location 18638H will contain the value 99H
Indexed addressing: this mode work in similar manner to that of the based
addressing mode but the effective address is obtained by adding the displacement to
the value in an index register (SI or DI). SI and DI hold the offset address.
Examples:
MOV DX, [SI]+5 ;PA=DS(shifted left)+SI+5
MOV CL, [DI]+20 ;PA=DS(shifted left)+DI+20
MOV AL, [SI]+1234H
82