Top Banner

Click here to load reader

of 31

Assignment on alp

Jun 11, 2015




2. FLAG REGISTERFLAGS Register: Individual bits control the action or represent the status of theprocessorControl flags (TF, IF, DF): Determine how the processor responds to certain situationsStatus flags (CF, PF, AF, ZF, SF, OF): Set to represent the result of certain operations Used to control conditional jump instructions 3. FLAG Register Bits:Status Flags:Control Flags:Bit Name Symbol Bit Name Symb ol0 Carry flagCF 8 Trap flagTF2 Parity flag PF4 Auxiliary carry flagAF 9 Interrupt flag IF6Zero flagZF 10Direction flag DF7Sign flagSF11Overflow flag OF 4. Status Flags:The Carry Flag (CF): CF = 1 if there is a carry out from the msb (mostsignificant bit) on addition, or there is a borrow into themsb on subtraction CF = 0 otherwise CF is also affected by shift and rotate instructionsThe Parity Flag (PF): PF = 1 if the low byte of a result has an even numberof one bits (even parity) PF = 0 otherwise (odd parity) 5. The Auxiliary Carry Flag (AF): AF = 1 if there is a carry out from bit 3 on addition, or there isa borrow into the bit 3 on subtraction AF = 0 otherwise AF is used in binary-coded decimal (BCD) operationsThe Zero Flag (ZF): ZF = 1 for a zero result ZF = 0 for a non-zero resultThe Sign Flag (SF): SF = 1 if the msb of a result is 1; it means the result isnegative if you are giving a signed interpretation SF = 0 if the msb is 0 6. The Overflow Flag (OF): OF = 1 if signed overflow occurred OF = 0 otherwiseExample 1. ADD AX,BX , where AX contains FFFFh , BX containsFFFFh.Solution:FFFFh + FFFFh 1FFFEhThe result stored in AX is FFFEh=1111 1111 1111 1110SF = 1 because the msb is 1PF = 0 because there are 7(odd number) of 1 bits in the low byte ofthe result .ZF = 0 because the result is nonzero.CF = 1 because there is a carry out of the msb on addition.OF = 0 because the sign of the stored result is the same as that ofthe numbers being added (as a binary addition, there is a carryinto the msb and a carry out). 7. Example 2. ADD AX, BX, where AX contains 7132h ,BX contains 7000h Solution:7132h+ 7000hE132h The result stored in AX is E132h=1110 0001 0011 0010 SF = 1 because the msb is 1 PF = 0 because there are 3(odd number) of 1 bits in thelow byte of the result . ZF = 0 because the result is nonzero. CF = 0 because there is no a carry out of the msb onaddition. OF = 1 8. Example-3: SUB AX, BX , where AX contains 8000h and BXcontains 0001h. Solution:8000h -0001h7FFFh The result stored in AX is FFFEh=0111 1111 1111 1111 SF = 0 because the msb is 0 PF = 1 because there are 8(even number) of 1 bits in the low byteof the result . ZF = 0 because the result is nonzero. CF = 0 because a smaller unsigned number is being subtractedfrom a larger one. Now for OF. In a signal sense, we are subtracting a positive numberfrom a negative one, which is like adding two negatives. Becausethe result is positive (the wrong sign), OF = 1. 9. OVERFLOW The overflow flag is set when the Most SignificantBit (MSB) is set or cleared. For example, take the addition of 127 and 127.The 8 bit signed binary number of 127 isrepresented as 0111 1111. The MSB (the bit to the far left) is 0. When thesetwo 8 bit numbers are added the result is 254, or1111 1110. Notice now that the MSB is now 1 andnot 0. Therefore, the overflow flag has been set. Here,1111 1110 would be interpreted as a negativenumber. 10. The addition test shows whether the overflowflag has been set.If two positive operands generate a negativesum. For example, 0101 1100 and 0100 1010 is1010 0110, or -90. The MSB changed from 0 to 1. And the two negative operands generate apositive sum. For example 1100 0010 and 1000 0100 is01101000 or 104. The MSB changed from 1 to 0, so the overflowflag is being set.Overflow never occurs when the sign of twoaddition operands are different. 11. (Signed) Overflow Can only occur when adding numbers of the same sign (subtractingwith different signs) Detected when carry into MSB is not equal to carry out of MSB Easily detected because this implies the result has a different signthan the sign of the operands Programs can ignore the Flags 12. Example 4. ADD AX,BX , where AX and BX both contains 7FFFh .Solution: HexBinary7FFFh0111 1111 1111 11117FFFh0111 1111 1111 1111FFFEh1111 1111 1111 1110The signed and unsigned interpretation of 7FFFh is 32767. Thus forboth signed and unsignedaddition,7FFFh+7FFFh=32767+32767=65534.This is out of rangefor signed numbers, the signed interpretation of the stored answerFFFEh is -2,so signed overflow occurred .However the unsignedinterpretation of FFFEh is 65534,which is the right answer, so thereis no unsigned overflow. 13. Unsigned overflow: On addition, unsigned overflow occurs when there is a carry out ofthe msb. On subtraction unsigned overflow occurs when there is a borrowinto the msb.Example 5. ADD AX, BX, where AX contains FF12h, BX contains 1ACBh.Solution: FF12h+ 1ACBh119DDhThe result is stored in AX is 19DDh=0001 11 111 1101FF12h=-1 and 1ACBh=1, and FF12h+1ACBh=-1+1=0, so sign overflow didnot occur. Here a 1 is carried out of the msb, so unsigned overflow occurred. 14. The importance of flag registers:Flag register has its importance by following resion.1. Sign flag: use to store the sign of any number under processing i.ewhen arithmetical logic has negative sign it is in set condition. andrest in reset.2. Zero flag: when ALU operation is zero it is in reset condition.3. Auxiliary carry flag: it hold the carry during internal processing ofaddition ,sub , mul and div.4. Parity flag: hold 1 for even parity,0 for odd parity.5. Carry flag: hold carry after end of processing of operation. 15. FLAGS Register & Flowcontrol Instruction Flags RegisterIndividual bits control the action orrepresent the status of the processor 16. Control flags (TF, IF, DF): Determine howthe processor respondsto certain situationsStatus flags (CF, PF, AF, ZF, SF, OF): Set to represent the result of certain operations Used to control conditional jumpinstructions 17. Flow Control Instructions:In this assignment we will practice how tocontrol the flow of an assembly languageprogram using the compare instruction, thedifferent jump instructions and the loopinstructions.Objectives:1- Jump Instructions.2- Compare Instruction.3- Loop Instructions. 18. Jump Instructions:The jump instructions are used to transferthe flow of the program to the indicatedOperator.Here we discus about various categories.Conditional Jumps:There are Three categories of ConditionalJumps: a)Singed Jumps b)Unsigned Jumps: c) Single-Flag Jumps: 19. The Unconditional Jump:The unconditional jump may beused to make infinite loops. Though the use of such instructions is notrecommended in high levellanguages, due to the availability of program control structures, inassembly however, most of the timeone must use the unconditional jump. 20. The JMP InstructionsThe JMP instruction causes an unconditional transfer of control(unconditional jump).The syntax is 21. IF-THEN: The IF-THEN structure may be expressedin pseudocode as followIF (condition is true) THENExecute true-branch statementsEND_IF 22. IF-THEN-ELSEIF condition is true THENExecute true-branch statementsELSEExecute false-branch statementsEND-IF 23. LoopLoops represent the final basic control structure(sequences, decisions, and loops) which makeup a typical program. Program loops consist ofthree components: an optional initializationcomponent, a loop termination test, and thebody of the loop. 24. FOR LOOP FOR LOOP_COUNTInitialize counttimes DOStatementsStatementEND_FORCount=count-1falsecount=otrue 25. EXAMPLE Write a count-controlled loop to display A to Z 26 characterThe code is MOV CX, 26 MOV AH, 2 MOV DL, A TOP:INT21HLOOP TOP 26. While Loops WHILE conditionDo Statements END_WHILE 27. Example I = 0;mov I, 0 WHILE (I

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.