[go: up one dir, main page]

0% found this document useful (0 votes)
171 views12 pages

String and String-Handling Instructions

The document discusses string and string handling instructions in computers. It explains that string instructions allow programmers to move blocks of data from one memory location to another. It then describes various string instructions like MOVSB, CMPSB, LODSB, and STOSB that can perform operations like moving, comparing, loading and storing strings. It also discusses the REP prefix that can be used to repeat string instructions. An example is provided to illustrate the use of these instructions to copy data from one memory block to another.
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)
171 views12 pages

String and String-Handling Instructions

The document discusses string and string handling instructions in computers. It explains that string instructions allow programmers to move blocks of data from one memory location to another. It then describes various string instructions like MOVSB, CMPSB, LODSB, and STOSB that can perform operations like moving, comparing, loading and storing strings. It also discusses the REP prefix that can be used to repeat string instructions. An example is provided to illustrate the use of these instructions to copy data from one memory block to another.
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/ 12

String and String-Handling Instructions

 String means a series of data words (or bytes) that reside


in consecutive memory locations
 String instructions permit a programmer to implement
operations such as to move data from one block of
memory to a block elsewhere in memory

43
String and String-Handling Instructions
 Autoindexing for string instruction – CLD and STD
instructions
◦ DF=1  Decrementing the address
◦ DF=0  Incrementing the address

44
String and String-Handling Instructions
 Move string – MOVSB, MOVSW
◦ Example – The block-move program using the move-string
instruction
* CLD clears direction flag

45
String and String-Handling Instructions
 Compare string and scan string – CMPSB/CMPSW,
SCASB/SCASW
◦ Example – Block scan operation using the SCASB instruction

46
String and String-Handling Instructions
 Load and store string –LODSB/LODSW, STOSB/STOSW
◦ Example – Initializing a block of memory with a store string
instruction

47
String and String-Handling Instructions
 REP string – REP (repeat prefixes)

48
String and String-Handling Instructions
 REP string – REP (repeat prefixes)
◦ Example – Initializing a block of memory by repeating the STOSB
instruction

49
String and String-Handling Instructions
 EXAMPLE: Describe what happen as the following
sequence of instruction is executed

CLD
MOV AX, DATA_SEGMENT
MOV DS, AX
MOV AX, EXTRA_SEGMENT
MOV ES, AX
MOV CX, 20H
MOV SI, OFFSET MASTER
MOV DI, OFFSET COPY
REPMOVSB

50
Input/ Output Instructions
 Types of instructions
• Direct I/O instructions—only allow
access to ports at page 0 addresses
• Variable I/O instructions—allows
access of ports anywhere in the I/O
address space
• Direct I/O instructions
IN Acc,Port
OUT Port,Acc
• Port = 8-bit direct address—limited
to 0H through FFH (page 0)
• Acc = accumulator register AX (word
transfer); AH or AL (byte transfer)
• Example:
IN AL, FE
(FE)  AL (byte input operation)

51
Input/ Output Instructions
• Variable I/O instructions
IN Acc,DX
OUT DX,Acc
• DX = 16-bit indirect address—allows
access to full I/O address space
• Acc = accumulator register AX (word
transfer); AH or AL (byte transfer)
• Example:
MOV DX,A000 ;load I/O address
IN AL,DX ;input value to AL
MOV BL,AL ;copy value to BL
(A000)  BL (byte input operation)

52
Input/ Output Instructions
Example1:
Write instructions to output the value FF to the byte wide port at I/O address
AB.

Solution:
MOV AL, FF ;load data into AL
OUT AB, AL ;output to port
AB
Example2:
Write instructions to output the value FF to the byte wide port at I/O address
B000.
Solution:
MOV DX, B000 ; load address into DX
MOV AL, FF ; load data into AL
OUT DX,AL ; output to port B000

53
Input/ Output Instructions
Example3:
Read data from byte-wide ports at addresses AA and A9. Output as a word to
the word-wide port at address B000.

Solution:

IN AL,AA ; input first byte


MOV AH,AL ; load data into AL
IN AL,A9 ; input 2nd byte
MOV DX,B000 ; load address into DX
OUT DX,AX ; output word to port B000

54

You might also like