0% found this document useful (0 votes)
10 views

MPCA LAB3 Programs

The document outlines the laboratory exercises for a Microprocessor and Computer Architecture course, specifically for Lab 3. It includes tasks such as writing assembly language programs to check parity, compute factorials, sum digits, perform matrix addition, and implement search algorithms. Each program is accompanied by algorithms and instructions for execution, along with requirements for screenshots of the code and register windows.

Uploaded by

deeptic82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

MPCA LAB3 Programs

The document outlines the laboratory exercises for a Microprocessor and Computer Architecture course, specifically for Lab 3. It includes tasks such as writing assembly language programs to check parity, compute factorials, sum digits, perform matrix addition, and implement search algorithms. Each program is accompanied by algorithms and instructions for execution, along with requirements for screenshots of the code and register windows.

Uploaded by

deeptic82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MICROPROCESSOR AND

COMPUTER ARCHITECTURE
LABORATORY
4TH Semester(UE22CS251B)

LAB3
Saturday, March 15, 2025

Prof Deepti C
Computer Science and Engineering
Microprocessor & Computer Architecture Laboratory

LAB3 1. Write an ALP to check whether the given number has odd or
even number of 1’s (Even Parity and Odd Parity).
2. Write a program to compute the factorial of a number using
subroutines
3. Write an ALP to find the sum of all the digits of a given decimal
number
4. Write a program to perform 3X3 matrix addition.
5. Write a program to search for an element in an array using
Linear search technique
Assignment Questions:
Assignment:
i)Write a program to search for an element in an array using binary
search technique.
ii)Write a program to find the sum of N data items at alternate [odd
or even positions] locations in the memory. Store the result in the
memory location.
Microprocessor & Computer Architecture Laboratory

PROGRAM 1
WEEK 3 Write an ALP to check whether the given number has odd or even
number of 1’s (Even Parity and Odd Parity).

Algorithm
1.Let R0 contain the required number
2.Initialise R1=Number of bits in Given Number
3.Initialise R2 to count number of ones,initial value zero RESULT 1 RESULT 2
4.Initialise R3 to count number of zeroes, ,initial value zero
5.AND number in R0 with 1
R0=0x00F0 R0=0x00F4
6.Check if current LSB bit of R3 is 1
7.If bit is one,increment ones counter R2 00000000 00000000 00000000 00000000
8.If bit is zero,increment zeroes counter R3 00001111 00000000 00001111 00000100
9.Shift the contents of register R0 one bit to the right
10.Decrement count in R1(Number of bits in given number)
11.Repeat steps 5 to 10 till all 32 bits are checked Number of Ones =4 Number of Ones =5
12.AND value in register R2 with 1.If result after AND is zero,it Number of zeroes=28 Number of zeroes=28
indicates even parity.Else if result after AND is 1,it indicates
odd parity
13.End program
Even Parity Odd Parity

Two Screenshots –One for odd parity,One for Even Parity.


Include both code window and register window
Microprocessor & Computer Architecture Laboratory
PROGRAM 2
WEEK Write a program to compute the factorial of a number using
subroutine
3

Algorithm
R1=5=Given Number,
1.Initialise required number n in R1 R2=1=Initial Factorial Value
2.Initialise initial factorial value in R2 equal to one After 1st R2=5*1=5, R1=4
3. Call subroutine to compute Factorial Iteration
Algorithm for Factorial Subroutine After 2nd R2=5*4=20=0x14,
4a.Compare given number with zero Iteration R1=3
If zero,copy Link Register value to Program Counter(R15)
Else After 3rd R2=20*3=60=0x3C,
Iteration R1=2
4b.Multiply given number in R1 with initial factorial value in
R2(i.e,1)
After 4th R2=60*2=120=0x78
4c.Decrement R1 to get the value (n-1) Iteration R1=1
4d.Repeat steps 4a to 4c till R1 is not equal to zero After 5th R2=120*1=120=0x78
(Recursive Subroutine to be used) Iteration R1=0
5.On return from subroutine,go to end of Program
(One Screenshot-Choose your own example)
Microprocessor & Computer Architecture Laboratory
PROGRAM 3
WEEK Write an ALP to find the sum of all the digits of a given decimal number
3

Algorithm
1.Initialise required number whose sum of digits is required in
R3
2.Copy the number to R0 for further processing R1=25=Given Number=R0,
3. Let R1 keep track of number of elements ,initial value =0 R1=0,R2=0
4.Let R2=initial value of sum=0
Initial value R0=25,R1=0
5.Compare the value in R0 with decimal 10
6.If R0 value is greater than 10,repeatedly subtract from 10 First iteration R0=15,R1=1,R2=0
7.If R0 value is lesser than 10,increment R1 by 1
Second iteration R0=5,R1=2,R2=0
8.Compare current value of R0 with decimal 10.
9.If greater than 10 repeat steps 5 to 8 Third iteration R0=5,R1=2,R2=5
10.If R0 is less than 10,then add current R0 value to value of
Fourth iteration R0=5,R1=2,R2=7
sum in R2
11.Copy content of R1 to R0
12.Let R1 contain zero
13.Compare R0 with zero to check if all digits have been
covered
14.If not zero,Repeat steps 5 to 13
15.If R0 is equal to zero,go to end of program

(One Screenshot-Choose your own example)


Microprocessor & Computer Architecture Laboratory
PROGRAM 4
WEEK
Write a program to perform 3X3 matrix addition.
3
(Write an ALP to implement C[i][j]=a[i][j]+b[i][j])

Algorithm
1. Declare the matrices A,B,RES in .data segment =Matrix A
2. Let R0 contain address of A
3. Let R1 contain address of B
4. Let R2 contain address of RES=Initial Value 0
5. Let R3 contain the count for max number of elements in each square matrix(Here it is 9)
6. Copy first element of matrix A to temporary register R4.
=Matrix B
7. Increment index register R0 to point to next element of matrix A
8. Copy first element of matrix A to temporary register R5.
9. Increment index register R1 to point to next element of matrix B
10. Add registers R4 and R5.Save result in R6
11. Store result of addition in the location of matrix RES. Final addition result will be
available at address of matrix RES = Result Matrix
12. Decrement R3(Count of number of Elements) by 1
13. Repeat steps 6 to 12 until R3 is not equal to zero
14. End Program

One Screenshot-Choose your own value for array


elements.Show the Memory Window,Code window and
Register Window in the screenshot.
Microprocessor & Computer Architecture Laboratory

PROGRAM 5
WEEK 3 Write a program to search for an element in an array using Linear
search technique

Algorithm
1. Declare the array A in .data segment
2. Let R0=Address of A A:.WORD 5,10,15,20,25,30,35,40,45,50
3. Initialise key element in register R1
4. Initialise count= number of values in the array in R3 R2 KEY =30 KEY =33
5. Initial value of FOUND=0(Register R2) R3 COUNT =10 COUNT =10
6. Get the first element of array into register R4
7. Compare value in R4 with key element R0 Address of A Address of A
8. If there is a match ,key is FOUND,go to Step 12
R2 After Execution After Execution
9. If no match,increment R0 to move to next number in
Key Found Key NOT
array A.
R2=1 Found
10. If no match ,decrement the count value in R3 R2=0
11. Repeat steps 6 to 10 till R3=0.End Program
12. To indicate KEY FOUND Copy value 1 into Register
R2
13. End program Two Screenshots -Choose your own value for array
elements.Show the Memory Window,Code window and
Register Window in the screenshot.Show key found and key
not found.
THANK YOU

Deepti C

Department of Computer Science and


Engineering
deeptic@pes.edu

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy