Coarm Lab Manual Vtu 5th Sem 21 Scheme
Coarm Lab Manual Vtu 5th Sem 21 Scheme
LAB MANUAL
LIST OF EXPERIMENT
PART-A
Conduct the following experiments by writing Assembly Language Program (ALP) using ARM
Cortex M3 Registers using an evaluation board/simulator and the required software tool.
1. Write an ALP to i)multiply two 16 bit binary numbers ii) add two 64 bit Numbers.
2. Write an ALP to find the sum of first 10 integer numbers.
3. Write an ALP to find factorial of a number.
4. Write an ALP to add an array of 16 bit numbers and store the 32 bit result in internal RAM
5. Write an ALP to find the square of a number (1 to 10) using look-up table.
6. Write an ALP to find the largest/smallest number in an array of 32 numbers.
7. Write an ALP to arrange a series of 32 bit numbers in ascending/descending order.
8. i) Write an ALP to count the number of ones and zeros in two consecutive memory locations.
ii) Write an ALP to scan a series of 32 bit numbers to find how many are negative.
Tools:
Keil 5µvision
Program:
AREA DIS, CODE, READONLY
ENTRY
LDR R0,VALUE1 ; LOAD THE DATA PRESENT IN THE VALUE1 TO R0.
LDR R1,VALUE2 ; LOAD THE DATA PRESENT IN THE VALUE2 TO R1.
UMULL R4,R3,R1,R0 ; UNSIGNED MULTIPLY LONG R4, R3, R1, R0; [R3,R4] = R1*R0
STOP B STOP ; THIS LINE CAN BE IGNORED IF USING ONLY CODE.
VALUE1 DCD &11111111
VALUE2 DCD &11111111
END
Tools:
Keil 5µvision
Program:
AREA add64, CODE, READONLY
ENTRY
MAIN
LDR R0, =Value1 ;pointer to first value
LDR R1, [R0] ;load first part of value1
LDR R2, [R0, #4] ; load lower part of value1
LDR R0, =Value2 ;pointer to second value
LDR R3, [R0] ;load upper part of value2
LDR R4, [R0, #4] ; load lower part of value2
ADDS R6, R2, R4 ;add lower 4 bytes and set carry flag
ADC R5, R1, R3 ;add upper 4 bytes including carry
LDR R0, =Result ;pointer to result
STR R5, [R0] ;store upper part of result
STR R6, [R0, #4] ;store lower part of result
SWI &11
Value1 DCD &12A2E640, &F2100123
Value2 DCD &001019BF, &40023F51
Result DCD 0
END
(OR)
AREA ADDITION , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
LDR R0,=0X1234E640 ;LOAD THE FIRST VALUE IN R0,R1
LDR R1,=0X43210010
LDR R2,=0X12348900 ;LOAD THE SECOND VALUE IN R2,R3
LDR R3,=0X43212102
ADDS R4,R1,R3 ;RESULT IS STORED IN R4,R5
ADC R5,R0,R2
NOP
NOP
NOP
END ;Mark end of file
Program No. 4 To add an array of 16 bit numbers and store the 32 bit result in internal
RAM
Aim: Write a program to add an array of 16 bit numbers and store the 32 bit result in internal
RAM
Program:
AREA PROG, CODE, READONLY
ENTRY
MOV R0, #04
MOV R1, #00
MOV R2, #0X40000000
MOV R3, #0X40000010
LOOP LDRH R4,[R2]
ADD R1,R4,R1
SUBS R0,R0,#01
ADD R2,#2
BNE LOOP
STR R1,[R3]
STOP B STOP
END
Program No. 5 to find the square of a number (1 to 10) using look-up table.
Aim: Write a program to find the square of a number (1 to 10) using look-up table.
Program:
AREA SQUARE, CODE, READONLY
ENTRY
LDR R0,=TABLE1
LDR R1, =5
SUB R1, #1
ADD R0,R1
LDRB R2, [R0]
STOP B STOP
AREA DATA1, DATA, READONLY
TABLE1 DCB 01,04,09,16,25,36,49,64,81,100
END
Result: The given number is 5, Square of 5 is 25 in decimal, It is 18 in Hexa, The value 18 is
found in R2.
Program No. 8 (i) To count the number of ones and zeros in two consecutive memory
locations.
Aim: Write a program to count the number of ones and zeros in two consecutive memory
locations.
Program:
AREA DATA1, CODE, READONLY
ENTRY
MOV R0, #0X40000000
MOV R1,#02
MOV R2,#00
MOV R3,#00
UP MOV R4,#08
LDRB R5,[R0]
TOP TST R5,#01
BEQ INCZERO
ADD R2,#01
B LOOP
INCZERO ADD R3,#01
LOOP LSR R5,#01
SUBS R4,#01
CMP R4,#0
BNE TOP
ADD R0,#1
SUBS R1,#01
CMP R1,#00
BNE UP
STOP B STOP
END
Program 8(ii) To Scan a series of 32 bit numbers to find how many are negative.
AIM: Write an ALP to Scan a series of 32 bit numbers to find how many are negative.
Program:
;/*ARRAY OF 7 NUMBERS
0X12345678,0X8D489867,0X11111111,0X33333333,0XAAAAAAAA */
;/*0XE605546C ,0X99999999 */
;/* RESULT CAN BE VIEWED IN R2 */
AREA NEGATIVE , CODE, READONLY
ENTRY ;Mark first instruction to execute
START
MOV R5,#7 ; INTIALISE COUNTER TO 7(i.e. N=7)
MOV R2,#0 ; COUNTER
LDR R4,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE
LOOP
LDR R1,[R4],#4 ; WORD ALIGN T0 ARRAY ELEMENT
ANDS R1,R1,#1<<31 ; TO CHECK NEGATIVE NUMBER
BHI FOUND ; IF THE GIVEN NUMBER IS NEGATIVE GOTO FOUND
B LOOP1; IF THE GIVEN NUMBER IS NOT NEGATIVE GOTO LOOP1
FOUND
ADD R2,R2,#1 ; INCREMENT THE COUNTER
(NEGATIVE NUMBER)
B LOOP1 ; GOTO LOOP1
LOOP1
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
NOP
NOP
;ARRAY OF 32 BIT NUMBERS(N=7)
VALUE
DCD 0X12345678 ;
DCD 0X8D489867 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XE605546C ;
DCD0XAAAAAAAA;
DCD 0X99999999 ;
END ; Mark end of file
DEMONSTRATION EXPERIMENTS
Conduct the following experiments on an ARM CORTEX M3 evaluation board using evaluation version
of Embedded 'C' & Keil Uvision-4 tool/compiler.
9.Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
#include <LPC214X.h>
void delay();
void delay()
{
int i,j;
for (i=0; i<0xff; i++)
for (j=0; j<0xff; j++);
}
int main()
{
IO0DIR=0x000F0000; //Consider ARM port Pin from 16-19
//And set these pins
while (1)
{
//while (IO0PIN & 0x00008000);
//while (! (IO0PIN & 0x00008000));
IO0PIN=0x00010000;
delay ();
IO0PIN=0x00020000;
delay ();
IO0PIN=0x00040000;
delay ();
IO0PIN=0x00080000;
delay();
}
}
PROGRAM NO:10
Aim: Interface a DAC and generate Triangular and Square waveforms.
PROGRAM:
SQUARE WAVE PROGRAM
PROGRAM
#include "LPC214X.h"
unsigned int result=0x00000040,val;
int main()
{
PINSEL1|=0x00080000;
while(1)
{
while(1)
{
val =0xFFFFFFFF;
DACR=val;
{
break;
}
}
while(1)
{
val =0x00000000;
DACR=val;
{
break;
}
}
}
}
AIM: Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay in between
PROGRAM:
#include <LPC214x.H>
void delay_led(unsigned long int);
int main(void)
{
IO0DIR = 0x000007FC;
while(1)
{
IO0CLR = 0x00000FFF;
IO0SET = 0x00000604;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000007E4;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000648;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000618;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000730;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000690;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000680;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x0000063C;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000600;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000630;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000620;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000780;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006C4;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x00000708;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006C0;
delay_led(15000000);
IO0CLR = 0x00000FFF;
IO0SET = 0x000006E0;
delay_led(15000000);
IO0CLR = 0x00000FFF;
}
}
void delay_led(unsigned long int count1)
{
while(count1 > 0) {count1--;}
}
PROGRAM NO:12 Interface a simple Switch and display its status through Relay, Buzzer
and LED.
#include <LPC17xx.H>
int main(void)
{
LPC_PINCON->PINSEL1 = 0x00000000;
//P0.24,P0.25 GPIO
LPC_GPIO0->FIODIR = 0x03000000;
//P0.24 configured output for buzzer,P0.25 configured output for Relay/Led
while(1)
{
if(!(LPC_GPIO2->FIOPIN & 0x00000800)) //Is
GP_SW(SW4) is pressed??
{
LPC_GPIO0->FIOSET = 0x03000000; //relay on
}
else
{
LPC_GPIO0->FIOCLR = 0x03000000; //relay off
}
}
}
//end