Mpca Lab1 Programs
Mpca Lab1 Programs
COMPUTER ARCHITECTURE
LABORATORY
4TH Semester
Prof Deepti C
Computer Science and Engineering
Microprocessor & Computer Architecture Laboratory
Course Information
WEEK PROGRAMS
2 1. Write an ALP to add if the numbers are equal, otherwise subtract
them.
2. Write an ALP using ARM instruction set to check if a number stored in
a register is even or odd.
3. Write a program to find the factorial of a given number.
4. Write a program to find GCD of two numbers.
Microprocessor & Computer Architecture Laboratory
WEEK Write an ALP to compare the value of R0 and R1, add if R0 = R1,
else subtract.
2
Algorithm
1.The first number is to be saved in R0
2.The second number is to be saved in R1
3.Compare the two numbers
4.If they are equal,branch to location L1
where both numbers are added.
5.Save the addition result in R2 and end
execution
WEEK Write an ALP to find the factorial of a number stored in R0. Store
the value in R1 (without using LDR and STR instructions).Use
2
only registers.
Algorithm
1.The number n is to be saved in R0
2.Let R1=1
3.Multiply contents of R0 and R1
Save the result in R1
4.Subtract the contents of R0 by 1 to
calculate n-1 1st Iteration R0=0x05
5.Check if the content of R0 is one R1=0x04
6.Repeat steps 3 to 5 till R0 reaches one R1=0X14=Decimal 20
9.End execution when R0=1 2nd Iteration R1=0x14
(One Screenshot-Choose your own R0=0X03
R1=0x3C=Decimal 60
example)
3rd Iteration R1=0x3C
R0=0X02
R1=0x78
4th Iteration R1=0x78
R0=0X01
R1=0x78 =Decimal 120
Microprocessor & Computer Architecture Laboratory
WEEK Write an ALP to find GCD of two numbers (without using LDR
and STR instructions).Both numbers are in registers. Use only
2
registers.
Algorithm
1.The first number is to be saved in R0
2.The second number is to be saved in R1
3. Compare both numbers in R0 and R1.
4.If they are equal, end execution
5.If R0 is greater than R1,R0= R0-R1
6.Repeat steps 3 to 6 till R0=R1, end
execution
7. If R0 is lesser than R1,R1= R1-R0
(Three Screenshots(A=B,A<B,A>B)
Choose your own example)
THANK YOU
Deepti C