FLAG & PROCESSOR & STRING INSTRUCTIONS.pptx
susmithaganapathi
12 views
17 slides
Sep 23, 2024
Slide 1 of 17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
About This Presentation
Microprocessor
Size: 2.94 MB
Language: en
Added: Sep 23, 2024
Slides: 17 pages
Slide Content
FLAG MANIPULATION AND PROCESSOR CONTROL INSTRUCTIONS & STRING INSTRUCTIONS INSTRUCTIONS - 8086 By: G.SUSMITHA II M.Sc PHYSICS
FLAG MANIPULATION INSTRUCTION TO MODIFY STATUS FLAGS 1.CARRY FLAG *SET *CLEAR *COMPLEMENT 2.DIRECTION FLAG *SET *CLEAR 3 .INTERRUPT FLAG *SET *CARRY
CLC( Clear carry flag CF) code= F8 This instruction resets the carry flag CF=0.Other flags are not affected. . CARRY FLAG CMC (Take complement of carry flag CF). Code= F5. This instruction takes complement of the carry flag CF. If CF is 0, this instruction sets it to 1. If CF=1, this instruction resets it to 0.Other flags ar e not affected. STC(Set carry flag CF to 1.) Code=F9. No other flags are affected.
FLAG MANIPULATION CLD(Clear direction flag DF) Code=FC This instruction resets the direction flag DF to 0. Other flags are not affected . STD( Set direction flag DF to 1.) Code=FD No other flags are affected. DIRECTION FLAG
CLI(Clear interrupt flag IF). Code=FA This instruction resets the interrupt flag IF to 0. Other flags are not affected. When IF id reset, an interrupt s i gnal on INTR line will not be entertained. CLI does not affect nonmaskable interrupt NMI. STI (Set interrupt flag IF to 1). This instruction sets interrupt flag IF to 1, to enable INTR interrupt. No other flags are affected. INTERRUPT FLAG
PROCESSOR CONTROL INSTRUCTIONS HLT: Halt The instruction HLT causes the processor to enter halt state * The CPU stops fetching &executing of the instruction. * The CPU can be brought out of the halt state with the following events Interrupt signal on INTR pin Interrupt signal on NMI pin Reset signal on RESET pin NOP: no operation * It is used to add wait state of 3 clock cycles during 3 clock cycles does not perform any operation. * It can be used to add delay loop in the program delay the operation before going to read or write from port.
WAIT It causes processor to enter into an ideal or wait state- continue to remain in that state till the processor receives state until one of the following signal: Signal on processor TEST pin A valid interrupt on INTR pin A valid interrupt on NMI pin This signal used to synchronize with other external hardware. LOCK This instruction prevent other processor to take the control of shared resources. * The lock instruction is used as a prefix to the critical instruction that has to execute. * Example: LOCK IN AL, 80H
* 8086 instruction set includes instruction for string movement, comparison, scan, load and store. * String instructions end with S or SB or SW. S represents string, SB string byte and SW string word. * Offset or effective address of the source operand is stored in SI register and that of the destination operand is stored in DI register. * Depending on the status of DF, SI and DI registers are automatically updated. 1. DF = 0 ; SI and DI are incremented by 1 for byte and 2 for word. 2. DF = 1 ;SI and DI are decremented by 1 for byte and 2 for word. STRING INSTRUCTIONS * String is a assembly language,it is stored bytes or words in sequential memory locations. * Index Register i )SI (Data segment) ii)DI(Extra segmen t) Counter : CX (General purpose or special function register used in this string instructions )
DIRECTION FLAG FOR STRING INSTRUCTIONS Controls the direction of string operations. If DF is set to 0, the string operations are performed from left to right. If DF is set to 1, the string operations are performed from right to left. 1. MOVS/MOVSB/MOVSW 2. CMPS/CMPSB/ CMPSW 3. SCAS /SCASB/SCASW 4. LODS/LODSB/LODSW 5. STOS/STOSB/STOSW REPEAT INSTRUCTION REP/REPE/REPZ/REPNE/REPNZ TYPES OF STRING INSTRUCTIONS
MOVS / MOVSB / MOVSW: It causes moving of byte or word from one string to another. In this instruction, the source string is in Data Segment referred by DS:SI and destination string is in Extra Segment referred by ES:DI. MOVS :Copies contents of BYTE given by DS:SI into ES:DI MOVSW :Copies contents of WORD given by DS:SI into ES:DI
MOVSD :Copies content of DOUBLE WORD given by DS:SI into ES:DI MOVE MEMORY TO MEMORY
EXAMPLE Opcode Instruction Description A4 MOVS m8, m8 Move byte at address DS:(E)SI to address ES:(E)DI A5 MOVS m16, m16 Move word at address DS:(E)SI to address ES:(E)DI A5 MOVS m32, m32 Move doubleword at address DS:(E)SI to address ES:(E)DI A4 MOVSB Move byte at address DS:(E)SI to address ES:(E)DI A5 MOVSW Move word at address DS:(E)SI to address ES:(E)DI A5 MOVSD Move doubleword at address DS:(E)SI to address ES:(E)DI
COMPARE MEMORY WITH MEMORY Logic: CMP (DS:SI), (ES:DI) ; Sets flags only if DF = 0 SI =SI + 1 DI =DI + 1 else SI = SI - 1 DI = DI - 1 This instruction compares two values by subtracting the byte pointer to by ES:DI, from the byte pointed to by DS:SI, and sets the flags according to the results of the comparison. The operands themselves are not altered. After the comparison, SI and DI are incremented . (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for comparing the next element
LODS / LODSB / LODSW: It causes TRANSFER of byte or word from one string to another. LOADING INSTRUCTION * This instruction copies a byte from a string location pointed to by SI to AL, or a word from a string location pointed to by SI to AX. LODS does not affect any flags. LODSB copies byte and LODSW copies a word. LODSB: moves the byte at address DS:SI into AL; SI is incr / decr by1 LODSW: moves the word at address DS: SI into AX; SI is incr / decr by 2
* The STOS instruction copies a byte from AL or a word from AX to a memory location in the extra segment. * DI is used to hold the offset of the memory location in the extra segment. After the copy, DI is automatically incremented or decremented to point to the next string element in memory. * If the direction flag, DF, is cleared, then DI will automatically be incremented by one for a byte string or incremented by two for a word String Instruction in 8086. * If the direction flag is set, DI will be automatically decremented by ono for a byte string or decremented by two for a word string. STOS does not affect any flags. STOSB copies byte and STOSW copies a word. STOS/STOB/STOW
( i ) REP (Repeat): This is an instruction prefix. It causes the repetition of the instruction until CX becomes zero. E.g.: REP MOVSB It copies byte by byte contents. REP repeats the operation MOVSB until CX becomes zero. REPEAT INSTRUCTIONS
(ii) REPE (or REPZ). Code = F3 Repeat if CX is not 0 and ZF = 1 * REPE and REPZ are two mnemonics for the same instruction. * REPE or REPZ is a prefix instruction which is used before the string instruction CMPS or SCAS. * It repeats the string instruction when CX is not zero and zero flag ZF = 1. Repetition stops when when CX is decremented to 0 or ZF = 0. (iii) REPNE (or REPNZ). Repeat if CX is not zero and ZF = 0. Code = F2 * REPNE and REPNZ are two mnemonics for the same instruction. * REPNE or REPNZ is a prefix instruction which is often used before the string instruction SCAS . * It repeats the string instruction when CX is not zero and ZF = 0. Repetition stops when CX is decremented to 0 or ZF = 1.