Professional Documents
Culture Documents
Next
Course Content
Microprocessor Architecture Addressing Modes Data Movement, Arithmetic logic, and Program control Instructions Programming the Microprocessor Memory Interfacing Interrupts Sensor and Transducer
Microprocessor Architecture
Introduction
Writing a program in assembly language requires knowledge of the Microprocessors hardware (or Architecture) and the details of its instruction set. An explanation of the basic hardware : bit, bytes, registers, memory, microprocessor, and buses is provided in this lecture. The instruction set are listed in the rest lectures[2].
connect it with the outside world, and a clock circuit to act as a master
timer for the system[3]
Next 3
Clock
Microprocessor
Memory
Interface adapter
Input/Output Device
A Basic Microcomputer[3]
Next 4
Memory
Information processed by the computer is stored in its memory [1]. A memory circuit element can store one bit of data. The memory circuits are usually organized into groups that can store eight bits which its called byte. Each memory byte is identified by a number that is called its address, like the street address of a house. The first memory byte has address 0. The data stored in a memory byte are called its contents. The main difference between address and contents 1. The address of memory byte location is fixed but the contents of memory location can be changed 2. The contents of a memory location are always 8-bits, the number of bits in an address depends on the processor. For example, the Intel 8086 microprocessor assigns a 20-bit address, and the Intel 80286 microprocessor uses a 24-bit address
Next 5
Memory
Example: Suppose a processor uses 20-bits for address. How many memory locations can be accessed[1]. Solution: The number of bits used in the address determines the number of memory locations that can be accessed by the precursor a bit can have two possible values, so in a 20-bit address there can be 220 =1,048,576 or 1 megabyte
Memory Address
0 0
Binary Contents
0 0 0 0
1 0
0 1
0 0
1 0
0 1
3 2 1 0 0 0 0 0 0 1 0 0
Memory
Depending on model, the processor can access one or more bytes at a time[2]. In the case two byte word, the processor allows any pair of successive memory locations to be treated as a single unit. The lower address of the two memory locations is used as the address of the memory word Figure (1.3) shows the bit position in a microcomputer word and byte. The position are numbered from right to left starting from 0. in a word, the bits 0 to 7 form low-order least significant byte and bits 8 to 15 form high order most significant byte [1]
7 6 5 4 3 2 Byte Bit Positions 15 14 13 12 11 10 9 8 7 6 5 4 3 2 Word Bit Positions High Byte Low Byte 1 0 1 0
Figure (1.3) Example: Consider the hex number 0529H, requires 2 bytes or 1 word
Next 7
05 29 7612
29 05 7613
The processor reverses the bytes again to retrieve the word from memory
Next 8
Memory Operations
The processor perform two operations on memory : Read operation Fetch, the contents of a memory location the original contents of the location are unchanged. Write operation Store, data at memory location the data written become the new contents of the location and the original contents of the location are lost [1]. The processor communicates with memory and I/O circuits by using signals that travel along a set of wires called buses. There are three kinds of signals : address, data, and control. Also there are three buses: address bus, data bus, and control bus[1].
address bus
Microprocessor
control bus
Memory
I/O Devices
data bus
Next 9
Instruction Execution
Any machine instruction has two parts: Opcode : to specify the type of operation. Operands : which are often given as memory address to the data The microprocessor goes through the following steps to execute a machine instruction (fetch and execute cycle) Fetch cycle Fetch an instruction from memory Decode the instruction to determine the type of operation Execute cycle Retrieve data from memory if necessary Perform the operation on the data Store the result in memory if needed
10 Next
Execution a Program
To understand how the microprocessor operates, consider the following sample of a program Example LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Opcode for LDA Operand (7) Opcode for ADD Operand (10) Opcode for HLT
11
Next
Execution a Program
Before a Program can be run, it must be placed in memory To begin executing the program, the program counter must be set to the address of the first instruction i.e 0000 0000 zero
Microprocessor UNIT
Arithmetic Logic Unit (ALU)
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 0
Instruction Decoder
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100
Binary
Assembly Code
LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
12
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 0
Instruction Decoder
0 0 0 0 0 0 0 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100
Binary
Assembly Code
LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
13
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100
Binary
Assembly Code
LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
14
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 0 Address bus
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Binary
Assembly Code
LDA 7 ADD 10 HLT
15
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Data bus
Binary
Assembly Code
LDA 7 ADD 10 HLT
16
Next
Accumulator
Controller Sequencer
LDA
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100
Binary
Assembly Code
LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
17
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 1
1 0 0 0 0 1 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100
Binary
Assembly Code
LDA 7 ADD 10 HLT
1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
18
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 1 0
Program Counter
Instruction Decoder
0 0 0 0 0 0 0 1
Address Register
1 0 0 0 0 1 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Binary
Assembly Code
LDA 7 ADD 10 HLT
19
Next
Accumulator
Controller Sequencer
0 0 0 0 0 0 1 0
Instruction Decoder
0 0 0 0 0 0 0 1 Address bus
1 0 0 0 0 1 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Binary
Assembly Code
LDA 7 ADD 10 HLT
20
Next
Accumulator
0 0 0 0 0 1 1 1
Controller Sequencer
0 0 0 0 0 0 0 1
Instruction Decoder
0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Data bus
Binary
Assembly Code
LDA 7 ADD 10 HLT
21
Next
Accumulator
0 0 0 0 0 1 1 1
2
0 0 0 0 0 0 1 0
Instruction Decoder 5
1 0 0 0 1 1 0 1
1
0 0 0 0 0 0 1 0
Address bus 3
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Data bus
Binary
Assembly Code
LDA 7 ADD 10 HLT
22
Next
Accumulator
0 0 0 1 0 0 0 1
Controller Sequencer
2
0 0 0 0 0 0 1 1
Instruction Decoder
1
0 0 0 0 0 0 1 1
Address bus 3 0 0 0 0 1 0 1 0
Data Register
MEMORY
Address Contents
0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Data bus
Binary
Assembly Code
LDA 7 ADD 10 HLT
23
Next
Accumulator
0 0 0 1 0 0 0 1
Controller Sequencer
HLT
2
0 0 0 0 0 1 0 0
Instruction Decoder 5
0 0 0 0 1 0 1 0
1
0 0 0 0 0 1 0 0
Address bus 3
Data Register
5. The contents of the data register are decoded by the instruction decoder.
MEMORY
Address Contents
Binary Assembly Code
LDA 7 ADD 10 HLT 0000 0000 0000 0001 0000 0010 0000 0011 0000 0100 1000 0110 0000 0111 1000 1011 0000 1010 0011 1110
Data bus
Execute cycle
1. The execution of the HLT instruction is very simple. The instruction sequencer stops producing control signals then all computer operations stop.
24
Next
Machine Cycle
A clock circuit controls the microprocessor by generating a train of clock pulses as shown
Voltage Time
A one machine cycle can be defined as the minimum time required to fetch a data from memory[1,12],[3,76]. If the microprocessor speed is one megahertz 1MHz, the machine cycle is expressed as: T=1/f =1/1000000 =1 micro second Thus, the fetch cycle of an instruction requires one machine cycle. In inherent and immediate addressing modes ,the execute cycle also requires one machine cycle. Therefore, the minimum time required to fetch and execute any instruction is two machine cycle. As will see later in a lecture of addressing modes
25 Next
Programming languages
We know that, the operations of the computers hardware are controlled by its software. The software program is written by one of the following programming languages:
Machine language
A microprocessor can only execute machine language instructions. As weve seen, they are bit strings from 0 or 1.
Assembly language
A more convenient language to use is the assembly language. In assembly language, we use symbolic names to represent operations, register, and memory location. Such as, mov ax,7 A program written in assembly language must be converted to machine language before the microprocessor can execute it. The assembler is used to translated from assembly language into machine language
26
Next
Programming languages
High-Level language
Different high-level languages are designed for different applications, but they generally allow programmers to write programs that look more like natural language text than is possible in assembly language A program called a compiler is needed to translate a high-level language program into machine code
27
Next
Programming languages
Advantages of Assembly Language
1. Assembly language is so close to machine language, so the assembly language program is efficiency because it produces a faster, shorter machine language program 2. Some operations, such as reading or written to specific memory locations I/O ports, can be done easily in assembly language than high level language 3. Assembly language helps to understand why the operations are executed inside the computer
28
Next
Example :
3932=3x103+9x102+3x101+2x100
29
Next
30
Next
31
Next
25d = 11001b
32
Next
LSB
MSB
33
Next
C 1100
1010 A
Next
The units digit = 6+2 = 8 The tens digit = 4+7 = 11 we write down 1 and carry 1 to hundreds column The hundreds digit = 5+8+1 = 14 we write down 1 and carry 4 to the last column The last digit = 2+1+1 = 4
The units column = 9h+4h = 13h=Dh The next column = 3h+Fh = 12h write down 2 and carry 1 to the next column The next column = Bh+Ah+1h = 16h write down 6 and carry 1 to the next column The last column = 5h+7h+1 = Dh
35 Next
The units column = 1+0= 1 The next column = 1+1= 10 The next column = 1+1+1= 11 And so on
write down 0 and carry 1 to the next column write down 1 and carry 1 to the next column
36
Next
The units digit The tens digit The hundreds digit The last digit
By the same way the Hex and Binary subtraction can be computed
37
Next
38
Next
Decimal Interpretation
We show how signed and unsigned decimal integers may be represented in the computer. In reverse way. Now, we attempt to interpret the contents of a byte or word as signed or unsigned decimal integer Unsigned decimal interpretation Just do a binary to decimal conversion (b to h and then h to d) Signed decimal interpretation If the MSB is 0, the number is positive, the signed decimal is the same as the signed decimal If the MSB is 1, the number is negative, so call it N. To find N, just take the twos complement and the convert to decimal
41
Next
Decimal Interpretation
Example: Suppose AX contains FE0Ch. Give the unsigned and signed decimal interpretations Solution: Unsigned decimal interpretation, convert FE0Ch to decimal yields 65036 For the signed interpretation, FE0Ch=1111 1110 0000 1100. So the sign bit is 1 i.e negative number, call it N. To find N, get the twos complement FE0Ch = 1111 1110 0000 1100 ones complement of FE0Ch = 0000 0001 1111 0011 +1 Twos complement of FE0Ch = 0000 0001 1111 0100 Then, AX contains -500 =01F4h=500d
42 Next
No. Transistors
Physical Memory Internal data bus External data bus Address bus Data type (bits)
4500
64K 8 8 16 8
6500
64K 8 8 16 8
29000
1M 16 16 20 8, 16
29000
1M 16 8 20 8, 16
130000
16M 16 16 24 8, 16
275000
4G 32 32 32 8, 16, 32
1.2million
4G 32 32 32 8, 16, 32
43
Next
45
Next
386 but it has only a 16 bit external data bus and 24 bit address
bus (16`MB)
Execute2
Fetch3
Execute3
Fetch1
Execute1
Fetch2 Execute2
Fetch3
47
Execute3
Next
AX BX CX DX SP BP SI DI CS DS SS ES IP
Internal Bus
Temporary registers
ALU
Flags
Instruction queue
48
Next
External Bus
50
Next
8086 Registers
AX AH BH CH DH
Data Registers AL BL CL DL
The 8086 has four general date registers; the address registers are divided into segment, pointer, and index registers; and the status
BX CX DX
Segment Registers CS DS SS ES
SI DI
SP
BP IP Flags Register
51
Next
8086 Registers
52
Next
Flags Register
The Flags register is an individual 16 bits reflect the result of a computation. There are two kinds of flags:
53
Next
CS : Code Segment
SS : Stack Segment
DS : Data Segment
ES : Extra Segment
Memory Segment
A segment is an area of consecutive memory bytes up to 216 (64kb). Each segment is identified by a segment number, starting
In the 8085 there are only 64 kb of memory for all code, data,
55
Next
address is the 20 bit address that is actually put on the address pins
of the 8086 microprocessor and decoded by address decoder. This address range from 00000h to FFFFFh for the 8086. The offset address is the location within a 64KB segment range. So the offset range from 0000h to FFFFh. The logical address consists of a segment value and an offset address. To obtain a 20 bit physical address, the 8086 microprocessor first
shifts the segment address 4 bit to the left, and then adds the offset.
56
Next
Example
If CS=24F6 and IP=634Ah, show 1. The logical address 24F6:634A
634A
24F60+634A=2B2AA
4. The lower and upper rang of that segment Lower range=24F60+0000=24F60 Upper range=24F60+FFFF=34F5F
57
Next
Instruction Pointer: IP
To access instructions in the code segment, the 8086 uses the registers CS and IP. The CS register contains the segment number and the IP contains the offset
59
Next
60
Next
MOV BX,DX
MOV ES,AX MOV AL,BH
It should be noted that the source and destination registers must match in size. In other words coding MOV CL,AX will give an error. Since the source is a 16-bit register and the destination is an 8bit
61
Next
When the instruction is assembled, the operand comes immediately after the opcode. For this reason, this addressing mode executes
quickly. As an example:
MOV AX,2550H MOV CX,625 MOV BL,40H ;move 2550h into AX ;load the decimal value 625 into CX ;load 625 into BL
In the first two addressing modes, the operands are either inside the microprocessor or tagged along with the instruction which that are not referred to the memory. There are many ways of accessing
62
Next
63
Next
Example
Find the physical address of the memory location and its contents
after the execution of the following, assuming that DS=1512H. MOV AL,99
MOV [3518],AL
Solution First AL is initialized to 99H, then in line two, the contents of AL are stored to logical address DS:3515 which is 1512:3518. shifting DS left and adding it to the offset gives the physical address of (15120H+3518H=18638H). That means after execution of the second instruction, the memory location with address 18638H will contain
64
Next
used for this purpose are SI, DI, and BX as a pointer. For example
MOV AL,[BX] ;moves into AL the contents of the ;memory location pointed to by DS:BX Example : assume that DS=1120, SI=2498, and AX=17FE. Show the contents of memory locations after the execution of
MOV [SI],AX
Solution The contents of AX moves into memory locations with The logical address DS:SI and DS:SI+1; therefore the physical address starts at DS (shifted left) +SI=13698. Low address 13698Hcontains FE, low byte, and high address 13698H will contain 17, the high byte
65 Next
value, are used to calculate the offset address. The physical address
(PA) are DS for BX and SS for BP, For example MOV CX,[BX]+10 MOV AL,[BP]+5
;move DS:BX+10 and DS:BX+10+1 into CX ;physical address=DS(shifted left)+BX+10 ;physical address=SS(shifted left)+BP+5
66
Next
67
Next
MOV AH,[BP][SI]+29
;PA=SS(shifted left)+BP+SI+29
68
Next
Example
Assume that DS=4500,SS=2000,BX=2100,SI=1486,DI=8500,BP=7814, and AX=2512. Show the exact physical memory location where AX is stored in each of the following. All value are in hex a) MOV [BX]+20,AX c) MOV [DI]+4,AX
b) MOV [SI]+10,AX
d) MOV [BP]+12,AX
Solution
In each case PA = segment register (shifted left)+ offset register +
displacement
References
1. Assembly Language Programming and Organization of the IBM PC, Ytha Ya and charles marut
2. Fundamentals of PC Hardware and Software
Next
70
End
71