ICE 313 Lab-5(Subrata Roy)
ICE 313 Lab-5(Subrata Roy)
Lab Report
Course Title: Microprocessor and Interfacing
Section:01
Experiment No: 05
Student Information
Name : Subrata Roy ID: 2020-1-50-038
Objectives: The main goal of the experiment is to educate students to how to construct a
function and call it from the main program, as well as the accompanying stack memory details,
utilizing ARM Assembly Codes for various practical modular applications.
Program #1
Code:
// R0 = a, R1 = b, R2 = a^b
.GLOBAL MAIN
MAIN:
MOV R0, #3
MOV R1, #5
PUSH {R0, R1}
BL POWER
MOV R2, R0
POP {R0, R1}
MOV R7, #1
SWI 0
POWER:
CMP R1, #0
BNE NZ
MOV R0, #1
B RET
NZ:
MOV R2, #1
MOV R3, R0
MOV R0, #1
FOR:
CMP R2, R1
BGT RET
MUL R0, R0, R3
ADD R2, R2, #1
B FOR
RET:
MOV PC, LR
Output:
Program #2
Code:
.global _start
_start: // R0 = n, R1 = n!
.GLOBAL MAIN
MAIN:
MOV R0, #7
MOV R1, #0
PUSH {R0}
BL FACT
MOV R1, R0
POP {R0}
MOV R7, #1
SWI 0
FACT:
CMP R0, #0
BNE NZ
MOV R0, #1
B RET
NZ:
MOV R2, #1
MOV R1, R0
MOV R0, #1
FOR:
CMP R2, R1
BGT RET
RET:
MOV PC, LR
Output:
2. Develop an ARM function which takes two integer N and R as input and computes the
permutation (NPR) and combination (NCR) values as outputs. Test your function under a
suitable main function. Note that, you also have to consider the boundary conditions.
Code:
.global _start
_start:
.GLOBAL MAIN
MAIN:
MOV R0,#7
MOV R1,#0
PUSH {R0}
MOV R1,R0
POP {R0}
MOV R2,#1
SWI 0
COMB:
CMP R0,#0
BNE NZ
MOV R0,#1
B RET
NZ:
MOV R2,#1
MOV R1,R0
MOV R0,#1
FOR:
CMP R2,R1
BGT RET
MUL R0,R0,R2
ADD R2,R2,#1
B FOR
RET:
MOV PC,LR
Output: