0% found this document useful (0 votes)
10 views11 pages

Lecture 14 19th Feb 2024

Uploaded by

Anmol Murti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Lecture 14 19th Feb 2024

Uploaded by

Anmol Murti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

2/26/2024

Topic-IV

80x86 Instruction Sets and ALP

T1. Barry B Brey, The Intel Microprocessors. Pearson, Eight Ed. 2009. Chapter 4-6, 8

19-02-2024

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

 Ex: CF=0 , BX= 11100101 11010011


SHR BX,1 ;Shift BX register contents 1 bit position right,
keeping MSB same
; CF=1 , BX=01110010 11101001

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

• With either type of instruction, the programmer can select either a


left or a right rotate.

• Addressing modes used with rotate are the same as those used
with shifts.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

Rotate
• ROL Destination, count
• ROR Destination, count

• Use CL for count greater than 1.


• (In 80386 onwards count greater than 1 can be directly given)

• 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

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

Rotate

ASSUME BX=1111 0000 1001 1100, Swap the bytes of the


BX register

MOV CL, 08H


ROL BX, CL

MOV CL, 08H


ROR BX, CL

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

3
2/26/2024

Rotate through Carry

RCL

RCR

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

The rotate instructions showing the direction and operation of each


rotate.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

4
2/26/2024

 Ex: CF=0 , BX= 11100101 11010011


RCL BX,1 ;rotate BX register contents 1 bit position left
; CF=1 , BX= 11001011 10100110

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

 Ex: CF=0 , BX= 11100101 11010011


RCR BX,1 ;rotate BX register contents 1 bit position right
; CF=1 , BX=01110010 11101001

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

5
2/26/2024

2/26/2024 96

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

 Ex: CF=0 , BX= 11100101 11010011


ROL BX,1 ;rotate BX register contents 1 bit position left
; CF=1 , BX= 11001011 10100111

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

6
2/26/2024

 Ex: CF=0 , BX= 11100101 11010011


ROR BX,1 ;rotate BX register contents 1 bit position right
; CF=1 , BX= 11110010 11101001

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

WRITE A PROGRAM THAT COUNTS THE NUMBER OF 1’S IN A BYTE


IN LOCATION DATA1 AND WRITES IT INTO LOCATION RES1

.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

• String instructions are powerful because they allow the


programmer to manipulate large blocks of data with relative ease.

• Block data manipulation occurs with MOVS, LODS, STOS, INS,


and OUTS.

• Additional string instructions allow a section of memory to be


tested against a constant or against another section of memory.

– SCAS (string scan); CMPS (string compare)

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

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

Can be used with prefix


REPNE SCASB

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

8
2/26/2024

• SCAS uses direction flag (D) to select auto- increment or auto-


decrement operation for DI.

also repeat if prefixed by conditional repeat prefix

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

Write an ALP to find the displacement at which the data


0DH is present from an array of data stored from location
DAT 1. The number of bytes of data in the array is 80.

. 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

CMPS / CMPSB/ CMPSW

• Compares a byte in one string with a byte in another string or a


word in one string with a word in another string

DS: SI with ES: DI

• Flags affected
• Direction flag used for auto increment or decrement
• Can be used with Prefix

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

Ex:
MOV SI, OFFSET STRING FIRST
MOV DI, OFFSET STRING SECOND
CLD
MOV CX, 100
REPE CMPSB

• Repeat until end of string or until compared bytes are equal

• REPE CMPSB
• REPNE CMPSB

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

10
2/26/2024

End of Lecture 14

2/26/2024 106

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

11

You might also like