
Instruction Set
4-215
S AR
S AR
Flag Settings After Instruc tion
If count=0, flags are unaffected. Otherwise, flags are affected as shown below:
Examples
This example divides an 8-bit integer in memory by 2.
This example divides a 16-bit integer in DX by 4.
T ips
If the integer
dividend will fit in a 16-bit register and you don’t need the remainder, use SAR
to divide integers by powers of 2. When dividing an integer by a power of 2, it is faster to
use SAR than IDIV.
Related Instruc tions
If you want to
Divide an unsigned number by another unsigned number
Divide an integer by another integer
Rotate the bits of a component and the value of CF to the left
Rotate the bits of a component and the value of CF to the right
Rotate the bits of a component to the left
Rotate the bits of a component to the right
Multiply an integer by a power of 2
Divide an unsigned number by a power of 2
See
DIV
IDIV
RCL
RCR
ROL
ROR
SAL/SHL
SHR
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Processor Status
Flags Register
reserved
OF DF
IF TF SF ZF
–
–
AF
PF
CF
= undefined; – = unchanged
Undefined unless single-bit shift, then:
OF=1 if result larger than destination operand
OF=0 otherwise
–
res res
res 0
SF=1 if result is 0 or positive
SF=0 if result is negative
ZF=1 if result equal to 0
ZF=0 if result not equal to 0
PF=1 if low byte of result has even number of set bits
PF=0 otherwise
CF=0 unless shift lengths are less than or
equal to the size of the shifted operand,
then:
CF=1 for carry or borrow to high-order bit
CF=0 otherwise
INTEGER
DB
-45
; D3h
; signed division by 2: INTEGER = INTEGER / 2
SAR
INTEGER,1
; INTEGER = EAh = -22
; remainder in CF
POWER2
INTEGER
EQU
DW
2
-21
; divide by 4
; FFEBh
; signed division by 4: DX = DX / pow(2,POWER2)
MOV
DX,INTEGER
SAR
DX,POWER2
; DX = FFEBh = -21
; DX = FFFBh = -5
; remainder is lost