assembly flag resister
-
Upload
safayet-hossain -
Category
Education
-
view
50 -
download
0
Transcript of assembly flag resister
![Page 1: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/1.jpg)
WelcomeGroup : V
![Page 2: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/2.jpg)
OUR GROUP
Swapnil Saha 151-15-4939Safayet Hossain 151-15-4938Md. Shahadat Hoseen 151-15-5187Fahmida Al Ikra 151-15-5076Khurshida Jahan 151-15-5190
![Page 3: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/3.jpg)
FLAGS resister and
Their changes due to operation of 8086
![Page 4: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/4.jpg)
What is FLAGS register ??
FLAGS resister:The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. 8086 has 16 flag registers among which 9 are active. The purpose of the FLAGS register is to indicate the
status of the processor. It does this by setting the individual bits called flags.
![Page 5: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/5.jpg)
Types of FLAGS:There are two kinds of FLAGS.
1. Status FLAGS 2. Control FLAGS
![Page 6: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/6.jpg)
Types of FLAGSStatus FLAGS : Status FLAGS reflect the result of an operation
executed by the processor
Control FLAGS : The control FLAGS enable or disable certain
operations of the processor.
![Page 7: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/7.jpg)
![Page 8: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/8.jpg)
FLAG Register Bits
![Page 9: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/9.jpg)
Status FlagsThe Carry Flag (CF) : CF = 1 if there is a carry out
from the msb (most significant bit) on addition, or there is a borrow into the msb on subtraction.
CF = 0 otherwise CF is also affected by shift
and rotate instructions
![Page 10: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/10.jpg)
Status FlagsThe Parity Flag (PF): PF = 1 if the low byte
of a result has an even number of one bits (even parity)
PF = 0 otherwise (odd parity)
![Page 11: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/11.jpg)
Status FlagsThe Auxiliary Carry Flag (AF): AF = 1 if there is a carry out
from bit 3 on addition, or there is a borrow into the bit 3 on subtraction
AF = 0 otherwise AF is used in binary-coded
decimal (BCD) operations
![Page 12: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/12.jpg)
Status FlagsThe Zero Flag (ZF) : ZF = 1 for a zero result ZF = 0 for a non-zero result In this example the result is
not zero. So ZF=0
![Page 13: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/13.jpg)
Status FlagsThe Sign Flag (SF) : SF = 1 if the msb of a
result is 1; it means the result is negative if you are giving a signed interpretation
SF = 0 if the msb is 0In this Example the msb of
the result is 1. So SF=1
![Page 14: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/14.jpg)
Status FlagsThe Overflow Flag (OF): OF = 1 if signed overflow occurred OF = 0 otherwise
Overflow flag is 2 types:1.Signed2. Unsigned
![Page 15: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/15.jpg)
Control FlagsDirection Flag (DF) : - this flag is used by some instructions to process data
chains, when this flag is set to 0 - the processing is done forward, when this flag is set to 1 the processing is done backward.
Interrupt enable Flag (IF): when this flag is set to 1 CPU reacts to interrupts
from external devices.Trap Flag (TF): Used for on-chip debugging.
![Page 16: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/16.jpg)
How instruction affect the flagsInstruction affect flagsMOV/XCHG noneADD/SUB allINC/DEC all except CFNEG all(CF=1 unless result is 0 ;OF=1 if word operand is 8000h or byte operand is 80h)
![Page 17: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/17.jpg)
Example1:ADD AX,BX,where AX contains FFFFh,BX contains FFFFh.Solution: FFFFh +FFFFh 1FFFEhThe result stored in AX is FFFEh =1111 1111 1111 1110
![Page 18: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/18.jpg)
Example2:ADD Al,Bl,where Al contains 80h,Bl contains 80h.
Solution: 80h +80h 100hResult stored in Al is 00h.
![Page 19: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/19.jpg)
Example 3:INC AL , where AL contains FFh.
Solution :
FFh+ 1h100hThe result stored in AL is 00h. SF = 0, PF =1, Zf =1. Even though there is a carry out, CF is unaffected by INC. this means that if CF = 0 before the execution of the instruction , CF will still be 0 afterward. OF = 0 because numbers of unlike sign are being added (there is a carry into the msb and also a carry out ).
![Page 20: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/20.jpg)
Example 4: MOV AX,-5
Solution:The result stored in AX is -5=FFFBh.
None of the flags are affected by MOV.
![Page 21: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/21.jpg)
Example 5 : NEG AX , where AX contains 8000hSolution :
8000h=1000 0000 0000 0000One’s complement=0111 1111 1111 1111 +1 1000 0000 0000 0000=8000hThe result stored in AX is 8000h.
SF=1, PF=1 ,ZF=0.CF=1, because for NEG CF is always 1 unless the result is 0.OF=1, because the result is 8000h; when a number is negated, we would expect a sign change, but because 8000h is its own two’s complement , there is no sign change.
![Page 22: assembly flag resister](https://reader036.fdocuments.us/reader036/viewer/2022070603/587054f11a28aba2118b5181/html5/thumbnails/22.jpg)
Thanks