Download - Microprocessors used in Personal Computers
Microprocessors used in Personal Computers
Manufacturer Processor Data Bus Address Bus Memory size
Intel 8086 16 20 1M8088 8 20 1M80386 32 32 4G80486 32 32 4G + 8K CachePentium 64 32 4G + 16K CachePentium Pro 64 36 64G + 16K L1 Cache
+ 256 L2 CacheMotorola 6800 8 16 64K
68000 16 24 16M68040 32 32 4G + 8K CachePowerPC 64 32 4G + 32K Cache
The Memory Map of a Personal Computers
• Transient Program Area (TPA): Holds the operating system (interrupt vectors, DOS BIOS, devices drivers, Command.com) and application programs.
• System Area: Holds the ROM BIOS, the video buffer area, and the BASIC language ROM.
• Extended Memory: Memory above the 1M conventional memory found in AT compatible computers . Its size depends on the RAM installed on the motherboard, and is limited by the size of the processor’s address bus.
TPA640K
System Area384K
ExtendedMemory
15M . . 64G
The 80x86 Programming Model
AH ALAX AccumulatorEAX
BH BLBX BaseEBX
CH CLCX CountECX
DH DLDX DataEDX
SP Stack PointerESP
BP Base PointerEBP
DI Destination IndexEDI
SI Source IndexESI
IP Instruction PointerEIP
Flags Flag RegisterEFLAGS
CS Code Segment0
DS 0
0
ES 0
SS
FS 0
GS 0
Data Segment
Stack Segment
Extra Segment
078151631
80386 to Pentium only
The Flag Register
• Z (zero): This flag is set to one if the result of the last arithmetic or logic instruction is zero.
• S (sign): This flag is set to one if the MSBit of the result of the last arithmetic or logic instruction is one, indicating a negative number .
• C (carry): This flag is set to one if the last arithmetic instruction gave a carry out or a borrow in.
• O (overflow): This flag is set to one if the result of the last arithmetic operation on signed numbers exceeded the capacity of the destination register.
NT
14
IOP1
13
IOP0
12
O
11
D
10
I
9
T
8
S
7
Z
6
A
4
P
2
C
0
VIF
19
AC
18
VM
17
RF
1631
ID
21
VIP
20
8088/8086
80286
80386
80486
Pentium
80x86 Modes of operation
• Protected mode– Programs are given separate memory areas (segments)– Programs are not allowed to access memory outside of their
segments
• Real-address mode– Environment of 8086 processor– Direct access to system memory and hardware devices– The operating system could crash
• System management mode– Provides an operating system for implementing power
management and system security functions (computer manufacturers)
Segmentation
• Segmentation is used to allow relocation of programs, i.e. programs can be loaded on different memory areas and still run correctly.
• Segmentation is used in the 8088/8086 microprocessors to allow the generation of 20-bit addresses using 16-bit registers.
• In the Real Mode Operation a 20-bit address (effective address) is obtained by shifting the segment address 4 bits to the left (X10H) and then adding the offset address.
• The offset address is specified in the program. The segment address is specified by the operating system whenever the program is loaded.
• The code segment holds the machine codes of the program.The Instruction Pointer specifies the offset address in the code segment.
• The data segment holds the data used by the program. Most data references are specified in the data segment.
• The stack segment holds the stack of the program. The offset address in the stack segment is specified with the registers SP and BP.
• The extra segment is used as a data segment by some data movement instructions.
Segmentation (Example)
If DS =1600H find the maximum area occupied by the data segment. Find also the effective address, if the offset address is 1F00H.
Starting address = DS X 10H = 1600H X 10H
= 16000H
Ending address = Starting address + FFFF
= 16000H + FFFFH = 25FFFH
Effective address = Segment:Offset = 1600:1F00
= Segment address X 10H +
Offset
= 1600H X 10H + 1F00H
= 16000H + 1F00H = 17F00H
64Kbytesegment
FFFFF
25FFF
17F00
16000
00000
1600
SegmentRegister
Offset 1F00
Assembler Directives
Directives are instructions given by the programmer to the assembler on how to assemble the program.
Directives are not part of the instruction set of the microprocessor.
The use of directives might vary from assembler to assembler.
Some of the MASM 6.12 assembler directives are:– ORG (Origin): Tells the assembler where to store the machine code of
the next instruction.
– EQU (Equate): Tells the assembler to assign a value to an identifier.
– SEGMENT: Tells the assembler to begin a new segment.
– ASSUME: Tell the assembler to associate a segment with a segment register.
– PROC (Procedure): Tells the assembler to begin a new procedure.
– MACRO: Assigns the sequence of instructions to an identifier.
– END: Ends a program, segment (ENDS), a procedure (ENDP), or a macro (ENDM).
Data Definition Directives
• Data Definition directives tell the assembler to store the specified data in the next memory locations. Data that occupies more than one location is stored with the LSByte in the lower address.
– (DB) Define Byte (1 byte or 8 bits - Same as BYTE)
– (DW) Define Word (2 bytes or 16 bits - Same as WORD)
– (DD) Define Double Word (4 bytes or 32 bits - Same as DWORD)
– (DQ) Define Quad Word (8 bytes or 64 bits - Same as QWORD)
– (DT) Define Ten Bytes (10 bytes or 80 bits - Same as TBYTE)
Examples:• ABC DB 26H ;ABC=26H• XYZ DB 35H,87H,0A4H ;XYZ= {35H,87H,A4H}• YOU DB ‘JOHN’ ;YOU = ‘JOHN’• VAL DW 1254H ;VAL = 1254H• X1 DB ? ;X1 = UNSPECIFIED• X4 DB 3 DUP(20H) ;X4 = {20H,20H,20H}• N1 DB 123H ;INVALID
Data Definitions (Example)
Show the content of the memory based on the following data definitions:
ORG 100H
VAL1 EQU 21H
AB10 DB 37
NEW DB 23H,56H,’$’
LOT DW 1245H
XY11 DB ‘NEXT’
A123 DD 123H
B561 DB 4 DUP(40H)
VAL2 DB VAL1
AB10
Label
NEW+0
NEW+1
NEW+2
LOT
XY11+0
XY11+1
XY11+2
A123
XY11+3
B561+1
B561+0
B561+2
B561+3
VAL2
DS:0100
Address
DS:0101
DS:0102
DS:0103
DS:0105
DS:0104
DS:0106
DS:0107
DS:0108
DS:010A
DS:0109
DS:010B
DS:010C
DS:010D
DS:010F
DS:010E
DS:0110
DS:0111
DS:0112
Content
12H
45H
Format of DOS programs
• All programs must have a code and a stack.
– Code is the part of the program that contains the instructions of the program.
– Stack is an area in the RAM used by the system to store return addresses, and by the programmer to store temporarily data. It is a Last In First Out (LIFO) buffer.
• Programs can also have a data area, where all data (variables) is stored.
• There are two basic types of programs:
– Commands (.COM). The data and the stack of the program are part of the Code segment. The stack is always located at the end of the segment. The first 256 bytes of the segment are reserved.
– Executable (.EXE). The code and stack and data of the program are located in different segments.
Format of the .COM programs
CSEG SEGMENT PARA 'CODE’ ;Start a Code segment
ASSUME CS:CSEG, DS:CSEG, SS:CSEG
ORG 100H ;Reserve first 256 locations
START: JMP MAIN ;Skip data area
{Place the data of the program here}
MAIN PROC NEAR ;Beginning of main procedure
{Place the code of the program here}
RET ;Get return DOS address
MAIN ENDP ;End of main procedure
CSEG ENDS ;End of the segment
END START ;End of the program
Addressing Modes
Addressing mode refers to the way the data
needed by an instruction is specified.
Immediate Addressing Mode
• The data needed is specified as a number in the machine code of a program. The data is specified by the programmer:
– as a numeric operand in the instruction,
e.g. MOV AL,87H ;AL 87H
MOV CX,34A6H ;CX 34A6H
MOV BL,8C2H ;Invalid (Data Mismatch)
– or as a label. The actual value is determined by the assembler.
e.g. MOV BX,OFFSET VAL3 ;BX Address of VAL3
MOV AH,CON1 ;AH CON1
Immediate Addressing Mode (Example)
Instructions
AX
MOV CX,CON2
BX SI
Label Address Data
0105
0106
0107
0108
0109
010A
010B
010C
010D
MOV BX,OFFSET DAT1
MOV SI,2310H
MOV AL,CON1
MAIN PROC NEAR
MOV AX,283CH
MOV AX,OFFSET DAT3
CX
ORG 100H
CON1 EQU 6CH
CON2 EQU 245AH
STRT: JMP MAIN
AH AL BH BL CH CL
DAT1 DB 2FH,48H
DAT3 DW 37AH
DAT2 DB 4 DUP (0)
0100
0101
0102
0103
0104
Register Addressing Mode
• Both of the operands are the contents of registers.
e.g. MOV AL,BH ;AL BH
MOV BX,CX ;BX CX
MOV AX,DL ;Invalid (Data Mismatch)
• Example:Instructions AX
MOV CX,AX
BX SI
MOV BX,CX
MOV AL,DH
MOV AH,AL
MOV SI,DX
CX DX
AH AL BH BL CH CL DH DL
36 20 EE A5 90 89 73 F6 2006
Direct Addressing Mode
• One of the operands is the contents of the memory location that is specified directly in the instruction.
e.g. MOV AL,[1008H] ;AL [1008H]
MOV BX,VALUE ;BX [VALUE]
Instructions
AX
MOV DX,VAL1
BX Label Address Data
0105
0106
MOV BX,[0108H]
MOV AL,[0104H]
MOV CH,FRST
MOV AH,ARR1
MOV CL,ARR1+3
CX DX
AH AL BH BL CH CL DH DL
0107
0108
0109
0103
0104
FRST
VAL1
ARR1
C1
56
87
9F
A6
75
8C
Register Indirect Addressing Mode
• One of the operands is the contents of the memory location that is specified by a register, or a combination of registers and an offset, in the instruction.
Index: Use of SI or DI to specify a memory location.
e.g. MOV AL,[SI] ;AL [SI]
- Base: Use of BX or BP to specify a memory location.e.g. MOV AH,[BP] ;AL [BP]
- Base Relative: Use of BX or BP in combination with an offset to specify a memory location.
e.g. MOV AL,[BX+ 2] ;AL [BX + 2]
- Base Relative plus Index: Use of BX or BP in combination with an index register (SI or DI) and an offset to specify a memory location.
e.g. MOV AL,[BX+SI+8] ;AL [BX+SI+8]
MOV BX,ARR[BX+DI] ;BX ARR[BX+DI]
Register Indirect Addressing Mode (Example)
Instructions
AX
MOV AX,DAT1[DI]
BX SI
Label Address Data
0105
0106
0107
0108
0109
010A
010B
010C
010D
MOV AL,[BX]
MOV AH,DAT2[SI]
MAIN PROC NEAR
MOV AL,[BX+SI]
MOV AH,[BX+DI+3]
DI
ORG 100H
STRT: JMP MAIN
AH AL BH BL
DAT1 DB 2FH,48H
DAT3 DW 7A5H
DAT2 DB 12H,10H,18H
0100
0101
0102
0103
0104
DAT4 DW 37H
DAT5 DB 10H
77 45 01 04 0001 0002
Addressing Modes (Example)
Instructions AX
MOV AX,2F8AH
BX SI Address Label Address Data
0112
0111
0110
010F
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
4F
8C
5A
AC
93
59
4F
A3
7E
F4
09
8A
5C
6A
MOV BX,OFFSET LAB4
MOV SI,3
MOV AL,LAB1
MOV AH,BL
MOV AL,LAB2+3
MOV AX,LAB3
MOV AL,LAB2[SI]
MOV AL,[BX+1]
MOV AL,[SI+102]
MOV AL,[BX+SI-1]
MOV AL,LAB4[SI+2]
MOV AL,LAB2[SI+5]
MOV AL,LAB3+1
Addr. Mode
Lab1
Lab2+0
Lab2+1
Lab2+2
Lab2+3
Lab3+0
Lab3+1
Lab4+0
Lab4+1
Lab4+2
Lab4+3
Lab4+4
ExamplesIndicate whether or not each of the following MOV instructions is valid or invalid• MOV AX,BX• MOV DX,BL• MOV ECX,EDX• MOV SI,DI• MOV DS,AX• MOV AL,DH• MOV AX,DH• MOV IP,AX• MOV SI,CL• MOV EDX,AX• MOV AX,ES
• MOV AX,16
• MOV DX,7F65H
•MOV ECX,6F23458H
•MOV SI, -1
•MOV DS,1000H
•MOV AL,100H
•MOV 123,DH
•MOV 0FABH,AX
•MOV SI, CL
•MOV EDX,ESI
•MOV EDX,-2