Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment 2

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

Computer Organization & Assembly Language

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

Prints all uppercase letters if the entered letter is ‘U’


Prints all lowercase letters if the entered letter is ‘L’
Prints number between 0-9 if the entered letter is ‘N’
Prints first seven terms of Fibonacci series using loop if the entered letter is ‘F’
If entered letter is ‘P’ then takes a single digit number an input and displays
whether its prime or not (‘P’ or ‘N’)

Question No.3

Write a program that displays following output (By taking Input) ,.

(A) Input = 4 (B)

7 8 9 10 Input =3 (Must be odd)


456
23 *
1 **
****
**
*
(C) Input = 6

*******
* *
* *
* *
* *
*******

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;
}
}
}

You might also like