Uploaded by Manas Ameria

EXP 1-8 MICROPROCESSOR LAB 20BCE1476

advertisement
20BCE1476
Manas N Ameria
AIM:
Perform the basic arithematic operations (ADD, SUB, MUL, DIV) on 8-bit and 16-bit
numbers using IMMEDIATE and DIRECT addressing.
TOOLS USED:
Assembler- MASM 611
ALGORITHM:
Step 1- Assigning values num1 and num2 to specific registers (AX and BX).
Step 2- Adding the values in the registers and store the sum in AX register (AX = AX+BX).
Step 3- Re-assign the values of the registers (AX and BX).
Step 4- Subtracting the values in the registers and store the difference in AX register (AX =
AX-BX).
Step 5- Re-assign the values of the registers (AX and BX).
Step 6- Multiply the values in register and store the product in AX (AX = AX*BX).
Step 7- Re-assign the values of the registers (AX and BX).
Step 8- Divide the values in registers and store quotient in AX register and the remainder in
DX register (AX = AX/BX → Only quotient, DX → Remainder).
ADDITION OF TWO 8-BIT NUMBERS USING IMMEDIATE ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 20H
Input num2: 05H
SAMPLE OUTPUT:
Sum: 25H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
ADDITION OF TWO 16-BIT NUMBERS USING IMMEDIATE ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 2005H
Input num2: 2002H
SAMPLE OUTPUT:
Sum: 4007H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
ADDITION OF TWO 8-BIT NUMBERS USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 20H
Input num2: 05H
SAMPLE OUTPUT:
Sum: 25 H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
ADDITION OF TWO 16-BIT NUMBERS USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 2005H
Input num2: 2002H
SAMPLE OUTPUT:
Sum: 4007 H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
SUBSTRACTION OF TWO 8-BIT NUMBERS USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 20H
Input num2: 05H
SAMPLE OUTPUT:
Difference: 1B H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
SUBSTRACTION OF TWO 16-BIT NUMBERS USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 2005H
Input num2: 2002H
SAMPLE OUTPUT:
Difference: 03 H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
MULTIPLICATION OF TWO 8-BIT NUMBERS USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 20H
Input num2: 05H
SAMPLE OUTPUT:
Product: A0 H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
DIVISION OF 16-BIT NUMBER AND 8-BIT NUMBER USING DIRECT ADDRESSING:
PROGRAM:
SAMPLE INPUT:
Input num1: 520H
Input num2: 25H
SAMPLE OUTPUT:
Quotient: 23 H
Remainder: 11 H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Therefore, arithematic operations (ADD, SUB, MUL, DIV) with 8 bit and 16 bit numbers
tested and verified using DOSBOX assembly language MASM611 using both DIRECT and
IMMEDIATE addressing.
20BCE1476
Manas N Ameria
AIM:
Using MASM 611 assembly language, find and store Sum and Average of a set of numbers
stored in an array.
TOOLS USED:
Assembler- MASM 611
FINDING SUM AND AVERAGE OF A SET OF FIVE 16-BIT NUMBERS:
ALGORITHM:
Step 1- Assign the 16-bit values in the array (ARRAY).
Step 2- Initialize SUM and AVG storage spaces.
Step 3- Initialize count and base register (CX and BL) as 05H.
Step 4- Loop through the array using the source index (SI), counting down CX on every
iteration and keep adding every element.
Step 5- Store SUM in every iteration to AX and then finally putting in memory space.
Step 6- Take SUM from AX and divide by BL (05H) to get average stored in AX and then
move value in AX to AVG storage space initialized earlier.
PROGRAM:
SAMPLE INPUT:
NUM1→0091H
NUM2→0095H
NUM3→0094H
NUM4→0093H
NUM5→0095H
SAMPLE OUTPUT:
SUM→E2
AVERAGE→93
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
FINDING THE SUM AND AVERAGE OF TEN, 16-BIT NUMBERS CREATED FROM FIVE 8-BIT
NUMBERS WHEN MULTIPLIED WITH 02H (5 ELEMENTS) AND 0AH (5 ELEMENTS):
ALGORITHM:
Step 1- Assign the 8-bit values in the main array (ARRAY1) and initialize a 2nd array for
calculation of the coming 10 elements (ARRAY2).
Step 2- Initialize SUM and AVG storage spaces.
Step 3- Initialize code register as 05H (CX), base register as 0002H (BX), source index as
offset of ARRAY1 (SI) and data index as offset of ARRAY2 (DI).
Step 4- Loop through the main array (ARRAY1) using the source index (SI), 2nd array
(ARRAY2) using data index (DI) counting down CX and incrementing SI and DI on every
iteration. Keep multiplying every element in ARRAY1 with BX, store them in ARRAY2.
Step 5- Loop through the array (Array1) after resetting SI as offset of ARRAY1, CX as 05H
again and BX as 000AH this time. Keep multiplying the elements in ARRAY1 and store the
values in ARRAY2 combined with previous values.
Step 6- Reset DX as offset of ARRAY2 and CX as 0AH this time to loop through ARRAY2 to
find SUM of all the elements in it.
Step 7- Store SUM in every iteration to AX and then finally putting in memory space.
Step 8- Take SUM from AX and divide by BX (000AH) to get average stored in AX and then
move value in AX to AVG storage space initialized earlier.
PROGRAM:
SAMPLE INPUT:
NUM1→91H*02H
NUM2→95H*02H
NUM3→94H*02H
NUM4→93H*02H
NUM5→95H*02H
NUM6→91H*0AH
NUM7→95H*0AH
NUM8→94H*0AH
NUM9→93H*0AH
NUM10→95H*0AH
SAMPLE OUTPUT:
SUM→2298
AVERAGE→375
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENTS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Therefore, Sum and Average of numbers calculated and verified using DOSBOX MASM611
assembler language.
20BCE1476
MANAS N AMERIA
AIM:
Using MASM 611 assembly language, to sort an array in ascending and descending order
and then finding the largest and the smallest numbers in the array.
TOOLS USED:
Assembler- MASM 611
ALGORITHM:
Step 1- Assign 15, 8-bit values in the array (ARRAY).
Step 2- Initialize COUNT as 15 and the data register (DX) as COUNT-1 for looping.
Step 3- Initialize label (LABL1) which resets CX as DX and also the stack index (SI) as offset
of the array, basically pointing at start of array. LABL1 also prints the first and the last
positions of the array (ARRAY) after every iteration in AX.
Step 4- Initialize label (LABL2) for comparing and accordingly swapping elements pointing
at [SI] and [SI+01].
Step 5.1(ASCENDING)- If element at [SI]<element at [SI+01], then no need of
swapping. If element at [SI]>element at [SI+01], then jump statement to carry (JC
LABL1) and swap the elements.
Step 5.2(DESCENDING)- If element at [SI]>element at [SI+01], then no need of
swapping. If element at [SI]<element at [SI+01], then jump statement when no carry
(JNC LABL1) and swap the elements.
Step 6- Label LABL3 increments SI and loops label LABL2 for traversing through the
array and swapping whenever needed.
Step 7- Finally the array (ARRAY) values are changed in sorted order after looping
through the array 14 times (COUNT-1) and now LABL1 will be called one last time so
that it can print the first and the last positions in the array, that will be the smallest
and the largest numbers in the array in AX (FOR ASCENDING: Smallest number – AL,
Largest number – AH and FOR DESCENDING: Smallest number – AH, Largest number AL).
SORTING THE ARRAY OF 15 ELEMENTS IN ASCENDING ORDER:
PROGRAM:
SAMPLE INPUT:
ARRAY = {22H, 44H, 45H, 01H, 49H, 54H, 45H, 94H, 10H, 54H, 44H, 22H, 04H, 07H, 06H}
SAMPLE OUTPUT:
ARRAY = {01H, 04H, 06H, 07H, 10H, 22H, 22H, 44H, 44H, 45H, 45H, 49H, 54H, 54H, 94H}
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
SORTING THE ARRAY OF 15 ELEMENTS IN DESCENDING ORDER:
PROGRAM:
SAMPLE INPUT:
ARRAY = {22H, 44H, 45H, 01H, 49H, 54H, 45H, 94H, 10H, 54H, 44H, 22H, 04H, 07H, 06H}
SAMPLE OUTPUT:
ARRAY = {94H, 54H, 54H, 49H, 45H, 45H, 44H, 44H, 22H, 22H, 10H, 07H, 06H, 04H, 01H}
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
FINDING LARGEST AND SMALLEST NUMBER FROM AN ARRAY:
PROGRAM:
SAMPLE INPUT:
ARRAY = {22H, 44H, 45H, 01H, 49H, 54H, 45H, 94H, 10H, 54H, 44H, 22H, 04H, 07H, 06H}
SAMPLE OUTPUT:
AX = 9401 (94 – largest number, 01 – smallest number)
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Therefore, sorting an array of 15 8-bit numbers in ascending order, descending order and
finding the largest and the smallest number in that array verified using MASM611
assembler language.
MANAS N AMERIA
20BCE1476
04/02/2022
EXP. 4: 8086 ASM programs on finding factorial, nPr and nCr
AIM:
Using MASM 611 assembly language, to find factorial of a number, nPr (Permutations) and
nCr (Combinations).
TOOLS USED:
Assembler- MASM 611
FINDING FACTORIAL OF A NUMBER:
ALGORITHM:
Step 1- Assign a variable to store 01 (in our case AX register) and the number we want to find
the factorial of in another variable (in our case CX register).
Step 2- Create a loop of the number whos factorial we need to calculate and keep
multiplying to the 01 we stored in the variable after every iteration.
Step 3- Decrement the value of CX register after every loop till CX reaches 01H.
Step 4- After the whole loop is complete the result should be displayed (in AX register).
Step 5- Therefore, the result displayed will be the factorial of the number (N!).
PROGRAM:
SAMPLE INPUT AND OUTPUT:
Sno.
INPUT (n)
OUTPUT(n!)
1
8 = 08H
40320 = 9D80H
2
4 = 04H
24 = 18H
3
5 = 05H
120 = 78H
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
FINDING PERMUTATIONS (nPr):
ALGORITHM:
Step 1- Assign the values of the 2 numbers n and r for the calculation of nPr and also assign
variables TEMP and NPR for the storage of temporary results and final result respectively.
Step 2- Calculate and store n-r in another variable (in our case using temporary storage of
BX register), for calculation of (n-r)! and check if n-r is equal to 1 to avoid unnecessary
calculations, if it is equal to 1 then TEMP = 1, otherwise go to Step 3 to calculate factorial
of n-r.
Step 3- Make a function (label) named LABL1 which calculates the factorial of any number
provided to it and calculate the factorial of the number stored in BX register by calling the
function (label) and store in TEMP.
Step 4- Now re-assign BX register to store n value and find the factorial of it by calling the
function (LABL1), store the result in another variable (in our case using temporary storage
of AX register).
Step 5- Again re-assign BX to contain value in TEMP variable and divide the value in AX
with BX to get the result in AX.
Step 6- The result we obtain is nPr calculation that should now be stored in NPR
memory location.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
Sno.
INPUT (n, r)
OUTPUT(nPr)
1
5 = 05H, 3 = 03H
5P = 60 = 3CH
3
2
7 = 07H, 6 = 06H
7P = 5040 = 13B0H
6
3
8 = 08H, 4 = 04H
8P = 1680 = 690H
4
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
FINDING COMBINATIONS (nCr):
ALGORITHM:
Step 1- Assign the values of the 2 numbers n and r for the calculation of nCr and also assign
variables TEMP, TEMP1 and NCR for the storage of temporary results and final result
respectively.
Step 2- Calculate and store n-r in another variable (in our case using temporary storage of
BX register), for calculation of (n-r)! and check if n-r is equal to 1 to avoid unnecessary
calculations, if it is equal to 1 then TEMP = 1, otherwise go to Step 3 to calculate factorial
of n-r.
Step 3- Make a function (label) named LABL1 which calculates the factorial of any number
provided to it and calculate the factorial of the number stored in BX register by calling the
function (label) and store in TEMP.
Step 4- Now re-assign BX register to store r value and find the factorial of it by calling the
function (LABL1), store the result in another variable (in our case using temporary storage
of AX register).
Step 5- Again re-assign BX to contain value in TEMP variable and multiply the value in
AX with BX to get the result in AX (r! * (n-r)!), store this result in the variable we
created earlier TEMP1.
Step 6- Again re-assign BX register to store n value and calculate its factorial by calling
the function (LABL1) and store in AX temporarily.
Step 7- Now, re-assign BX value to the result in TEMP1 and divide AX by BX to get the
result (nCr). Store the result in NCR memory location created earlier.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
Sno.
INPUT (n, r)
OUTPUT(nPr)
1
5 = 05H, 4 = 04H
5C = 5 = 05H
4
2
8 = 08H, 4 = 04H
8C = 70 = 46H
4
3
7 = 07H, 6 = 06H
7C = 7 = 07H
6
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Calculation of factorial of a number, nCr combination and nPr permutation of a set of
numbers, verified using DOSBOX MASM611 assembly language.
20BCE1476
MANAS N AMERIA
AIM:
Using MASM 611 assembly language, for number system conversions (BCD to ASCII, ASCII to
BCD, ASCII to Binary, Binary to ASCII).
TOOLS USED:
Assembler- MASM 611
BCD TO ASCII CONVERSION:
ALGORITHM:
Step 1- Initialize memory space with BCD number (NUM1) which is to be converted into its
corresponding ASCII value and free memory locations RES1 and RES2 for results.
Step 2- Moving NUM1 value into AX register and 10H to BL register to divide AX by 10, for
separating the units and the tens digit from the number.
Step 3- After separation of the units and the tens digit they are stored in the AH and the AL
register, add 3030H to AX and store in AX.
Step 4- Now, AH and AL together store the result that transfers to 2 different memory
spaces RES1 and RES2 respectively.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
INPUT
0111 0111
0101 0011
1000 1001
MANUAL VERIFICATION:
OUTPUT
3737
3533
3839
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
ASCII TO BCD CONVERSION:
ALGORITHM:
Step 1- Initialize memory space with the number (NUM1) that has to be converted into its
corresponding BCD value and free memory location RES for storing result.
Step 2- Move NUM1 value into AX and do masking on AL part to separate the two 8 bit parts
and initialize count register (CL) as 04H.
Step 3- Apply Shift left on AL for a count of 04H (CL) and carry out OR operation on AH and AL
values which will give the result.
Step 4- Now, store the result in AH into RES memory space.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
INPUT
3934
3532
3638
MANUAL VERIFICATION:
OUTPUT
94
52
68
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
BINARY TO ASCII CONVERSION:
ALGORITHM:
Step 1- Initialize memory space with 8 bit (binary) a number (NUM1) and a free memory
space RES for storing the final result.
Step 2- Move NUM1 value into AL register and compare it with 0AH.
Step 3.1- If carry flag doesn’t set that means NUM1 is greater than or equal to 0AH and JC
instruction jumps to the Label MANAS directly.
Step 3.2- Else it means that NUM1 is less than 0AH and JC instruction is skipped and
followed by adding 07H to AL value at moment.
Step 4- Label MANAS adds 30H into AL and stores final result which is then stored in RES
through MOV instruction.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
INPUT
A
C
F
OUTPUT
41
43
46
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
ASCII TO BINARY CONVERSION:
ALGORITHM:
Step 1- Initialize memory space with 8 bit number (NUM1) and a free memory space RES for
storing the final result.
Step 2- Move NUM1 value into AL register and subtract 30H from it.
Step 3- Now, compare the value in AL with 11H.
Step 4.1- If carry flag doesn’t set that means value in AL is greater than 11H and JC
instruction jumps to the Label L1 directly.
Step 4.2- Else it means that the value in AL is less than or equal to 11H and JC instruction is
skipped and followed by subtracting 07H to AL value at moment.
Step 5- Label L1 stores final result which is then stored in RES through MOV instruction.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
INPUT
39
42
45
OUTPUT
09
0B
0E
MANUAL VERIFICATION:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Verification of code conversion (ASCII to BCD, BCD to ASCII, ASCII to BINARY, BINARY to
ASCII), successfully executed using MASM 611 Assembly language and Manual verification.
20BCE1476
MANAS N AMERIA
AIM:
Using MASM 611 assembly language, for finding a character in a string and replacing a
character in a string using string instructions.
TOOLS USED:
Assembler- MASM 611
FINDING A CHARACTER IN A STRING:
ALGORITHM:
Step 1- Assigning a free memory space in DATA segment(RES) for result to be stored when
the required character is found from the EXTRA segment.
Step 2- EXTRA segment contains the string in which the character is to be searched for.
Step 3- Now, in the CODE segment, first assign the index registers (SI and DI) with their
respective offset addresses and also assign the AL register with the character that is to be
found in the string.
Step 4- Clear the direction flag (CLD instruction) as we need a clear value of the
comparisons we are going to be making and count register should be given the value of
the number of characters in the given string, so that it can loop and compare the value
required in the string till it traverses through all the characters.
Step 5- This compare function stated above is carried out by REPNE SCASB (Repeat till Not
Equal and scanning the string for character). This instruction scans the string and compares
character by character till the characters are equal (the character to be searched is found),
hence, it repeats till the characters are not equal.
Step 6- As soon as the instruction finds the characters to be equal (character found), it
comes out of the loop, decrements the DI register by 1 and then prints the found character
from the EXTRA segment in the DATA segment under the RES memory space.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
Element to find
02H
09H
03H
EXTRA SEGMENT (INPUT)
04H, 02H, 09H, 03H, 01H
04H, 02H, 09H, 03H, 01H
04H, 02H, 09H, 03H, 01H
REGISTER AND MEMORY CONTENS FOR I/O:
DATA SEGMENT (OUTPUT)
02H
09H
03H
SNAPSHOT OF OUTPUT:
FINDING AND REPLACING A CHARACTER IN A STRING:
ALGORITHM:
Step 1- Assigning a free memory space in DATA segment(RES) for result to be stored when
the required character is found from the EXTRA segment.
Step 2- EXTRA segment contains the string in which the character is to be searched for.
Step 3- Now, in the CODE segment, first assign the character that should be replaced with a
particular character in the string in the BH register, then assign index registers (SI and DI) with
their respective offset addresses and also assign the AL register with the character that is to
be found in the string.
Step 4- Clear the direction flag (CLD instruction) as we need a clear value of the
comparisons we are going to be making and count register should be given the value of
the number of characters in the given string, so that it can loop and compare the value
required in the string till it traverses through all the characters.
Step 5- This compare function stated above is carried out by REPNE SCASB (Repeat till Not
Equal and scanning the string for character). This instruction scans the string and compares
character by character till the characters are equal (the character to be searched is found),
hence, it repeats till the characters are not equal.
Step 6- As soon as the instruction finds the characters to be equal (character found), it
comes out of the loop, decrements the DI register by 1 and then prints the replacing value
which is already assigned to the BH register in the DATA segment under the RES memory
space in place of the character from the EXTRA segment.
PROGRAM:
SAMPLE INPUT AND OUTPUT:
Element to find and replace
04H
02H
03H
EXTRA SEGMENT BEFORE
REPLACEMENT (INPUT)
04H, 02H, 09H, 03H, 01H
04H, 02H, 09H, 03H, 01H
04H, 02H, 09H, 03H, 01H
REGISTER AND MEMORY CONTENS FOR I/O:
EXTRA SEGMENT AFTER
REPLACEMENT (OUTPUT)
AAH, 02H, 09H, 03H, 01H
04H, 30H, 09H, 03H, 01H
04H, 02H, 09H, 11H, 01H
SNAPSHOT OF OUTPUT:
RESULT:
Verified finding and replacing of a character in a string, using DOSBOX MASM611 Assembly
language using string instructions.
20BCE1476
MANAS N AMERIA
AIM:
Using MASM 611 assembly language, for DOS and BIOS interrupts programming.
TOOLS USED:
Assembler- MASM 611
REVERSE OF A STRING (EXP 6 CHALLENGE PROBLEM):
ALGORITHM:
Step 1- Setting all string characters in the memory (NUM1 to NUM5) and free memory
spaces for storing reverse of this string (RES1 to RES5).
Step 2- Initialize the index registers as one more than the start address of the last element of
the original string (SI = 9505H) and the other as the start address of the last element of the
string (DI = 9504H). Set count register as 05H for 5 character string.
Step 3- Implement a label (LOOP1) that will perform reversing of the original string and print
it in the data segment under the free memory space.
Step 4- Loop the label by decrementing and incrementing the index registers (DI and SI).
PROGRAM:
SAMPLE INPUT:
01H, 03H, 25H, 07H, 22H
SAMPLE OUTPUT:
22H, 07H, 25H, 03H, 01H
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
GETTING A CHRACTER INPUT FROM THE KEYBOARD:
ALGORITHM:
Step 1- Putting AH as 01H, which reads the keyboard input through the DOS interrupt (INT
21H).
Step 2- End program.
PROGRAM:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
GETTING CHARACTERS TILL THE CHARACTER MATCHES THE LAST
CHARACTER OF YOUR NAME:
ALGORITHM:
Step 1- Initialize last letter of your name (STR) which will be compared with user keyboard
input.
Step 2- Make a Label (LOOP1) to compare the keyboard entered input.
Step 3- The keyboard input is read by the DOS interrupt instructions as shown in the
previous program.
Step 4- The label checks for the last letter of the name to be equal to the keyboard entered
input (CMP STR, AL) using the jump not equal instruction (JNE) which will keep on running
the loop till the input is equal to the last letter of name.
PROGRAM:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
STORING THE STRING OF CHARACTERS COLLECTED FROM KEYBOARD IN
DATA SEGMENT:
ALGORITHM:
Step 1- Initialize the free data spaces where the keyboard input will be stored later.
Step 2- Set index register as the offset address of the first free memory space or the string of
elements (SI) and count register as 04H for 4 inputs to be stored.
Step 3- Initializing the accumulator high and low as 01H for using DOS interrupt instruction
(INT 21H).
Step 4- Making a label (LOOP1) which will store the keyboard input in the data segment
free memory spaces.
Step 5- Keep on incrementing index register for looping till all the inputs are stored in the
data segment.
PROGRAM:
SAMPLE INPUT:
BUBS
SAMPLE OUTPUT:
MEMORY LOCATION – 42, 55, 42, 53
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
DISPLAY THE STORED STRING IN BLINKING FASHION AND YOUR FAVOURITE
COLOUR:
ALGORITHM:
Step 1- Initialize the string that is to be modified and printed on screen (STR).
Step 2- Assign AH as 09H for allowing the BIOS to modify the string and the DOS to perform
printing interrupt on screen after modification of the string.
Step 3- Set data register as offset of the string to perform the experiments on it.
Step 4- Assign count as length of the string so that the modification only applies on the
string.
Step 5- Finish program with the BIOS and the DOS interrupt instructions (INT 10H) (INT
21H) so that the code written above can perform the actions written.
PROGRAM:
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
CHALLENGING TASK:
ALGORITHM:
Step 1- Initialize the main string which has the string to be checked for palindrome (STR1).
Step 2- Set the index registers as the offset of the main string and the end address of the
main string (SI and DI).
Step 3- Initialize the count register with the number of iterations needed to compare the
halves of the string.
Step 4- To compare and check the 2 halves characters values, create label (LOOP1), which
also checks that the SI value should not be greater than DI value.
Step 5- The code jumps out if the SI value increments and becomes greater than the DI
value.
Step 6- The code also jumps out and ends if any of the string halves characters don’t
exactly match.
PROGRAM:
SAMPLE INPUT:
HIIH
SAMPLE OUTPUT:
THE STRING IS A PALINDROME
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Use and verification of the DOS and BIOS interrupt instructions performed successfully by
using MASM611 assembly language in DOSBOX.
20BCE1476
MANAS N AMERIA
AIM:
Using MASM 611 assembly language, for basic matrix operations.
TOOLS USED:
Assembler- MASM 611
TRANSPOSE MATRIX-1 TO DERIVE MATRIX-2:
ALGORITHM:
Step 1- Initiating the matrix M1 and M2 matrix free space for storing result.
Step 2- Setting count register as 03H for looping 3 times around each row of the matrix and
assigning the offset addresses of M1 and M2 to the index registers SI and DI respectively.
Step 3- Creating a label (LOOP2) and setting DL register as 03H for decrementing the offset
values after each iteration of this label.
Step 4- Creating another label inside the previous label (LOOP1) which will take the first
value of each M1 row and place it as the first value of the M2 matrix.
Step 5- The above label keep looping with SI and DI values and finally give the transpose of
the matrix M1.
PROGRAM:
SAMPLE INPUT:
22, 44, 45, 01, 49, 54, 20, 14, 76
SAMPLE OUTPUT:
22, 01, 20, 44, 49, 14, 45, 54, 76
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
ADD MATRIX-1 AND MATRIX-2 AND PRODUCE MATRIX-3 AS THE SUM:
ALGORITHM:
Step 1: Initialize M1 and M2 and then make M3 free space for result.
Step 2: Set SI as offset of MX1, DI as offset of MX2 and BX as offset of MX3
and count register as 09H.
Step 3: Add the values of MX1 and MX2 being pointed at by SI and DI.
Step 4: Store the result in the memory location being pointed at by BX.
Step 5: Label keeps looping with increment in SI and DI values.
PROGRAM:
SAMPLE INPUT:
M1 = 22, 44, 45, 01, 49, 54, 20, 14, 76
M2 = 22, 01, 20, 44, 49, 14, 45, 54, 76
SAMPLE OUTPUT:
M3 = 44, 45, 65, 45, 92, 68, 65, 68, EC
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
MULTIPLY MATRIX-1 WITH MATRIX-3 AND GENERATE MATRIX-4 AS
PRODUCT AND STORING RESULTS IN DATA SEGMENT AT AN OFFSET 2022H:
ALGORITHM:
Step 1: Initiate the matrix values that are to be multiplied.
Step 2: Also assign the matrix free memory space for the result to be stored.
Step 3: Set the values of the index registers and the base register as the offset addresses of
M1, M3 and M4 respectively.
Step 4: Creating a function (LOOP1) which will perform the matrix multiplication by
multiplying the characters from specific memory spaces in the M1 and M3 matrices and
then storing in the memory location of the M4 matrix.
Step 5: The above step can be looped by incrementing the index and base register’s values
till we complete 9 iterations. Finally giving us the multiplication result of the 2 matrices.
PROGRAM:
SAMPLE INPUT:
M1 = 22, 44, 45, 01, 49, 54, 20, 14, 76
M3 = 44, 45, 65, 45, 92, 68, 65, 68, EC
SAMPLE OUTPUT:
M4 = 0908, 1254, 1B39, 0045, 29A2, 2220, 0CA0, 0820, 6CC8
REGISTER AND MEMORY CONTENS FOR I/O:
SNAPSHOT OF OUTPUT:
RESULT:
Therefore, verified the matrix operations (TRANSPOSE, ADDITION and MULTIPLICATION)
using 8086 assembly language in DOSBOX MASM611 system.
Download