Instruction Set
Instruction Set
- Data Transfer
Instructions.
- Arithmetic Instructions.
- Logical instructions.
Shift instructons
Not Allowed instructions
• MOV X,Y
• MOV X,[BX]
• MOV Y, ARRAY[SI]
• MOV Y,[200]
• MOV AX,@DATA
• MOV DS,AX
• MOV BX,DS
• MOV CS,BX
MOV BX, OFFSET VALW
• MOV AL,3
• MOV BL,5
• MUL bl
• A= 41H 0100 0001
• 00100000 or
27
Shift Instructions
29
Shift Right
SHR: 0 C
SAR: S C
30
SHR
Instruction Binary Decimal CF
MOV AL,10110011B 1011 0011 179 -
SHR AL,01 0101 1001 89 1
MOV CL,02
SHR AL,CL 0001 0110 22 0
(80286+)
SHR AL,02
31
SAR
Instruction Binary Decimal CF
MOV AL,10110011B 1011 0011 -77 -
SAR AL,01 1101 1001 -39 1
MOV CL,02
SAR AL,CL 1111 0110 -10 0
(80286+)
SAR AL,02
32
SHR and SAR
• Right shifts are especially useful for halving values: i.e. integer
division by 2
• Right shift by 2 bits => divide by 4
• Right shift by 3 bits => divide by 8 etc.
• SHR: for unsigned numbers
• SAR: for Signed numbers
• Much faster than the divide instruction.
• Shifting by 1 bit, the remainder is in CF.
33
Shift Left
C 0
SHL & SLA:
34
• X = 00001000
• Shl x,1 ; 00010000 16
• Mov y,-1
• Sal y,1
• y= 11111111
• 11111110 * 2
• 11111100
SHL
Instruction Binary Decimal CF
MOV AL,00001101B 0000 1101 13 -
SHL AL,01 0001 1010 26 0
MOV CL,02
SHL AL,CL 0110 1000 104 0
(80286+)
SHL AL,02 1010 0000 160 1
36
SAL
Instruction Binary Decimal CF
MOV AL,11110110B 1111 0110 -10 -
SAL AL,01 1110 1100 -20 1
MOV CL,02
SAL AL,CL 1011 0000 -80 1
(80286+)
SAL AL,02 1100 0000 -64 0
37
• F = X * 20
F= X*16 + X*4
MOV AL,X
SHL AL,4
SHL X,2
ADD X,AL
SHL and SAL
• SHL and SAL are identical
• SHL for unsigned and SAL for signed
• can be used to double numbers.
• Each bit shift to the left , double the value
• shifting left by 2 bits = multiply by 4 etc.
• Note: if after a left shift CF=1
• size of the register/memory location is not large enough for the result.
39
Example
A code segment that will multiply AX by 10
Assume the number N is the content of AX
40
Rotate Instructions
• Rotate binary data in a memory location or a register either from one
end to the other, or through the CF.
• Used mostly to
• inspect specific bits
• shift numbers that are wider that register size (I.e. wider that 16 bits in
8086/286).
41
Rotate Instructions
• Rotate Right
• ROR
• RCR
• Rotate Left
• ROL
• RCL
42
Rotate Right
ROR: C
RCR: C
43
Rotate Left
C
ROL:
C
RCL:
44
Example
Instruction Binary CF
MOV BL,10110100B 1011 0100 -
ROR BL,01 0101 1010 0
MOV CL,02
ROR BL,CL 1001 0110 1
45
Example
• Rotate instructions are often used to shift wide numbers to the left or
right.
Example: Assume a 48-bit number is stored in registers DX, BX, AX
write a code segment to shift number to the left by one position:
SHL AX,1
RCL BX,1
RCL DX,1
46