STRING MANIPULATION
AIM:
To write an assembly language program using 8086 to find the number of
Characters in a string, to move a byte from the source to destination and to store
the string primitive.
ALGORITHM (LENGTH OF THE STRING):
1. Start the program.
2. Enter the opcodes from 1000.
3. Enter the string starting from the location 1200.
4. After entering the last character in the string enter the hexa value FF.
5. Execute the program and check for result in 1100.
PROGRAM
ADDRESS | LABEL | OPCODE | MNEMONICS | OPERAND | COMMENTS |
1000 | | BE, 00,12 | MOV | SI, 1200 | Initializing the string and the string starts in SI |
1003 | | BA, FF, FF | MOV | DX, FFFF | Maximum location used for the entry of the string |
1006 | | B4, FF | MOV | AH, FF | Moving the final data of array and also indicates the end of the string |
1008 | LOOP | 42 | INC | DX | Incrementing the string length by 1 |
1009 | | 8A, 04 | MOV | AL, [SI] | Get the string character to AL |
100B | | 46 | INC | SI | Increment the address location to get the next string |
100C | | 38,C4 | CMP | AH, AL | Check for the end of the string |
100E | | 75,F8 | JNZ | LOOP | Checking for the zero value. |
1010 | | 89,16,00,11 | MOV | [1100], DX | Successful increment in the count else stores the string length. |
1014 | | F4 | HLT | | Stop the program |
ALGORITHM (STORE THE STRING PRIMITIVE):
1. Start the program.
2. Enter the program and execute it.
3. Check if locations 1100 to 11FF contain 34.
4. Stop the program.
PROGRAM:
ADDRESS | LABEL | OPCODE | MNEMONICS | OPERAND | COMMENTS |
1000 | | B9, 00,01 | MOV | CX, 0100 | Moving the total no of location in which the primitive must be stored |
1003 | | BF, 00,11 | MOV | DI, OFFSET S_ARRAY | Moving the starting location value to DI |
1006 | | B8, 34,00 | MOV | AX, 0034 | Moving the primitive value to AX |
1009 | | FC | CLD | | Clearing the data. |
100A | L | AA | STOSB | | Storing the string byte |
100B | | E2, FA | LOOP | L | Checking for the loop |
100D | | F4 | HLT | | Stop the program |
ALGORITHM (MOVE):
1. Start the program.
2. Enter the program from the location 1000.
3. Fill FF locations as stated above with a particular data, 41.
4. Execute the program.
5. Check if the contents are duplicated to another 255 locations using the compare command.
6. Stop the program.
PROGRAM:
ADDRESS | LABEL | OPCODE | MNEMONICS | OPERAND | COMMENTS |
1000 | | BE, 0E, 10 | MOV | SI, OFFSET S_ARAY | Moving the source location from which the data should be moved |
1003 | | BF, 0E, 11 | MOV | DI, OFFSET D_ARRAY | Moving the ending location to which the data should be moved. |
1006 | | B9, FF, 00 | MOV | CX, 00FF | Total count location within which the data can be moved |
1009 | | FC | CLD | | Clearing the data. |
100A | MOVE | A4 | MOVSB | | Moving the string byte. |
100B | | E2, FD | LOOP | MOVE | Continuous check of data |
100D | | F4 | HLT | | Stop the program |
RESULT:
Thus the string operations move, store string primitive and to find the length of
the string is executed and the results are verified.
0 comments:
Post a Comment