string instructions Flashcards

(20 cards)

1
Q

What are the 8086 string instructions and their purposes?

A

MOVS: Move data between memory blocks. CMPS: Compare two strings. SCAS: Scan a string for a value. LODS: Load data into AL/AX. STOS: Store AL/AX into memory. REP: Repeat instructions based on CX/flags.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does MOVSB work?

A

MOVSB: Copies a byte from [DS:SI] to [ES:DI]. Updates SI/DI: Increments if DF=0 (CLD), decrements if DF=1 (STD). Example: REP MOVSB copies CX bytes from DS:SI to ES:DI.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the role of the Direction Flag (DF)?

A

CLD (DF=0): SI/DI increment after each operation. STD (DF=1): SI/DI decrement. Affects MOVS, CMPS, SCAS, LODS, STOS.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does CMPSB compare strings?

A

CMPSB: Subtracts [ES:DI] from [DS:SI], updates flags. Flags: CF=1 if [DS:SI] < [ES:DI], ZF=1 if equal. SI/DI updated based on DF. Example: REPE CMPSB repeats while equal.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does SCASB do?

A

SCASB: Compares AL with [ES:DI]. Flags: ZF=1 if AL == [ES:DI]. DI updated based on DF. Example: REPNE SCASB scans until AL is found.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does LODSW function?

A

LODSW: Loads a word from [DS:SI] into AX. SI incremented/decremented based on DF. Example: LODSW → AX = [DS:SI], SI += 2 (if DF=0).”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of STOSW?

A

STOSW: Stores AX into [ES:DI]. DI incremented/decremented based on DF. Example: REP STOSW fills CX words with AX.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do REP prefixes work?

A

REP: Repeats until CX=0 (e.g., REP MOVSB). REPE/REPZ: Repeats while ZF=1. REPNE/REPNZ: Repeats while ZF=0. Example: REPE CMPSB stops on mismatch or CX=0.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What flags are affected by CMPSB?

A

Flags: CF (carry), ZF (zero), SF (sign), PF (parity), OF (overflow). ZF=1 if bytes are equal, CF=1 if source < destination.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to copy a block of memory using string instructions?

A

“1. LEA SI, source; LEA DI, destination. 2. CLD (set forward direction). 3. MOV CX, count. 4. REP MOVSB. Copies CX bytes from DS:SI to ES:DI.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens during REP STOSB?

A

REP STOSB: Stores AL into [ES:DI] CX times. DI increments/decrements after each store. Example: Fills a buffer with AL value.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to find a byte in a string using SCASB?

A

“1. LEA DI, string. 2. CLD. 3. MOV AL, target. 4. MOV CX, length. 5. REPNE SCASB. Stops when AL matches or CX=0.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between LODSB and LODSW?

A

LODSB: Loads a byte into AL, SI ±1. LODSW: Loads a word into AX, SI ±2. Example: LODSW → AX = [DS:SI], SI += 2 (DF=0).”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does REPE CMPSB terminate?

A

“Stops when CX=0 (end of string) or ZF=0 (mismatch found). Example: Compares strings until they differ.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What registers are used in string operations?

A

SI: Source index (DS segment). DI: Destination index (ES segment). CX: Counter for REP. AX/AL: Data for LODS/STOS/SCAS.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an example of STOSB usage?

A

LEA DI, buffer; CLD; MOV AL, 'A'; MOV CX, 10; REP STOSB. Fills 10 bytes in buffer with ‘A’.”

17
Q

How to reverse a string using STD?

A

“1. LEA SI, end_addr; LEA DI, dest_addr. 2. STD (DF=1). 3. MOV CX, len; REP MOVSB. Copies backward.”

18
Q

What happens if CX=0 before REP MOVSB?

A

“No operation. REP checks CX first; if CX=0, the instruction skips.”

19
Q

How does SCASW differ from SCASB?

A

SCASW: Compares AX with [ES:DI] (word). DI ±2 based on DF. SCASB: Compares AL with [ES:DI] (byte). DI ±1.”

20
Q

What is the result of CMPSW if [DS:SI]=1234h and [ES:DI]=5678h?

A

Flags: CF=1 (1234h < 5678h), ZF=0. SI/DI incremented/decremented by 2 (DF=0).