Program 1
Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
Language Programs (ALP).
ARM7
The full form of an ARM is an advanced reduced instruction set computer (RISC) machine,
and it is a 32-bit processor architecture expanded by ARM holdings. The applications of an
ARM processor include several microcontrollers as well as processors. The architecture of
an ARM processor was licensed by many corporations for designing ARM processor based
SoC products and CPUs.
Programmer's Model
ARM has a 32-bit data bus and a 32-bit address bus. The data types the processor supports are
Words (32 bits), where words must be aligned to four byte boundaries. Instructions are exactly one
word, and data operations (e.g. ADD) are only performed on word quantities. Load and store
operations can transfer words.
Registers
The processor has a total of 37 registers made up of 31 general 32 bit registers and 6 status registers.
At any one time 16 general registers (R0to R15) and one or two status registers are visible to the
programmer. The visible registers depend on the processor mode and the other registers (the banked
registers) are switched in to support IRQ, FIQ, Supervisor, Abort and undefined mode processing.
The register bank organization is shown in output.
In all modes 16 registers, R0 to R15, are directly accessible. All registers except R15 are general
purpose and may be used to hold data or address values. Register R15 holds the Program Counter
(PC). When R15 is read, bits [1:0] are zero and bits [31:2] contain the PC. A seventeenth register
(the CPSR - Current Program Status Register) is also accessible. It contains condition code flags
and the current mode bits and may be thought of as an extension to the PC. R14 is used as the
subroutine link register and receives a copy of R15 when a Branch and Link instruction is executed.
It may be treated as a general- purpose register at all other times. R14_svc, R14_irq, R14_fiq,
R14_abt and R14_und are used similarly to hold the return values of R15 when interrupts and
exceptions arise, or when Branch and Link instructions are executed within interrupt or exception
routines.
AIM: To write a simple Assembly Language Programs (ALP) using Keil software to observe
the various Registers, Dump, and CPSR.
Program:
AREA PG_1,CODE,READONLY
ENTRY
MOV R1,#0X00000002
MOV R2,#0X00000004
ADD R3,R1,R2
STOP B STOP
END
Output: Write the output or paste the output screen
Program 2
Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
(Demonstrate with the help of a suitable program).
AIM: To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations .
Program: Data Transfer Operations
AREA DATATRANSFER,CODE,READONLY
ENTRY
LDR R9,=SRC
LDR R10,=DST
LDMIA R9!,{R0-R7}
STMIA R10!,{R0-R7}
SRC DCD 1,2,3,4,5,6,7,8
AREA BLOCKDATA,DATA,READWRITE
DST DCD 0,0,0,0,0,0,0,0
END
Output: Write the output or paste the output screen
Arithmetic Operations
AREA ARITH,CODE,READONLY
ENTRY
LDR R1,=20
LDR R2,=25
ADD R3,R1,R2
MUL R4,R1,R2
SUB R5,R1,R2
STOP B STOP
END
Output: Write the output or paste the output screen
Logical Operations
AREA LOGIC,CODE,READONLY
ENTRY
LDR R0,=5
LDR R1,=3
AND R4,R0,R1
ORR R5,R0,R1
EOR R6,R0,R1
BIC R7,R0,R1
STOP B STOP
END
Output: Write the output or paste the output screen
Program 3
Develop an ALP to multiply two 16-bit binary numbers.
Aim: To write and simulate ARM assembly language program to multiply two 16-bit binary
numbers.
Program 1:
AREA MUL16BIT,CODE,READONLY
ENTRY
MOV R1,#0x0006
MOV R2,#0x0006
MUL R3,R1,R2
LDR R0,=RESULT
STR R3,[R0]
AREA DATA2,DATA,READWRITE
RESULT DCD 0X0
END
Output:
Program 2:
AREA SUM,CODE,READONLY
ENTRY
LDR R0,=NUM
LDRH R1,[R0]
LDRH R2,[R0,#2]
MUL R3,R1,R2
STOP B STOP
NUM DCW 0X0006,0X0006
END
Output:
Program 3
Develop an ALP to multiply two 16-bit binary numbers.
Aim: Write a Program to multiply two 16-bit binary numbers.
Program:
AREA SUM,CODE,READONLY
ENTRY
LDR R0,=NUM
LDRH R1,[R0]
LDRH R2,[R0,#4]
MUL R3,R1,R2
STOP B STOP
NUM DCD 0x00000006, 0x00000006
END
Output: Write the output or paste the output screen
Learning Outcomes:
Extra Program:
AREA MUL16BIT,CODE,READONLY
ENTRY
MOV R1,#0x0006
MOV R2,#0x0006
MUL R3,R1,R2
LDR R0,=RESULT
STR R3,[R0]
AREA DATA2,DATA,READWRITE
RESULT DCD 0X0
END
Program 4
Develop an ALP to find the sum of first 10 integer numbers
Aim:Write a program to find the sum of the first 10 integer numbers.
Program:
AREA SUM,CODE,READONLY
ENTRY
LDR R0,=ARRAY
LDR R1,=10
LDR R2,=0
NEXT
LDR R3,[R0],#4
ADD R2,R2,R3
SUB R1,R1,#1
CMP R1,#0
BNE NEXT
ARRAY DCD 1,2,3,4,5,6,7,8,9,10
END
Output:
Learning Outcomes:
PROGRAM 5
Develop an ALP to find the largest/smallest number in an array of 32 numbers
Aim:Write a program to find the largest/smallest number in an array of 32 numbers
Program: Largest number in an array of 32 numbers
AREA LARGEST_ARRAY,CODE,READONLY
ENTRY
MOV R0,#5
LDR R1,=ARRAY
LDR R2,[R1],#4
LOOP LDR R3,[R1],#4
CMP R2,R3
BHI NEXT
MOV R2,R3
NEXTSUBS R0,R0,#1
BNE LOOP
STOP B STOP
ARRAY DCD 1,5,6,2,3,9
END
Smallest number in an array of 32 numbers
AREA LARGEST_ARRAY,CODE,READONLY
ENTRY
MOV R0,#5
LDR R1,=ARRAY
LDR R2,[R1],#4
LOOP LDR R3,[R1],#4
CMP R2,R3
BLO NEXT
MOV R2,R3
NEXTSUBS R0,R0,#1
BNE LOOP
STOP B STOP
ARRAY DCD 9,5,6,2,3,1
END
Output: Write the output or paste the output screen
Learning Outcomes:
PROGRAM 6
Develop an ALP to count the number of ones and zeros in two consecutive memory
locations.
AREA OZ,CODE,READONLY
ENTRY
MOV R2,#0
MOV R3,#0
MOV R7,#2
LDR R6,=NUM
LOOP MOV R1,#32
LDR R0,[R6],#4
LOOP0 MOVS R0,R0,ROR #1
BHI ONES
ZEROS ADD R3,R3,#1
B LOOP1
ONES ADD R2,R2,#1
LOOP1 SUBS R1,R1,#1
BNE LOOP0
SUBS R7,R7,#1
BNE LOOP
STOP B STOP
NUM DCD 0x5,0X7
END
PROGRAM 7
Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.
#include<lpc21xx.h>
int main(void)
{
unsigned long int temp, arr[4]= {0x00000001, 0x00000002, 0x00000004,
0x00000003};
unsigned char i,j,n=4;
for (i=0;i<n-1;i++)
{
for (j=0;j<n-1;j++)
{
if (arr[j]<arr[j+1])
{
temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]= temp;
}
}
}
}
PROGRAM 8
Simulate a program in C for ARM microcontroller to find factorial of a number.
#include<lpc21xx.h>
int main(void) {
unsigned long n=5, fact=1;
unsigned char i;
if (n==0) {
fact=1;
}
else if(n>0) {
for (i=1;i<=n;i++)
{
fact=fact*i;
}
}
}
PROGRAM 9
Simulate a program in C for ARM microcontroller to demonstrate case conversion of
characters from upper to lowercase and lower to uppercase.
#include<lpc21xx.h>
int main()
{
unsigned char d, c[10]="abcdAB";
unsigned int i,j;
for(i=0;i<=10;i++)
{
int j=(int)c[i];
if(j>=65 && j<=90)
{
j=j+32;
c[i]=(char)j;
}
else
{
j=j-32;
c[i]=(char)j;
}
}
}
EXTRA PROGRAM
Simulate a program in c for ARM microcontrollers to display fibonacci
series:
#include<lpc21xx.h>
int main(void) {
unsigned int a = 0, b = 1, c, i;
for (i = 0; i < 5; i++) {
c = a + b;
a = b;
b = c;
}
while (1); // Infinite loop
}
Develop an ALP to display Fibonacci Series :
AREA FIB, CODE, READONLY
ENTRY
MOV R0, #0
SUB R0, R0, #1
MOV R1, #1
MOV R4, #5
LDR R2, = FIBO
BACK
ADD R0, R1
STR R0, [R2]
ADD R2, #4
MOV R3, R0
MOV R0, R1
MOV R1, R3
SUB R4, #1
CMP R4, #0
BNE BACK
STOP B STOP
AREA FIBONACCI, DATA, READWRITE
FIBO DCD 0,0,0,0,0
END