Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Av222 lab 1 st part

89
views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
89
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 6. OUTPUT:Location Value4000 4D4002 D45000 195002 1
• 7. LAB 2: BASIC MULTIPLICATION & DIVISIONQUESTION 1:Write an ALP IN 8086 to multiply two 16-bit numbers and store the result.ALGORITHM: Initialize the Data Segment. Store 16-bit numbers in locations 4000 - 4003. Read the first number in AX register and the second number in BX register. Multiply the 2 values using ‘MUL’ instruction. Store the product in location 5000 and Carry in 5002.PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8B 04 MOV AX, [SI] Getting the 1stvalue to AX register200D 46 INC SI Incrementing the Source Index200E 46 INC SI Incrementing the Source Index200F 8B 1C MOV BX, [SI] Getting the 2ndvalue to BX register2011 F7 E3 MUL BX Multiplying AX with BX, storing Quot. in AX2013 89 15 MOV [DI], DX Storing the the high word in the location2015 47 INC DI Incrementing the Destination Index2016 47 INC DI Incrementing the Destination Index2017 89 05 MOV [DI], AX Moving Carry to 50022019 CC INT 03 End of the ProgramOUTPUT:Location Value4000 044002 045000 105002 00QUESTION 2:Write an ALP IN 8086 to divide a 16-bit number with an 8-bit number and store the result.
• 8. ALGORITHM: Initialize the Data Segment. Store the 16-bit number in location 4000 and the 8-bit number in location 4002. Read the first number in AX register and the second number in BL register. Divide the 2 values using ‘DIV’ instruction. Store the quotient in location 5000 and remainder in 5002.PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8B 04 MOV AX, [SI] Getting the 1stvalue to AX register200D 46 INC SI Incrementing the Source Index200E 46 INC SI Incrementing the Source Index200F 8A 1C MOV BL, [SI] Getting the 2ndvalue to BL register2011 F6 E3 DIV BL Dividing AX by BL and Quot. in AL register2013 88 05 MOV [DI], AL Storing the Quotient in location 50002015 47 INC DI Incrementing the Destination Index2016 88 25 MOV [DI], AH Storing the Remainder in location 50012018 CC INT 03 End of the ProgramOUTPUT:Location Value4000 104002 075000 025002 02QUESTION 3:Write an ALP IN 8086 to find Factorial of a number.ALGORITHM: Initialize the Data Segment. Store the number (8-bit) for which factorial is required in location 4000. Read the number in AL register. Recursively decrease and multiply to get the Factorial. Store the result in location 5000.
• 9. PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8A 04 MOV AL, [SI] Getting the 1stvalue to AL register200D 46 INC SI Incrementing the Source Index200E 8A 1C MOV BL, [SI] Getting the 2ndvalue to BL register2010 F6 E3 MUL BL Multiply value of AL with BL register.2012 FE CB DEC BL Decrementing the value stored in BL register2014 74 01 JZ 2018 Jump if Zero to 20182016 EB F8 JMP 2010 Unconditional JMP to 20102018 88 05 MOV [DI], AL Moving the Factorial to 5000201A CC INT 03 End of the ProgramOUTPUT:Location Value4000 014001 055000 78QUESTION 4:Write an ALP IN 8086 to find LCM of 2 Numbers.ALGORITHM: Initialize the Data Segment. Store 16-bit numbers in locations 4000 - 4003. Read the first number in AX register and the second number in BX register. Use Euclid’s lemma concept of finding HCF. Then use the property of HCF and LCM, viz, HCF x LCM = Product of the numbers. Store the LCM in location 5000.
• 11. PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8B 04 MOV AX, [SI] Getting the 1stvalue to AX register200D 46 INC SI Incrementing the Source Index200E 46 INC SI Incrementing the Source Index200F 8B 1C MOV BX, [SI] Getting the 2ndvalue to BX register2011 46 INC SI Incrementing the Source Index2012 46 INC SI Incrementing the Source Index2013 8B 0C MOV CX, [SI] Getting the 3rdvalue to CX register2015 F7 E3 MUL BX Multiplying value of AX register with BX2017 8B DA MOV BX, DX Moving the value of DX register to BX2019 F7 E1 MUL CX Multiplying value of AX register with CX201B 89 05 MOV [DI], AX Moving value of AX register to location 5000201D 8B C1 MOV AX, CX Moving the value of CX register to AX201F 8B CA MOV CX, DX Moving the value of DX register to CX2021 F7 E3 MUL BX Multiplying value of AX register with BX2023 03 C1 ADD AX, CX Adding values of AX, CX registers2025 47 INC DI Incrementing the Destination Index2026 47 INC DI Incrementing the Destination Index2027 89 05 MOV [DI], AX Moving value of AX register to location 50022029 47 INC DI Incrementing the Destination Index202A 47 INC DI Incrementing the Destination Index202B 89 15 MOV [DI], DX Moving value of DX register to location 5004202D CC INT 03 End of the ProgramOUTPUT:Location Value4000 024002 034003 045000 065002 185004 00
• 12. LAB 3: ARRAYSQUESTION 1:Write an ALP IN 8086 to find the largest number from a given array.ALGORITHM: Initialize the Data Segment. Store 8-bit numbers in locations beginning from 4000. Read the first number in AL register and the second number in BL register. Perform swapping of the two numbers in such a way that the larger number comes1st. Repeat the above procedure equal to the number of numbers which are compared.PROGRAM:Addr Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8A 0C MOV CL, [SI] Getting the no. of numbers to CL register200D 46 INC SI Incrementing the Source Index200E 8A 04 MOV AL, [SI] Getting the 1stvalue to AL register2010 46 INC SI Incrementing the Source Index2011 8A 1C MOV BL, [SI] Getting the 2ndvalue to BL register2013 FE C9 DEC CL Decrementing the value of CL register2015 74 04 JE 201B Jump if Zero to 201B2017 3A C3 CMP AL, BL Comparing values of AL, BL registers2019 72 03 JB 201E Jump if Borrow is generated to 201E201B 88 05 MOV [DI], AL Moving the value of AL register to 5000201D CC INT 03 End of the Program201E 8A C3 MOV AL, BL Moving the value of BL register to AL2020 EB EE JMP 2010 Unconditional to 2010OUTPUT:Location Value4000 044001 604002 554003 174004 894005 364006 76
• 13. 4007 454008 044009 105000 89QUESTION 2:Write an ALP IN 8086 to find the 2ndlargest number from a given array.ALGORITHM: Initialize the Data Segment. Store 8-bit numbers in locations beginning from 4000. Read the first number in AL register and the second number in BL register. Perform swapping of the two numbers in such a way that the larger number comes1st. Repeat the above procedure equal to the number of numbers which are compared.PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2003 BF 00 50 MOV DI, 5000 Loading location 5000 to Destination Index2006 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B 8B 0C MOV CX, [SI] Getting the no. of numbers to CX register200D 46 INC SI Incrementing the Source Index200E 46 INC SI Incrementing the Source Index200F 8A 04 MOV AL, [SI] Getting the 1stvalue to AL register2011 46 INC SI Incrementing the Source Index2012 8A 1C MOV BL, [SI] Getting the 2ndvalue to BL register2014 3A C3 CMP AL, BL Comparing values of AL, BL registers2016 76 02 JBE 201A Jump if below or equal to 201A2018 8A C3 MOV AL, BL Moving the value of BL register to AL201A E2 F5 LOOP 2011 Looping the statement from 2011201C BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index201F 8B 0C MOV CX, [SI] Getting the no. of numbers to CX register2021 46 INC SI Incrementing the Source Index2022 46 INC SI Incrementing the Source Index2023 8A 24 MOV AH, [SI] Moving the value at 4002 to AH register2025 46 INC SI Incrementing the Source Index2026 8A 1C MOV BL, [SI] Moving the value at 4003 to AH register2028 3A DC CMP BL, AH Comparing values of BL, AH registers202A 75 F3 JBE 201F Jump if below or equal to 201F202C 3A D8 CMP BL, AL Comparing values of BL, AL registers
• 14. 202E 73 02 JNB 2032 Jump if no Borrow is generated to 20322030 8A E3 MOV AH, BL Moving the value of BL register to AH2032 E2 F1 LOOP 2025 Looping the statements from 20252034 88 25 MOV [DI], AH Moving the value of AH register to 50002036 CC INT 03 End of the ProgramOUTPUT:Location Value4000 044001 604002 554003 174004 894005 364006 764007 454008 044009 105000 76QUESTION 3:Write an ALP IN 8086 for arranging a given array of elements in ascending order.ALGORITHM: Initialize the Data Segment. Store 8-bit numbers in locations beginning from 4000. Read the first number in AL register and the second number in BL register. Perform swapping of the two numbers in such a way that the larger number comes1st. Repeat the above procedure equal to the number of numbers which are compared.
• 15. PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 B8 00 00 MOV AX, 0000 Loading the value 0000 to AX register2003 8E D8 MOV DS, AX Initializing Data Segment using AX register2005 B2 05 MOV DL, 05 Loading DL register with the value 052007 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index200A 8A F0 MOV DH, AL Moving the value of AL register to DH200C 8A 04 MOV AL, [SI] Getting the 1stvalue to AL register200E 46 INC SI Incrementing the Source Index200F 8A 24 MOV AH, [SI] Getting the 2ndvalue to AH register2011 3A E0 CMP AH, AL Comparing values of AH, AL registers2013 77 0B JNBE 201B Jump if not below or equal to 201B2015 88 04 MOV [SI], AL Moving the value of AL register to SI2017 4E DEC SI Decrementing the Source Index2018 88 34 MOV [SI], AH Moving the value of BH register to SI201A 46 INC SI Incrementing the Source Index201B FE CF DEC BH Decrementing the value of BH201D 80 FF 00 CMP BH, 00 Comparing value of BH with 002020 77 EA JNBE 200C Jump if not below or equal to 200C2022 FE CA DEC DL Decrementing the value of DL2024 80 FA 00 CMP DL, 00 Comparing value of DL with 002027 77 DE JNBE 2007 Jump if not below or equal to 20072029 CC INT 03 End of the ProgramOUTPUT:Location Value (before) Location Value (after)4000 04 4000 044001 60 4001 044002 55 4002 104003 17 4003 174004 89 4004 364005 36 4005 454006 76 4006 554007 45 4007 604008 04 4008 764009 10 4009 89
• 16. QUESTION 4:Write an ALP IN 8086 for sorting a given array of strings in Alphabetical order.[Hint: Write a subroutine to compare and exchange two strings. Use strings of fixedlength]Instructions useful for the lab session:Instruction Operands DescriptionCMPSB No OperandsCompare bytes: ES: [DI] from DS: [SI].Algorithm: DS: [SI] - ES: [DI]Set flags according to the result:OF, SF, ZF, AF, PF, CFIf DF = 0 then SI = SI + 1 DI = DI +1Else SI = SI – 1 DI = DI – 1REPE ChaininstructionRepeat following CMPSB, CMPSW, SCASB, SCASWinstructions while ZF = 2 (result is Equal), maximum CXtimes.Algorithm:Check_CX:If CX </> 0 then do the following chain instructions CX = CX – 1 If ZF = 1 then:o Go back to Check_CXElseo Exit from REPE cycleElse Exit from REPE cycleAlso study CMPSW, REPNE, REPNZ, REPZ, SCASW and SCASB.ALGORITHM: Initialize the Data Segment. Initialize CX register with number of elements in string. Compare the strings, stored in the Source Index and Destination Index, byte by byte. Store 00 if both are Equal, otherwise 01 if both are not equal.