MC LAB PROGRAMS
MC LAB PROGRAMS
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
AIM: To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations .
AREA DATATRANSFER,CODE,READONLY
ENTRY
LDR R9,=SRC
LDR R10,=DST
LDMIA R9!,{R0-R7}
STMIA R10!,{R0-R7}
AREA BLOCKDATA,DATA,READWRITE
END
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
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
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
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
END
Output:
Program 3
Develop an ALP 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
END
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
END
Program 4
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
END
Output:
Learning Outcomes:
PROGRAM 5
AREA LARGEST_ARRAY,CODE,READONLY
ENTRY
MOV R0,#5
LDR R1,=ARRAY
LDR R2,[R1],#4
CMP R2,R3
BHI NEXT
MOV R2,R3
NEXTSUBS R0,R0,#1
BNE LOOP
STOP B STOP
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
CMP R2,R3
BLO NEXT
MOV R2,R3
NEXTSUBS R0,R0,#1
BNE LOOP
STOP B STOP
END
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
LDR R0,[R6],#4
BHI ONES
B LOOP1
BNE LOOP0
SUBS R7,R7,#1
BNE LOOP
STOP B STOP
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
#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;