Lecture 14 19th Feb 2024
Lecture 14 19th Feb 2024
Topic-IV
T1. Barry B Brey, The Intel Microprocessors. Pearson, Eight Ed. 2009. Chapter 4-6, 8
19-02-2024
1
2/26/2024
Rotate
• Positions binary data by rotating information in a register or
memory location, either from one end to another or through the
carry flag.
– used to shift/position numbers wider than 16 bits
• Addressing modes used with rotate are the same as those used
with shifts.
Rotate
• ROL Destination, count
• ROR Destination, count
• ROL AX,1
• ROR BYTEPTR [SI], 1
• MOV CL, 04H
• ROL AX, CL
• ROL BYTEPTR [SI], CL
• ROL ECX, 12H 80386
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
2
2/26/2024
Rotate
Flags Affected : CF
OF –If MSB changes –single bit rotate
Rotate
3
2/26/2024
RCL
RCR
4
2/26/2024
5
2/26/2024
2/26/2024 96
6
2/26/2024
.Model Tiny
.data
DATA1 DB 0A7H
RES1 DB ?
.code
.startup
SUB BL, BL ;clear BL
MOV DL, 8 ;rotate total of 8 times
MOV AL,DATA1
AGAIN: ROL AL,1 ;rotate it once
JNC NEXT ;check for 1
INC BL ;if CF=1 then inc count
NEXT: DEC DL ;go through this 8 times
JNZ AGAIN ;if not finished go back
MOV RES1, BL
.exit
end
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
7
2/26/2024
STRING COMPARISONS
SCAS
Compares the AL with a byte of data in memory
Compares the AX with a word of data in memory
Compares the EAX with a doubleword of data in memory
Memory is ES: DI
Operands not affected flags affected(subtraction)
SCASB
SCASW
SCASD
8
2/26/2024
. MODEL TINY
.DATA
DAT1 DB 80 DUP (?)
.CODE
.STARTUP
MOV DI, OFFSET TEST STRING
MOV AL, 0DH
MOV CX, 50H • Scanning is repeated as
CLD long as bytes are not
REPNE SCASB equal or the end of the
.EXIT string not reached.
END
• If 0DH is found DI will
point to the next address
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
9
2/26/2024
• Flags affected
• Direction flag used for auto increment or decrement
• Can be used with Prefix
Ex:
MOV SI, OFFSET STRING FIRST
MOV DI, OFFSET STRING SECOND
CLD
MOV CX, 100
REPE CMPSB
• REPE CMPSB
• REPNE CMPSB
10
2/26/2024
End of Lecture 14
2/26/2024 106
11