operasi logika

21
LOGICAL OPERATION

Upload: riska-kafahris-fahmi-zain

Post on 22-Sep-2014

173 views

Category:

Documents


21 download

TRANSCRIPT

LOGICAL OPERATION

Operasi logika (logical operation)meliputi perbandingan dua buah elemen logika dengan menggunakan operator logika, yaitu: sama dengan (=) tidak sama dengan () kurang dari (=)

a. b.

c.d. e.

f.

Logical Instruction1. 2. 3. 4. 5. 6. 7. 8. 9.

AND And OR Or XOR Exclusive or NOT Not SAR Shift arithmetic right SHR Shift logical right SAL/SHL Shift arithmetic left/Shift logical left SHRD Shift right double SHLD Shift left double

10. ROR Rotate right 11. ROL Rotate left 12. RCR Rotate through carry right 13. RCL Rotate through carry left

AND

Operasi AND membandingkan 2 bit dan jika keduanya nilainya 1 maka hasilnya adalah 1 selain itu hasilnya adalah 0

0 0 1 0 0

1 0 1

OR

Operasi OR membandingkan 2 buah bit apabila salah satu atau kedua bit adalah 1 maka hasinya adalah 1 selain itu adalah 000 1 0 1

11 1

XOR

Operasi XOR (Exclusive OR) membandingkan 2 buah bit dan jika kedua bit tersebut bernilai sama maka hasilnya adalah 0 dan jika nilainya berbeda hasilnya adalah 10 1

0 1

0 1

1 0

NOT

Operasi NOT mengubah nilai dari suatu bit. Jika bit tersebut bernilai 1 maka hasilnya adalah 0 dan jika bit tersebut bernilai 0 hasilnya adalah 1.0 1

1

0

Contoh Operasi-Untuk operasi NOT Contoh : NOT 0111 = 1000 -untuk operasi OR Contoh : 0101 OR 0011 = 0111 -Untuk operasi XOR Contoh : 0101 XOR 0011=0110 -Untuk operasi AND Contoh : 0101 AND 0011 = 0001

Format intruksi NOT NOT

r/m8 Reverse each bit of r/m8 NOT r/m16 Reverse each bit of r/m16 NOT r/m32 Reverse each bit of r/m32

Format instruksi AND,OR,XORACC [ACC] IMM

REG/MEM [REG/MEM] IMMAND r/m8,imm8 AND r/m16,imm16 AND r/m32,imm32 AND r/m16,imm8 AND r/m32,imm8 AND r/m8,r8 AND r/m16,r16 AND r/m32,r32

AND AL,imm8 AND AX,imm16 AND EAX,imm32

AL AND imm8 AX AND imm16 EAX AND imm32 r/m8 AND imm8 r/m16 AND imm16 r/m32 AND imm32 r/m16 AND imm8 (sign-extended) r/m32 AND imm8 (sign-extended) r/m8 AND r8 r/m16 AND r16 r/m32 AND r32 r8 AND r/m8 r16 AND r/m16 r32 AND r/m32

REG/MEM [REG/MEM] [REG]

REG [REG] [REG/MEM]AND r8,r/m8 AND r16,r/m16 AND r32,r/m32

Shift Instructions

Shift Left SAL (shift arithmetic left)

SAL SRC SAL SRC,COUNT SHL (shift logical left)

SHL SRC SHL SRC,COUNT SHLD (shift left double)

SHLD SRC,REG,COUNT

Shift Right SAR (shift arithmetic right) lihat SAL

SHR (shift logical right) lihat SHL

SHRD (shift right double) lihat SHLD

SAL & SHL

shift the source operand left by from 1 to 31 bit positions empty bit positions are cleared CF flag is loaded with the last bit shifted out of the operand

SH R shifts the source operand right by from 1 to 31 bit

positions empty bit positions are cleared CF flag is loaded with the last bit shifted out of the operand

SA Rshifts the source operand right by from 1 to 31 bit positionspreserves the sign of the source operand by clearing empty bit positions if the operand is positive, or setting the empty bits if the operand is negative

CF flag is loaded with the last bit shifted out of the operand

Format Instruksi SAL (SAR, SHL, SHR)1-OPERAND SAL r/m8 SAL r/m16

SAL r/m32

Multiply r/m8 by 2, 1 time Multiply r/m16 by 2, 1 time Multiply r/m32 by 2, 1 time Multiply r/m8 by 2, CL times Multiply r/m16 by 2, CL times Multiply r/m32 by 2, CL times Multiply r/m8 by 2, imm8 times Multiply r/m16 by 2, imm8 times Multiply r/m32 by 2, imm8 times

2-OPERAND w/ CL SAL r/m8,CL SAL r/m16,CL SAL r/m32,CL

2-OPERAND w/ IMM SAL r/m8,imm8 SAL r/m16,imm8 SAL r/m32,imm8

SHLD & SHRD

shift a specified number of bits from one operand to another provided to facilitate operations on unaligned bit strings or to implement a variety of bit string move operations

Format Instruksi SHLD (SHRD)

SHLD r/m16, r16, imm8 SHLD r/m16, r16, CL SHLD r/m32, r32, imm8 SHLD r/m32, r32, CL

Shift r/m16 to left imm8 places while shifting bits from r16 in from the right Shift r/m16 to left CL places while shifting bits from r16 in from the right Shift r/m32 to left imm8 places while shifting bits from r32 in from the right Shift r/m32 to left CL places while shifting bits from r32 in from the right

Rotate Instructions

Rotate Left ROL (rotate left) RCL (rotate through carry left)

Rotate Right ROR (rotate right) RCR (rotate through carry right)

Format R-OP SRC,COUNT

ROL & ROR

ROL instruction rotates the bits in the operand to the left (toward more significant bit locations) ROR instruction rotates the operand right (toward less significant bit locations) CF flag always contains the value of the last bit rotated out of the operand

RCL & RCR

RCL instruction rotates the bits in the operand to the left, through the CF flag) RCR instruction rotates the bits in the operand to the right through the CF flag CF flag always contains the value of the last bit rotated out of the operand

Format Instruksi RCL (RCR, ROL, ROR)

RCL r/m8, 1 RCL r/m8, CL RCL r/m8, imm8 RCL r/m16, 1 RCL r/m16, CL RCL r/m16, imm8 RCL r/m32, 1 RCL r/m32, CL RCL r/m32,i mm8

Rotate 9 bits (CF, r/m8) left once Rotate 9 bits (CF, r/m8) left CL times Rotate 9 bits (CF, r/m8) left imm8 times Rotate 17 bits (CF, r/m16) left once Rotate 17 bits (CF, r/m16) left CL times Rotate 17 bits (CF, r/m16) left imm8 times Rotate 33 bits (CF, r/m32) left once Rotate 33 bits (CF, r/m32) left CL times Rotate 33 bits (CF, r/m32) left imm8 times