Instruction Set
4-226
SHR
SHR
Flag Settings After Instruction
If
count=0, flags are unaffected. Otherwise, flags are affected as shown below:
Examples
This example divides an 8-bit unsigned number in memory by 2.
This example counts the number of bits in a word that are set to 1. LOOP implements
a construct equivalent to the C-language
do-while loop. AND and JZ implement an
if statement within the loop.
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
POWER2
EQU
1
; divide by 2
UNUMBER
DB
253
; FDh
; unsigned division by 2: UNUMBER = UNUMBER / pow(2,POWER2)
SHR
UNUMBER,POWER2
; UNUMBER = 7Dh = 125
; remainder is lost
INDICATORS
DW
10110111b
; B7h
; count number of set bits in word
; set up registers
MOV
DX,INDICATORS
; DX = B7h
MOV
CX,8 * (SIZE INDICATORS)
; set up counter
MOV
BX,0
; initialize # of set bits
TEST_BIT:
MOV
AX,DX
; load copy of indicators into AX
AND
AX,1h
; is low bit set?
JZ
NEXT_BIT
; if not, then jump
INC
BX
; if so, add 1 to total
NEXT_BIT:
SHR
DX,1
; shift next bit into low bit
LOOP
TEST_BIT
; decrement CX
; if CX is not 0, jump to top of loop
Содержание Am186 Series
Страница 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Страница 10: ...Table of Contents x...
Страница 18: ...Programming 1 8...
Страница 40: ...Instruction Set Listing 3 14...