Your SlideShare is downloading. ×
Av222 lab 1 st part
Upcoming SlideShare
Loading in...5
×

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.
Text the download link to your phone
Standard text messaging rates apply

Av222 lab 1 st part

89
views

Published on

Published in: Business, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. LAB 1: BASIC ADDITION & SUBTRACTIONQUESTION 1:Write a program to add 2 eight bit numbers and store the sum and carry.ALGORITHM: Initialize the Data Segment. Store 2 eight bit numbers in locations 4000 and 4001. Read the first number in AL register and the second number in BL register. Add the 2 values. Store the sum in location 5000. If carry is produced, then store 01 in location 5001, else store 00 in that location.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 02 C3 ADD AL, BL Adding & Storing the result in AL register2012 72 08 JC 201C Jump to 201C if carry is generated2014 B1 00 MOV CL, 00 Loading 00 to CL register2016 88 05 MOV [DI], AL Storing the Sum in location 50002018 47 INC DI Incrementing the Destination Index2019 88 05 MOV [DI], CL Storing the Carry in location 5001201B CC INT 03 End of the Program201C B1 01 MOV CL, 01 Loading 01 to CL register201E EB F6 JMP 2016 Unconditional Jump to 2016OUTPUT:Location Value4000 A4001 75000 15001 1
  • 2. QUESTION 2:Write a program to add 2 sixteen bit numbers using 8 – bit addition and store the sum andcarry.ALGORITHM: Initialize the Data Segment. Store 2 sixteen bit numbers in locations 4000 – 4003. Read the first number in AX register and the second number in BX register. Add the 2 values using 8 – bit addition. (Hint: use ADC instruction) Store the sum in location 5000 and 5001. If carry is produced, then store 01 in location 5002, else store 00 in that location.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 (1st8-bit) to AL register200D 46 INC SI Incrementing the Source Index200E 8A 1C MOV BL, [SI] Getting the 2ndvalue (1st8-bit) to BL register2010 46 INC SI Incrementing the Source Index2011 8A 24 MOV AH, [SI] Getting the 1stvalue (2nd8-bit) to AH register2013 46 INC SI Incrementing the Source Index2014 8A 3C MOV BH, [SI] Getting the 2ndvalue (2nd8-bit) to BH register2016 02 C3 ADD AL, BL Adding the values of AL, BL registers2018 12 E7 ADC AH, BH Add with Carry the values of AH, BH registers201A 72 0B JC 2027 Jump to 2027 if carry is generated201C B1 00 MOV CL, 00 Loading 00 to CL register201E 88 25 MOV [DI], AH Storing the Sum (2nd8-bit) in location 50012020 47 INC DI Incrementing the Destination Index2021 88 05 MOV [DI], AL Storing the Sum (1st8-bit) in location 50012023 47 INC DI Incrementing the Destination Index2024 88 0D MOV [DI], CL Storing the Carry in location 50022026 CC INT 03 End of the Program2027 B1 01 MOV CL, 01 Loading 01 to CL register2029 EB F3 JMP 201E Unconditional Jump to 201E
  • 3. OUTPUT:Location Value4000 D44002 C85000 95001 C5002 1QUESTION 3:Write a program to add 2 sixteen bit numbers using 16 – bit addition and store the sumand carry.ALGORITHM: Initialize the Data Segment. Store 2 sixteen bit numbers in locations 4000 – 4003. Read the first number in AX register and the second number in BX register. Add the 2 values using 16 – bit addition. Store the sum in location 5000 and 5001. If carry is produced, then store 01 in location 5002, else store 00 in that location.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 03 C3 ADD AX, BX Adding & Storing the result in AX register2013 72 09 JC 201E Jump to 201E if carry is generated2015 B1 00 MOV CL, 00 Loading 00 to CL register2017 89 05 MOV [DI], AX Storing the Sum in location 50002019 47 INC DI Incrementing the Destination Index201A 47 INC DI Incrementing the Destination Index201B 88 0D MOV [DI], CL Storing the Carry in location 5002201D CC INT 03 End of the Program201E B1 01 MOV CL, 01 Loading 01 to CL register2020 EB F5 JMP 2017 Unconditional Jump to 2017
  • 4. OUTPUT:Location Value4000 D24002 2D5000 FF5002 00QUESTION 4:Write a program to subtract 2, 16 bit numbers using 8 – bit SUB and store the diff. andborrow.ALGORITHM: Initialize the Data Segment. Store 2 sixteen bit numbers in locations 4000 – 4003. Read the first number in AX register and the second number in BX register. Add the 2 values using 8 – bit subtraction. (Hint: use SBB instruction) Store the difference in location 5000 and 5001. If borrow is generated, then store 01 in location 5002, else store 00 in that location.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 (1st8-bit) to AL register200D 46 INC SI Incrementing the Source Index200E 8A 1C MOV BL, [SI] Getting the 2ndvalue (1st8-bit) to BL register2010 46 INC SI Incrementing the Source Index2011 8A 24 MOV AH, [SI] Getting the 1stvalue (2nd8-bit) to AH register2013 46 INC SI Incrementing the Source Index2014 8A 3C MOV BH, [SI] Getting the 2ndvalue (2nd8-bit) to BH register2016 2A C3 SUB AL, BL Subtracting the values of AL, BL registers2018 1A E7 SBB AH, BH Subtract with Borrow the values of AH, BH201A 72 0B JC 2027 Jump to 2027 if carry is generated201C B1 00 MOV CL, 00 Loading 00 to CL register201E 88 25 MOV [DI], AH Storing the Diff (2nd8-bit) in location 50012020 47 INC DI Incrementing the Destination Index2021 88 05 MOV [DI], AL Storing the Diff (1st8-bit) in location 50012023 47 INC DI Incrementing the Destination Index2024 88 0D MOV [DI], CL Storing the Borrow in location 50022026 CC INT 03 End of the Program2027 B1 01 MOV CL, 01 Loading 01 to CL register
  • 5. 2029 EB F3 JMP 201E Unconditional Jump to 201EOUTPUT:Location Value4000 844002 425000 45001 25002 0QUESTION 5:Write a program to subtract 2 sixteen bit numbers using 16 – bit subtraction and store thedifference and borrow.ALGORITHM: Initialize the Data Segment. Store 2 sixteen bit numbers in locations 4000 – 4003. Read the first number in AX register and the second number in BX register. Subtract the 2 values using 16 – bit subtraction. Store the difference in location 5000 and 5001. If borrow is generated, then store 01 in location 5002, else store 00 in that location.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 2A C3 SUB AX, BX Subtracting & Storing the result in AX register2013 72 09 JC 201E Jump to 201E if carry is generated2015 B1 00 MOV CL, 00 Loading 00 to CL register2017 89 05 MOV [DI], AX Storing the Sum in location 50002019 47 INC DI Incrementing the Destination Index201A 47 INC DI Incrementing the Destination Index201B 88 0D MOV [DI], CL Storing the Carry in location 5002201D CC INT 03 End of the Program201E B1 01 MOV CL, 01 Loading 01 to CL register2020 EB F5 JMP 2017 Unconditional Jump to 2017
  • 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.
  • 10. 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 8A E8 MOV CH, AL Moving the value of AL register to CH200F 46 INC SI Incrementing the Source Index2010 8A 1C MOV BL, [SI] Getting the 2ndvalue to AL register2012 8A D3 MOV DL, BL Moving the value of BL register to DL2014 B4 00 MOV AH, 00 Loading 00 to AH register2016 F6 F3 DIV BL Dividing value of AX register by BL2018 8A C3 MOV AL, BL Moving the value of BL register to AL201A 8A DC MOV BL, AH Moving the value of AH register to BL201C 80 FC 00 CMP AH, 00 Comparing the value of AH register with 00201F 75 F3 JNE 2014 Jump if not zero to LABEL 12021 8A C8 MOV CL, AL Moving the value of AL register to CL2023 8A C5 MOV AL, CH Moving the value of CH register to AL2025 F6 E2 MUL DL Multiplying Value of DL with AL register2027 F6 F1 DIV CL Multiplying Value of CL with AL register2029 88 05 MOV [DI], AL Moving the value of AL to 5000202B CC INT 03 End of the ProgramOUTPUT:Location Value4000 034001 055000 0FQUESTION 5:Write an ALP IN 8086 to multiply 3 numbers and store the result.ALGORITHM: Initialize the Data Segment. Store 16-bit numbers in locations 4000 - 4005. Read the first number in AX register and the second number in BX register. Multiply them. Store Product and Carry in BX and CX registers respectively. Multiply and Add the respective positions with the third number Store the Product 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.
  • 17. PROGRAM:Addr. Opcode Operand Mnemonic Comment2000 B2 03 MOV DL, 02 Loading the value 02 to DL register2002 BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2005 BF 04 40 MOV DI, 4004 Loading location 4004 to Destination Index2008 E8 F5 0F CALL 3000 Calling the statements from location 3000200B 72 01 JB 200E Jump if borrow is generated to 200E200D BE 00 40 MOV SI, 4000 Loading location 4000 to Source Index2010 BF 04 40 MOV DI, 4004 Loading location 4004 to Destination Index2013 E8 EA 10 CALL 3100 Calling the statements from location 31002016 BE 04 40 MOV SI, 4004 Loading location 4004 to Source Index2019 BF 08 40 MOV DI, 4008 Loading location 4008 to Destination Index201C E8 E1 0F CALL 3000 Calling the statements from location 3000201F 72 09 JB 202A Jump if borrow is generated to 202A2021 BE 04 40 MOV SI, 4004 Loading location 4004 to Source Index2024 BF 08 40 MOV DI, 4008 Loading location 4008 to Destination Index2027 E8 D6 10 CALL 3100 Calling the statements from location 3100202A 80 FA 00 CMP DL, 00 Comparing the value of DL reg. with 00202D FE CA DEC DL Decrementing the value of DL register202F 74 02 JE 2033 Jump if zero to 20332031 EB CF JMP 2002 Unconditional Jump to 20022033 CC INT 03 End of Program3000 B9 04 00 MOV CX, 0004 Loading the value 0004 to CX register3003 A6 CMP SB Comparing String Bytes3004 75 FA JNE 3000 Jump if not zero to 30003006 E2 FB LOOP 3003 Looping the statements from 30033008 C3 RET Returning back to the main program3100 B9 04 00 MOV CX, 0004 Loading the value 0004 to CX register3103 8A 04 MOV AL, [SI] Moving the value of Source Index to AL reg.3105 8A 1D MOV BL, [DI] Moving the value of Dest. Index to BL reg.3107 86 C3 XCHG AL, BL Exchanging the values of AL, BL registers3109 88 04 MOV [SI], AL Moving the value of AL reg. to Source Index310B 88 1D MOV [DI], BL Moving the value of BL reg. to Dest. Index310D 46 INC SI Incrementing Source Index310E 47 INC DI Incrementing Destination Index310F E2 F2 LOOP 3103 Looping statements from 31033111 C3 RET Returning back to the main programOUTPUT:Location Val. (before) αβs Location Val. (after) αβs4000 44 D 4000 44 D4001 4F O 4001 45 E
  • 18. 4002 4E N 4002 56 V4003 44 D 4003 41 A4004 47 G 4004 44 D4005 49 I 4005 4F O4006 4C L 4006 4E N4007 4D M 4007 44 D4008 44 D 4008 47 G4009 45 E 4009 49 I400A 56 V 400A 4C L400B 41 A 400B 4D MLAB 4: OPERATIONS IN 8086QUESTION 1:Write an ALP IN 8086 for verifying all the Logic Operations.ALGORITHM: Initialize the Data Segment. Store two 16-bit numbers in location 4000 – 4003. Read the first number in AX register and the second number in BX register. Knowing the basic gates to be NOT, AND, OR and XOR, we can simply NOT theprevious 2 to get NAND, NOR and XNOR gates.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 B9 03 00 MOV CX, 0003 Loading the value 0003 to CX register200E 8B 04 MOV AX, [SI] Getting the 1stvalue to AX register2010 46 INC SI Incrementing the Source Index2011 46 INC SI Incrementing the Source Index
  • 19. 2012 8B 1C MOV BX, [SI] Getting the 2ndvalue to BX register2014 50 PUSH AX Pushing the value of AX register2015 E2 FD LOOP 2014 Looping the statements from 20142017 23 C3 AND AX, BX AND operation on AX, BX registers2019 89 05 MOV [DI], AX Moving the value of AX to Destination Index201B 47 INC DI Incrementing the Destination Index201C 47 INC DI Incrementing the Destination Index201D F7 D0 NOT AX NOT operation on AX register201F 89 05 MOV [DI], AX Moving the value of AX to Destination Index2021 47 INC DI Incrementing the Destination Index2022 47 INC DI Incrementing the Destination Index2023 58 POP AX Popping the value of AX register2024 0B C3 OR AX, BX OR operation on AX, BX registers2026 89 05 MOV [DI], AX Moving the value of AX to Destination Index2028 47 INC DI Incrementing the Destination Index2029 47 INC DI Incrementing the Destination Index202A F7 D0 NOT AX NOT operation on AX register202C 89 05 MOV [DI], AX Moving the value of AX to Destination Index202E 47 INC DI Incrementing the Destination Index202F 47 INC DI Incrementing the Destination Index2030 58 POP AX Popping the value of AX register2031 33 C3 XOR AX, BX XOR operation on AX, BX registers2033 89 05 MOV [DI], AX Moving the value of AX to Destination Index2035 47 INC DI Incrementing the Destination Index2036 47 INC DI Incrementing the Destination Index2037 F7 D0 NOT AX NOT operation on AX register2039 89 05 MOV [DI], AX Moving the value of AX to Destination Index203B 47 INC DI Incrementing the Destination Index203C 47 INC DI Incrementing the Destination Index203D 58 POP AX Popping the value of AX register203E F7 D0 NOT AX NOT operation on AX register2040 89 05 MOV [DI], AX Moving the value of AX to Destination Index2042 CC INT 03 End of the ProgramOUTPUT:Location Value4000 F00F4002 0FF05000 00005002 FFFF5004 FFFF5006 00005008 FFFF500A 0000
  • 20. 500C 0FF0QUESTION 2:Write an ALP IN 8086 for verifying all the Shift and Rotate operations.ALGORITHM: Initialize the Data Segment. Store the 16-bit number in location 4000. Read the number in AX register.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 B9 06 00 MOV CX, 0006 Loading the value 0006 to CX register2010 50 PUSH AX Pushing the value of AX register2011 E2 FD LOOP 2010 Loop statements from 20102013 D1 C8 ROR AX, 1 Rotate AX right by 12015 89 05 MOV [DI], AX Moving the value of AX to Destination Index2017 47 INC DI Incrementing the Destination Index2018 47 INC DI Incrementing the Destination Index2019 58 POP AX Popping the value of AX register201A D1 C0 ROL AX, 1 Rotate AX left by 1201C 89 05 MOV [DI], AX Moving the value of AX to Destination Index201E 47 INC DI Incrementing the Destination Index201F 47 INC DI Incrementing the Destination Index2020 58 POP AX Popping the value of AX register2021 D1 D8 RCR AX, 1 Rotate (CF before MSB) AX right by 12023 89 05 MOV [DI], AX Moving the value of AX to Destination Index2025 47 INC DI Incrementing the Destination Index2026 47 INC DI Incrementing the Destination Index2027 58 POP AX Popping the value of AX register2028 D1 D0 RCL AX, 1 Rotate (CF after LSB) AX left by 1202A 89 05 MOV [DI], AX Moving the value of AX to Destination Index202C 47 INC DI Incrementing the Destination Index202D 47 INC DI Incrementing the Destination Index202E 58 POP AX Popping the value of AX register202F D1 F8 SAR AX, 1 Shift AX right by 1 (with new MSB = old MSB)2031 89 05 MOV [DI], AX Moving the value of AX to Destination Index2033 47 INC DI Incrementing the Destination Index2034 47 INC DI Incrementing the Destination Index
  • 21. 2035 58 POP AX Popping the value of AX register2036 D1 E0 SHL AX, 1 Shift AX left by 1 (with new LSB = 0)2038 89 05 MOV [DI], AX Moving the value of AX to Destination Index203A 47 INC DI Incrementing the Destination Index203B 47 INC DI Incrementing the Destination Index203C 58 POP AX Popping the value of AX register203D D1 E8 SHR AX, 1 Shift AX right by 1 (with new MSB = 0)203F 89 05 MOV [DI], AX Moving the value of AX to Destination Index2041 CC INT 03 End of the ProgramOUTPUT:Location Value4000 00075000 80035002 000E5004 80035006 000E5008 0007500A 000E500C 8003QUESTION 3:Write an ALP IN 8086 for generating the Fibonacci sequence.ALGORITHM: Initialize the Data Segment. Store the values of 1st2 terms of the Fibonacci sequence in locations 4000 & 4002respectively. Perform a recursive exchange and add operation to obtain the successive terms ofthe Fibonacci sequence. As the subsequent terms are obtained store them.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 registers2009 8E D8 MOV DS, AX Initializing Data Segment using AX register200B B9 00 00 MOV AL,00 Getting the 1stvalue to AX register200E 8A 0C MOV CL, [SI] Loading the no. of terms to CL register2010 88 05 MOV [DI], AL Moving the value of AL to Destination Index2012 47 INC DI Incrementing the Destination Index2013 B4 01 MOV AH, 01 Loading the value 01 to AH register
  • 22. 2015 02 E0 ADD AH, AL Adding the values of AH, AL registers2017 88 25 MOV [DI], AH Moving the value of AH to Destination Index2019 47 INC DI Incrementing the Destination Index201A 86 C4 XCHG AL, AH Exchanging the values of AL, AH registers201C E2 F7 LOOP 2015 Loop statements from 2015201E CC INT 03 End of the ProgramOUTPUT:Location Value4000 055000 005001 015002 015003 025004 035005 055006 08QUESTION 4:Write an ALP IN 8086 for computing nPr and nCr.ALGORITHM: Initialize the Data Segment. Store the values of ‘n’ and ‘r in locations 4000 & 4002’respectively. Do the following calculations in chronological order:o n!o (n – r)o (n – r)!o [n!/(n – r)!] = nPro r!o [nPr/ r!] = nCr As nPr and nCr are obtained store them.PROGRAM:
  • 23. 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 value of ‘n’ to AX register200D 46 INC SI Incrementing the Source Index200E 46 INC SI Incrementing the Source Index200F 8B 1C MOV BX, [SI] Getting the value of ‘r’ to BX register2011 50 PUSH AX Pushing the value of AX to stack memory2012 8B C8 MOV CX, AX Moving the value of AX register to CX2014 B8 01 00 MOV AX, 0001 Loading the value 0001 to AX register2017 F7 E1 MUL CX Multiply CX register with AX2019 E2 FC LOOP 2017 Loop statements from 2017201B 8B D0 MOV DX, AX Moving the value of AX register to DX201D 58 POP AX Popping the value of AX from stack memory201E 92 XCHG AX, DX Exchanging the values of AX, DX registers201F 2B D3 SUB DX, BX Subtracting the value of BX from DX register2021 8B CA MOV CX, DX Moving the value of DX register to CX2023 8B D0 MOV DX, AX Moving the value of AX register to DX2025 B8 01 00 MOV AX, 0001 Loading the value 0001 to AX register2028 52 PUSH DX Pushing the value of DX to stack memory2029 F7 E1 MUL CX Multiply CX register with AX202B E2 FC LOOP 2029 Loop statements from 2029202D 5A POP DX Popping the value of DX from stack memory202E 92 XCHG AX, DX Exchanging the values of AX, DX registers202F F6 F2 DIV DL Divide value of AX register by DL2031 89 05 MOV [DI], AX Moving the value of AX to Destination Index2033 91 XCHG AX, CX Exchanging the values of AX, CX registers2034 87 D9 XCHG BX, CX Exchanging the values of BX, CX registers2036 B8 01 00 MOV AX, 0001 Loading the value 0001 to AX register2039 F7 E1 MUL CX Multiply CX register with AX203B E2 FC LOOP 2039 Loop statements from 2039203D 93 XCHG AX, BX Exchanging the values of AX, BX registers203E F6 F3 DIV BL Divide value of AX register by BL2040 47 INC DI Incrementing the Destination Index2041 47 INC DI Incrementing the Destination Index2042 89 05 MOV [DI], AX Moving the value of AX to Destination Index2044 CC INT 03 End of the ProgramOUTPUT:Location Value4000 00054002 0002
  • 24. 5000 00145002 000A

×