04 Arithmetic
Download
Report
Transcript 04 Arithmetic
QUIZ
Berapakah nilai hexadecimal dari destination operand pada setiap
instruksi ? (Jika terdapat instruksi yang ERROR atau ILLEGAL,
tuliskan ERROR atau ILLEGAL sebagai jawaban !)
Instruction
Before
After
Mov ax,bx
AX=0022 BX=00A6
AX=00A6
Mov ah,3
AX=06AF
AX=03AF
Mov bl,ax
BX=00A5 AX=4000
BL=ERR
Mov di,100
DI=06E9
DI=0100
Mov ds,cx
DS=0FB2 CX=0020
DS=ERR
Mov ah,bl
AX=0023 BX=00A5
AX=A523
Add ah,3
AX=06AF
AX=09AF
Inc bl
BX=FFFF
BX=FF00
Add di,100
DI=06E9
DI=07E9
Dec cx
CX=0000
CX=FFFF
Berapakah nilai hexadecimal dari destination operand pada setiap
instruksi ? (Jika terdapat instruksi yang ERROR atau ILLEGAL,
tuliskan ERROR atau ILLEGAL sebagai jawaban !)
Instruction
Before
After
Mov ax,bx
AX=0022 BX=00A6
AX=
Mov ah,3
AX=06AF
AX=
Mov bl,ax
BX=00A5 AX=4000
BL=
Mov di,100
DI=06E9
DI=
Mov ds,cx
DS=0FB2 CX=0020
DS=
Mov ah,bl
AX=0023 BX=00A5
AX=
Add ah,3
AX=06AF
AX=
Inc bl
BX=FFFF
BX=
Add di,100
DI=06E9
DI=
Dec cx
CX=0000
CX=
Departemen Ilmu Komputer FMIPA IPB 2006
Perkalian dan Pembagian
Integer MUL dan DIV
Semua operand diasumsikan biner
MUL dan DIV digunakan untuk unsigned binary
integers, IMUL (integer MUL) dan IDIV (integer DIV)
digunakan untuk signed binary integers
MUL
(Perkalian)
MUL source
Merupakan operasi perkalian 8-bit atau 16-bit operand
dengan AL atau AX
Souce operand bisa berupa register atau memory operand,
tetapi tidak boleh immediate data
MUL reg16 → reg16 * AX
MUL reg8 → reg8 * AL
Hasil:
Reg16
High byte (bit 16-31) → DX
Low byte (bit 0-15) → AX
Reg8: AX
Contoh
MUL
Multiply AL dengan 10h
mov al,5
mov bl,10
mul bl
; AX = 0050h
Multiply AX dengan 10h
mov ax,2000
mov bx,0010
mul bx
DIV
(Pembagian)
DIV source
Merupakan operasi pembagian 8-bit atau 16-bit operand dengan AL
atau AX
DIV reg16 → DX:AX / reg16
DIV reg8 → AX / reg8
Output:
Reg16
Hasil bagi → AX
Sisa → DX
Reg8
Hasil bagi → AL
Sisa → AH
Keterangan: hasil bagi tidak boleh melebihi register
Contoh
DIV
DIV dengan reg 8-bit
mov ax,0083
mov bl,2
div bl
DIV dengan reg 16-bit
mov dx,0
mov ax,8003
mov cx,100
div cx
Instruksi Boolean
AND op1, op2
→ op1 = op1 AND op2
AND Destination, Source
OR op1, op2
→ op1 = op1 OR op2
OR Destination, Source
XOR op1, op2
→ op1 = op1 XOR op2
XOR Destination, Source
NOT op1
→ op1 = NOT op1
NOT Destination
NEG op1
NEG Destination
→ op1 = -op1
op1 dan op2 pada AND, OR, dan XOR harus berukuran sama, dan
hanya boleh salah satu op yang merupakan memory operand.
AND
-a 100
1373:0100 mov al,01
1373:0102 and al,00
1373:0104
R
T
T
OR
-a 100
1373:0100 mov al,01
1373:0102 or al,FE
1373:0104
R
T
T
XOR
-a 100
1373:0100 mov al,B4
1373:0102 xor al,86
1373:0104
R
T
T
NOT
-a 100
1373:0100 mov al,23
1373:0102 not al
1373:0104
R
T
T
NOT
-a 100
1373:0100 mov al,23
1373:0102 not ax
1373:0104
R
T
T
NEG
-a 100
1373:0100 mov al,12
1373:0102 neg al atau
1373:0104
R
T
T
neg ax
Perbandingan
CMP Instruction
CMP destination, source
membandingkan dua buah operand 8-bit atau
16-bit (sama seperti operasi pengurangan)
Hasil dapat diamati pada FLAG Reg
After CMP
Destination < Source
Destination = Source
Destination > Source
Flag Result
CF = 1
ZF = 1
CF = 0, ZF = 0
CMP 1
-a100
1373:0100 mov al,5
1373:0102 cmp al,10
R
T
T
CMP 2
-a100
1373:0100 mov ax,ABCD
1373:0102 cmp ax,abcd
R
T
T
CMP 3
-a100
1373:0100 mov si,105
1373:0102 cmp si,0
R
T
T
Latihan
Setelah instruksi di bawah ini dieksekusi, berapakah nilai CX, DX dan SI?
-a150
1373:0150 dw 026a,3fd9
-a100
1373:0100 mov si,0
1373:0103 mov cx,[150]
1373:0107 mov dx,[152]
1373:010B and cx,00ff
1373:010F not dx
1373:0111 xchg dx,[150]
1373:0115 inc si
1373:0116 dec dx
1373:0117 loop 115
1373:0119