Assignment 2
Assignment 2
Assignment 2
Assignment 2
Question No.1
Part A- A string is a palindrome if, considering only alphabets, the string reads the same both
backward and forward. For example, “Madam, I’m Adam” is a palindrome . Write an assembly
code, that takes a string from user and shows if it is a palindrome or not.
Note: Special characters shoud not spoil the palindrome (You may eliminate them before checking)
Part B- Input a list of Strings e.g ['Ali', 'Usman', 'Abdullah'] You have to sort them in
ascending order . (Take Input a size of array)
To decide which string is greater use the following algorithm. Multiply the ascii of each character
with its index and add them. The string with higher value would be greater.
For Example suppose the string passed are Ali & Umar then :
Ali : (ascii of A) * 1 + (Ascii of l) * 2 + (Ascii of i) * 3 = (65) * 1 + (108) * 2 + (105) * 3 = 491
Umar : (ascii of U) * 1 + (Ascii of m) * 2 + (Ascii of a) * 3 + (Ascii of r) * 4 = (85) * 1 + (109) * 2
+ (97) * 3 + (114) *4 = 1050
Question No.2
Write an assembly program that takes a letter as an input and does the following
Question No.3
*******
* *
* *
* *
* *
*******
Question No.4
Write a program to multiply two matrices and store the result in third matrix. The program must
take three arguments; first matrix, second matrix (input number of rows and columns for
matrix).
The algorithm for multiplication is given as:
void mm_mul (int A[N][N], int B[N][N], int C[N][N])
{
int i, j, k;
int sum;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
sum = 0;
for (k = 0; k < N; k++)
{
Sum += A[i][k] * B[k][j];
}
C[i][j] = sum;
}
}
}