Mikroprosesor dan Antarmuka
M
Instruksi Mikroprosesor
LOGO
-I
TT EL
KO
Oleh. Junartho Halomoan (
[email protected])
N
Mode Pengalamatan-Jenis[1]
JU
Addressing Mode / Mode Penglamatan : adalah cara, bagaimana 8088 dapat mengakses operand Mode Pengalamatan pada 80x86: – – – – – – –
(1) register (2) immediate (3) direct (4) register indirect/ register tidak langsung (5) based relative/ relatif berbasis (6) indexed relative/ relatif berindex (7) based indexed relative/ relatif berbasis dan index
1
Mode Pengalamatan - Reg [2]
-I
TT EL
KO
M
Menggunakan register untuk menyimpan data yang akan dimanipulasi Pada mode ini tidak operasi pada memori Operasi relatif cepat Contoh: MOV BX, DX ;copy isi DX ke BX MOV ES, AX ;copy isi AX ke ES ADD AL, BH ;jumlahkan isi BH dan AL, hasilnya di AL Register sumber dan tujuan mempunyai ukuran yang sama
N
Mode Pengalamatan-Imm[3]
JU
Operand (source) adalah konstanta, yang terletak setelah opcode Operasinya sangat cepat Immediate addressing mode dapat digunakan pada semua register, kecuali register segmen dan flag (?) Contoh: MOV AX,2550H ; bilangan 2550H dimasukkan ke AX MOV CX,625 ; bilangan 625d dimasukkan ke CX MOV BL, 40H ; bilangan 40H dimasukkan ke BL
2
Mode Pengalamatan-Direct[4] Operand dari instruksi ini merupakan alamat memori data yang akan diakses Alamat ini merupakan EA (Effective Address) Contoh: MOV DL, [2400] ;copy isi memori dengan alamat DS:2400H ke DL
-I
TT EL
KO
M
Ditandai dengan [ ]
JU
N
Mode Pengalamatan-Direct[5]
3
Mode Pengalamatan-Indirect[6]
-I
TT EL
KO
M
Alamat lokasi memori data yang akan diakses tersimpan dalam register Register yang digunakan pada mode ini : SI, DI, dan BX Ditandai Contoh: dengan [ ] MOV AL,[BX] PA (Physical Address) dan EA (Effective Address) ???
JU
N
Mode Pengalamatan-Indirect[7]
4
Mode Pengalamatan–Based.Re[8]
-I
TT EL
KO
M
Menggunakan register BX and BP, untuk mendapatkan EA (effective address), ditambah dengan displacement Segment yang digunakan untuk mendapatkan physical address (PA) adalah: DS untuk BX SS untuk BP Contoh : MOV CX,[BX]+10 Salinkan isi DS:BX+10 dan DS:BX+10+1 ke reg. CX (little endian convt.); PA = ?
N
Mode Pengalamatan–Index.Re[7]
JU
Sama seperti based relative addressing mode, register yang digunakan adalah DI dan SI Contoh: MOV DX, [SI]+5 ; MOV CL, [DI]+20 ;
5
Mode Pengalamatan–Base.Indx[8]
-I
TT EL
KO
M
Kombinasi based dan indexed addressing modes Menggunakan satu base reg. dan satu index reg. Contoh: MOV CL, [BX][DI] + 8 MOV CH, [BX][SI]+20 MOV AH,[BP][DI]+12 MOV AH,[BP][SI]+29
JU
N
Mode Pengalamatan–Base.Indx[9]
6
MOV
Clock
Acc mem
10
Mem acc
10
RR
2
Mem R
12 + EA
R mem
13 + EA
Immed R
4
Immed mem
10 + EA 2 8 + EA
Seg R R
2
9 + EA
-I
TT EL
Seg R mem
KO
R seg R Mem seg R
M
Jenis Instruksi.CLK - MOV [1]
N
Jenis Instruksi. CLK-Aritmatika[2] Clock
DIV
Clock
RR
3
8 bit reg
80 sd 90
Mem R
9 + EA
16 bit reg
144 sd 162
R mem
16 + EA
8 bit mem
(86 sd 96)+EA
Immed R
4
16 bit mem
(150 sd 168)+EA
Immed mem
17 + EA
JU
ADD/SUB
MUL
Clock
Shift & Rotate
Clock
8 bit reg
70 sd 77
Single bit reg
2
16 bit reg
118 sd 133
Var bit reg
8 + 4/bit
8 bit mem
(76 sd 83)+EA
Single bit mem
15 + EA
16 bit mem
(124 sd 139)+EA
Var bit mem
20+EA+4/bit
7
Jenis Instruksi.CLK-Kend.Prog[3] Clock
Clock
short
15
JCXZ
6 (no branch) 18 (branch)
Intrasegment direct
15
J condition
4 (no branch) 16 (branch)
Intersegment direct
15
Intrasegment using reg mode
11
Intrasegment indirect
18 + EA
Intersegment indirect
24 + EA
-I
TT EL
KO
M
JMP
Jenis Instruksi.CLK- lainnya [4]
N
Instruksi
Instruksi
Clock
3
MOV seg,reg
2
INC/DEC data
23+EA
MOV reg,reg
2
INC/DEC reg16
3
MOV mem,reg
13+EA
LOGIC reg,reg
3
MOV reg,mem
12+EA
LOGIC mem,reg
24+EA
MOV mem,imm
14+EA
LOGIC reg,mem
13+EA
MOV reg,imm
4
LOGIC reg,imm
4
MOV mem,acc
14
LOGIC mem,imm
23/25+E A
MOV acc,mem
14
LOGIC acc,imm
4
MOV seg,mem
12+EA
MOV reg,seg
2
MOV mem,seg
13+EA
JU
INC/DEC reg8
Clock
8
Jenis Instruksi.CLK-Eff.Addr[5] Addressing Mode
Clock
Direct
6
Register indirect
5
Register relative
9
Based indexed 7
(BP)+(SI) or (BX)+(DI)
8
M
(BP)+(DI) or (BX)+(SI)
KO
Based indexed relative
11
(BP)+(SI)+disp or (BX)+(DI)+disp
12
TT EL
(BP)+(DI)+disp or (BX)+(SI)+disp
-I
Catatan: EA = Effective address
N
Jenis Instruksi.CLK-contoh [6] Mnemonic
JU
Address
Assembly
Clock
CS:0100
B8 34 12
MOV AX,1234
4
CS:0103
35 34 12
XOR AX,1234
4
CS:0106
74 02
JZ 010A
CS:0108
B3 12
MOV BL,12
CS:010A
8A 0E 34 12
MOV CL,[1234]
12 + 6(EA)
CS:010E
88 16 34 12
MOV [1234],DL
13+ 6(EA)
16 (branch)
- (skiped)
Total
61
9
Format bhs mesin 8088[1] Terdiri dari op-code 8 bit + operand (data,register,dll)
M
MOV AX,BX 89 (opcode) D8 (operand)
-I
TT EL
mnemonic
KO
bahasa mesin
N
Format bhs mesin 8088[2]
JU
Sesungguhnya bhs mesin diciptakan untuk kemudahan programmer (manusia) Control Unit di CPU hanya mengerti pola bit perintah MOV AX,BX 8B C3 (versi EMU 8086/ MASM), 89 D8 (versi debug) MOV AL,[2400] A0 00 24 ADD AX,BX 01 D8
10
Format bhs mesin 8088-MOV[3]
byte 1 1 0 0 0 1 0 op code D W mod
byte 2 reg
byte 3 R/M
byte 4
low displacement
high displacement or
direct address low byte
direct address high byte
-I
TT EL
KO
M
(5 bit) mode pengalamatan Pemilihan register Data byte/word ; 0=byte, 1=word Arah transfer data, dari/ke register ; 0=dari, 1=ke kode operasi (operation code)
N
Format bhs mesin 8088[4]
JU
Pola Register
Register W=0 W=1 AL AX BL BX CL CX DL DX AH SP BH DI CH BP DH SI
code 000 011 001 010 100 111 101 110
Seg. Reg. CS DS ES SS
code 01 11 00 10
11
Format bhs mesin 8088[5] Pola MOD dan R/M
111
01
10
[BX] + [SI] [BX] + [DI] [BP] + [SI] [BP] + [DI] [SI] [DI] d16 direct address [BX]
[BX] + [SI] + d8 [BX] + [DI] + d8 [BP] + [SI] + d8 [BP] + [DI] + d8 [SI] + d8 [DI] + d8
[BX] + [SI] + d16 [BX] + [DI] + d16 [BP] + [SI] + d16 [BP] + [DI] + d16 [SI] + d16 [DI] + d16
W=0 AL CL DL BL AH CH
[BP] + d8
[BP] + d16
DH
SI
[BX] + d8
[BX] + d16
BH
DI
MEMORY MODE
M
110
11
00
W=1 AX CX DX BX SP BP
REGISTER MODE
KO
MOD R/M 000 001 010 011 100 101
-I
TT EL
d8 : 8 - bit displacement, d16 : 16 - bit displacement
JU
N
Format bhs mesin 8088-contoh[6]
Contoh: coding MOV AL,BL
12
Format bhs mesin 8088[7]
-I
TT EL
KO
M
Contoh u/ berbagai Ad. Mode mov SP,BX; register A. M. mov CX,[4372H]; direct A.M. mov CL,[BX]; register indirect A.M. mov [SI + 43H],DH; indexed relative A.M. mov AL,9CH; immediate A.M. (?) mov CS:[BX],DL; segment ovverides (?)
Format bhs mesin 8088[8] M.
N
mov SP,BX; register A.
JU
mov CX,[4372H]; direct
BIU C-BUS
A.M. mov CL,[BX]; register indirect A.M. mov [SI + 43H],DH; indexed relative A.M. mov AL,9CH; immediate A.M. (?)
ES CS SS DS IP EU
mov CS:[BX],DL;
segment ovverides (?)
4 3 2 1
INSTRUCTION STREAM BYTE QUEUE
CONTROL SYSTEM A- BUS
AH BH CH DH
SP BP SI DI
AL BL CL DL
ALU OPERAND FLAGS
13
Format bhs mesin 8088[9] Kode Operasi Immediate A.M. dan Segment Override
byte 1 1 0 1 1 w
byte 2 data - low byte
reg
byte 3 data - high byte (w=1)
Immediate Addressing Mode
byte 2
M
byte 1 1 0 0 0 1 0 op code D W mod
reg
R/M
-I
TT EL
KO
0 0 1 reg 1 1 0 Segment ovveride prefix
N
Format bhs mesin 8088[10]
JU
Op. Code Acc. ke/dari memori byte 1 1 0 1 0 0 0 d w
byte 2 Low byte address
byte 3 High byte address
14
-I
TT EL
KO
M
Format bhs mesin 8088-Lat[11]
N
Segment overides[1]
JU
CPU 80x86 memungkinkan program untuk mengganti register segmen yang seharusnya dengan register segmen yang lain. Contoh : MOV AL,[BX] ; penunjuk alamat fisik adalah DS:BX Bandingkan dengan : MOV AL,ES:[BX]
15
Segment overides[2] Offset Register untuk berbagai Segment CS
DS
ES
SS
Offset Register
IP
SI, DI, BX
SI, DI, BX
SP,BP
-I
TT EL
KO
M
Segment Register
N
Segment overides-contoh[3] Segmen yg digunakan
Segmen seharusnya
MOV AX,CS:[BP]
CS:BP
SS:BP
MOV DX,SS:[SI]
SS:SI
DS:SI
MOV AX,DS:[BP]
DS:BP
SS:BP
MOV CS,ES:[BX]+12
ES:BX+12
DS:BX+12
JU
Instruksi
MOV SS:[BX][DI]+32,AX SS:BX+DI+32
DS:BX+DI+32
16
Latihan Soal [1] If DS=7FA2H and the offset is 438EH, determine: a) The physical address b) The lower range of the data segment c) The upper range of the data segment d) Show the logical address
-I
TT EL
KO
M
a) The Physical address is; 7FA20+438E= 83DAE b) The lower range: 7FA20(7FA20+0000) c) The upper range: 8FA1F(7FA20+FFFF) d) The logical address is; 7FA2:438E
N
Latihan Soal [2]
JU
Ex: SP=1236, AX=24B6, DI=85C2, and DX=5F93, show the contents of the stack as each nstruction is executed.PUSH AX, PUSH DI, PUSH DX SP? SS:SP??
17
Latihan Soal [3]
-I
TT EL
KO
M
Ex: assume that the stack is shown below, and SP=18FA, show the contents of the stack and registers as each of the following instructions is executed.POP CX,POP DX,POP BX SP? SS:SP??
N
Latihan Soal [4]
JU
Ex: Show how the flag register is affected by the addition of 38H and 2FH. CF,PF,AF,ZF,SF? MOV BH,38H ; ADD BH,2FH ; CF = 0 since there is no carry beyond d7 PF = 0 since there is odd number of 1`s in the result AF = 1 since there is a carry from d3 to d4 ZF = 0 since the result is not zero SF = 0 since d7 of the result is zero
18
Latihan Soal [5] MOV AX,34F5H SUB AX,95EBH CF,PF,AF,ZF,SF?
JU
N
-I
TT EL
KO
M
CF = 1 since there is carry beyond d15 PF = 0 since there is odd number of 1s in the lower byte AF = 1 since there is a carry from d3 to d4 ZF = 0 since the result is not zero SF = 1 since d15 of the result is 1
Thank You! Please study this subject at home
LOGO
19