Professional Documents
Culture Documents
String and String-Handling Instructions
String and String-Handling Instructions
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:
54