Mupee 5
Mupee 5
AND, AX, BX
Causes the contents of BX to be ANDed with the content of AX. The result
is reflected by the new content of AX.
If [AX] 1234h
[BX] 000Fh
Solution:
a. [AL] 01010101B ( 55h )
b. 01010101b . 00011111b = 00010101b = 55 h , 1Fh = 15h [AL]
c. 00010101b + 11000000 = 11010101b = 15h + C0h = D5h [AL]
d. 11010101b Exor 00001111b = 11011010b = D5h exor 0Fh = DAh [AL]
e. [AL] = 11011010b’ = 00100101b = 25 h
C:>DEBUG
-A
1076:0100 MOV AL,55
1076:0102 AND AL,1F
1076:0104 OR AL,C0
1076:0106 XOR AL,OF
1076:0108 NOT AL
1076:010A
-T
AX=0055 ,,,,,,
-T
AX=0015 …….
-T
AX=00D5 …….
-T
AX=00DA …..
-T
AX=0025…..
SAL/SHL
Shift arithmetic left/shift logic left
SHL/SAL D, Count
Shift the [D] left by the number of bit
Positions equal to count and fill the vacated
Bit positions on the right with zeros
CF PF SF ZF OF
AF Undefined
OF Undefined if count == 1
SHR
Shift logical Right
SHR D, Count
Shift the [D] right by the number of bit
Positions equal to count and fill the vacated
Bit positions on the left with zeros
CF PF SF ZF OF
AF Undefined
OF Undefined if count === 1
SAR
Shift arithmetic Right
SAR D, Count
Shift the [D] right by the number of bit
Positions equal to count and fill the vacated
Bit positions on the left with the original
MSB
OF SF ZF PF CF
AF Undefined
Register 1
Register CL
Memory 1
Memory CL
In an arithmetic shift to the left SAL operation, the vacated bits at the
right of the operand are filled with zeros, whereas in an arithmetic shift to
the right, SAR operation, the vacated bits at the left are filled with the
value of the original MSB of the operand.
Thus, in an arithmetic shift to the right the original sign of the number is
extended.
Example:
SHL AX, 1
AX 0001001000110100 1234
0 001001000110100 0 0 2468
CF lsb
Bit 0
0001001000110100 1234
0 0000010010001101 0 048D
CF
SHR AX, CL
0000100100011010
0000001001000110 1
CF
C:> DEBUG
-A
1076:0100 SAR AX,CL
1076;0102
-R AX
AX 0000
:091A
-R CX
CX 0000
:2
-R F
NV UP EI PL NZ NA PO NC
-T
AX=0246 BX=0000 CX=0002 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=1076 ES=1076 SS=1076 CS=1076 IP=0102 NV UP EI PL NZ NA PO CY
1076:0102 241F AND AL,1F
-Q
ROL
Rotate left
ROL D, Count
Rotate the [D] left by the number of bit
Positions equal to count. Each bit shifted out
From the left most bit goes back into the
Rightmost bit positions
CF
OF undefined if count === 1
ROR
Rotate right
ROR D, Count
Rotate the [D] right by the number of bit
Positions equal to count. Each bit shifted out
From the right most bit goes into the left
Most bit position.
CF
OF Undefined if count === 1
RCL
Rotate left through carry
RCL D, Count
Same as ROL except carry is attached to
[D] for rotation
CF
OF Undefined if count === 1
RCR
Rotate right through carry
RCR D, Count
Same as ROR except carry is attached to
Destination count
Register 1
Register CL
Memory 1
Memory CL
Example:
What is the result in BX and CF after Execution of the following
instruction?
RCR BX, CL
Solution:
The original contents of BX are
[BX] = 0001001000110100b = 1234 h
Execution of the RCR instruction causes a 4 bit rotate right through carry
to take place on the data in BX. Therefore, the original content of bit 3,
which is zero, resides in carry; CF=0 and 1000b has been reloaded from bit
15. The resulting contents of BX are
Solution:
LAHF
MOV MEM1, AH
MOV AH, MEM2
SAHF
C:>DEBUG
-A 0:0110
0000:0110 LAHF
0000:0111 MOV [0150],AH
0000:0115 MOV AH, [0151]
0000:0119 SAHF
0000:011A
-E 0:0150 FF 01
-R CS
CS 1076
:0
-R IP
IP 0100
:0110
-R DS
DS 1076
:0
-R
…..
….
-T
-T
COMPARE INSTRUCTIONS
Destination Source
Register Register
Register Memory
Memory Register
Register Immediate
Memory Immediate
Accumulator Immediate
Example:
Describe what happens to the status flags as the sequence of instructions
that follows is executed.
MOV AX, 1234 h
MOV BX, 0ABCD h
CMP AX,BX
Assume that flags ZF SF CF AF OF AND PF are all initially reset.
Solution:
[Ax] – [Bx] = 0001001000110100b – 1010101111001101b
= 0110011001100111b
JUMP INSTRTUCTION
Operand
Short label
Near label
Far label
Memptr 16
Regptr 16
Memptr 32
Let BX be 0010h
C:>DEBUG
-A
1076:0100 JMP BX
1076:0102
-R BX
BX 0000
:10
-R
-T
-Q
C:> DEBUG
-A
1076:0100 JMP [BX]
1076:0102
-R BX
BX 0000
:1000
-E 1000 00 02
-D 1000 1001
1076:1000 0002
-R
………..IP = 0100
-T
…… IP = 0200
-Q
Mnemonic CALL
Meaning Subroutine call
Format CALL operand
Flags affected None
Operation Execution continue from the address of the subroutine
specified by the operand. Information required to return back to the main
program such as IP and CS are saved on the stack.
Here the physical address of the first byte of the 4-byte pointed in
memory is derived from the content of DS and DI
Mnemonic RET
Meaning Return
Format RET or RET operand
Flags affected None
Operation Return to the main program by restoring IP ( and CS for
far_proc). If operand is present, it is added to the contents of SP
Operand None
Disp 16
POP AX
[AL] [ [SP] ]
[AH] [ [SP] +1 ]
[SP] [ SP ] + 2
Operands ( S or D)
Register
Seg-reg ( CS illegal )
Memory
Example:
SUM PROC NEAR
PUSH DX
MOV DX, TOTAL
ADD DX, 31h
MOV TOTAL, DX
POP DX
RET
SUM ENDP
Example:
MOV AX, DATASEGADDR
MOV DS, AX
MOV SI, BLK1ADDR
MOV DI, BLK2ADDR
MOV CS, N
NXTPT: MOV AH, [SI]
MOV [DI], AH
INC SI
INC DI
LOOP NXTPT
HLT