Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Experiment 6

Theory:

Instruction sets -

● MOV Moves data from R2R, R2M, etc


● LOOP Jump to the defined label until CX=0
● INC/DEC Increment/decrement content of register or memory by 1
● CMP Used to compare two provided byte/word
● JMP Used to jump to the provided address to proceed to the next instruction
● JZ Used to jump if zero flag ZF=1
● REP Used to repeat the given instruction till CX=0
● MOVSB/MOVSW Move string byte/word
● LEA Used to load the address of operand into the provided register
● CLD Clears the direction flag (string operations will increment the index registers (SI and/or DI))
● REP Work as loop instruction Loop repeats until CX= 0

Q1

AIM: Write an ALP to count the number of vowels in a given string.

ALGORITHM:
1. Store all the vowels (lowercase and uppercase) in a string
2. Set counter to zero
3. Move the given string to SI and the vowel string to DI
4. Check for the end of the string
5. Traverse through SI compare the letter in the position with all vowels by traversing through DI
6. If vowel found, increment counter
7. Continue for all the letters in the given string

CODE:
OUTPUT:
RESULT AND VERIFICATION:

Input = ‘String’ contains 1 vowel.


The register BX stores the output and BX = 0001
Hence, the result was verified.
Q2

AIM: Write an ALP to perform addition and subtraction of 3*3 matrix

CODE:
OUTPUT:
RESULT AND VERIFICATION:
Input: Matrix 1 @ 1000 = ( (4,4,4) , (4,4,4) , (4,4,4) ), Matrix 2 @ 2000 = ( (1,1,1) , (1,1,1) , (1,1,1) )
Sum @ 5000 = ( (5,5,5) , (5,5,5) , (5,5,5) ), Difference @ 7000 = ( (3,3,3) , (3,3,3) , (3,3,3) ),
The output is displayed correctly.
Q3

AIM: Write an ALP to check if a string is a palindrome.

ALGORITHM:
1. Move the given string to SI
2. Reverse the given string
3. The string is now stored in DI
4. Compare each letter of DI to SI using REPE CMPSB
5. If same print message ‘Palindrome’ else print ‘not palindrome’

CODE:
OUTPUT:
RESULT AND VERIFICATION:

Input = ‘ABCBA’ is a palindrome and the same has been printed on the screen. Hence, result verified.
Q4
AIM: Write an ALP to find one’s and two’s complement of a 16-bit number.

ALGORITHM:
1. Move the given 16-bit data to AX register
2. Use the command NOT to invert all digits (0 to 1 and 1 to 0) to obtain the 1’s complement
3. Use the INC command to add 1 and obtain the 2’s complement.

CODE:
OUTPUT:

RESULT AND VERIFICATION:

Input = (0010)16 = (10000)2


1’s complement of (10000)2 = (01111)16
(FFEF)16 = (1111 1111 1110 1111)16
2’s complement of (01111)16 =(01111 + 1)16= (10000)16
(FFF0)16 = (1111 1111 1111 0000)16

You might also like