Title: CMP Compare instruction
1CMP (Compare instruction)
CMP dest, src dest - src (result is not
saved) used to set flags for Jxx
instructions
CMP performs a subtract operation without using
the carry bit. The result is not stored
anywhere, but flags are set. Because the result
is not stored, a single target register can be
repeatedly reused to check contents of src.
Mov al, a stores the ASCII code for
a Mov SI, 0 the index L1 CMP al,
Data1 SI look at Data1 elements until a
is found JE Foundit Foundit is a label
of more instructions Inc SI point to
the next data JMP L1 and check it
2Logical OperationsAND, OR, XOR, NOT
The logical operations are performed on a
bit-by-bit basis AND dest, src dest ? dest
src OR dest, src dest ? dest src NOT dest
XOR dest, src destination and source cannot
both be in memory
AX0ff0h BX0abcdh AND AX, BX AX ? 0bc0h AND
BL, AL BL ? 0c0h
3TEST (Compare instruction)
TEST dest, src dest ? src (result is not
saved) used to set flags and check the
status of a single bit
TEST performs an AND operation. The result is
not stored anywhere, but flags are set. TEST is
used to check the status of a single bit in a
byte or word without destroying the rest of the
contents.
Mov al, 1 a mask checking for bit 0
(data0) Test data, al 0 if data0 0,
?0 if data0 ?0 JNZ Bit1Set if bit 1
set, go to Bit1Set (a label) Test data,
80h check bit 7 (data7) JNZ Bit7Set
only possible because data is not
overwritten
4Shift Instructions
Shift mnemonic dest, count dest ? Shift
operation(dest, 1) repeated count times
count is 1 or CL bits shifted out are copied
to the Carry flag
SHL and SAL perform an 8-bit or 16-bit left-shift
with zero fill. SHR performs an 8-bit or 16-bit
right-shift with zero fill. SAR performs an
8-bit or 16-bit right-shift with sign extension
5Rotate Instructions
Rotate mnemonic dest, count dest ?
Rotate operation(dest, 1) repeated count times
count is 1 or CL
ROL performs an 8-bit or 16-bit left-rotate. The
bit rotated out (MSBdest) is rotated to dest0
and copied to the Carry flag ROR performs an
8-bit or 16-bit right-rotate. The bit rotated
out (dest0) is rotated to MSBdest and copied
to the Carry flag RCL performs an 9-bit or
17-bit left-rotate. The bit rotated out
(MSBdest) is rotated into the Carry flag and
the Carry flag is rotated into dest0 RCL
performs an 9-bit or 17-bit right-rotate. The bit
rotated out (dest0) is rotated into the Carry
flag and the Carry flag is rotated into MSBdest
6(No Transcript)
7CBW, CWD
CBW AH ? AL(7) CWD DX ? AX(15)
CBW (Convert Byte to Word) and CWD (Convert Word
to Double-Word) are used prior to the IDIV
operation. If a byte-division is to be
performed, the dividend must be 16-bits--CBW
creates the 16-bit dividend while preserving the
sign. Similarly, CWD initializes DX so that
DXAX creates a 32-bit dividend with the sign
preserved.
8NEG
NEG src src ? -src src ? 2s src
NEG replaces the operand with its negative.
Restated, NEG replaces the operand with its twos
complement.