MC Lab Manual
MC Lab Manual
MC Lab Manual
Laboratory MANUAL
(FOR THE ACADEMIC YEAR 2019-2020)
Exercises
4. ARM ALP # I
a. ALP to find the arithmetic progression with a=3, d=7.
b. ALP to find the sum of cubes of the first n natural numbers.
5. ARM ALP # II
a. ALP to count the number of zeroes and ones in a binary number.
b. ALP to find the average of ten 16-bit numbers stored in memory.
7. ARM ALP # IV
a. ALP to find the sum of digits of a number.
b. ALP to convert BCD number to binary.
8. ARM ALP # V
a. ALP to find nCr.
b. ALP to find nPr.
9. ARM ALP # VI
a. ALP to implement Bubble Sort on an array of integers.
b. ALP to implement Binary Search on an array of integers.
10. ARM ALP # VII
a. ALP to check whether the given number is palindrome.
b. ALP to count the number of times a substring is repeated in the string.
a)
b)
AREA PROG1,CODE,READONLY
ENTRY
MOV R0,#0x78
MOV R1,#0x21
ADD R3,R1,R0
STOP B STOP
END
Exercise # 2
a)
addition of first five natural numbers
AREA PROG2,CODE,READONLY
ENTRY
MOV R0,#0
MOV R1,#0
BACKK ADD R0,R0,#1
ADD R1,R1,R0
CMP R0,#5
BNE BACKK
GO B GO
END
c) sum of 5 terms in AP
AREA PROG4,CODE,READONLY
ENTRY
MOV R3,#0
MOV R1,#3
MOV R2,#0
BACKK ADD R3,R3,R1
ADD R1,R1,#7
ADD R2,R2,#1
CMP R2,#5
BNE BACKK
GO B GO
END
d) sum of squares of 5 numbers
AREA PROG5,CODE,READONLY
ENTRY
MOV R7,#0
MOV R2,#1
LOOP BL SQU
ADD R7,R7,R4
ADD R2,R2,#1
CMP R2,#6
BNE LOOP
GO B GO
SQU MUL R4,R2,R2
MOV PC,LR
END
Exercise # 3
a)
AREA PROG8,CODE,READONLY
ENTRY
MOV R1,#3
MOV R2,#1
LDR R3,=PRO
STR R1,[R3]
ADD R1,R1,#7
BACKK STR R1,[R3,#4]!
ADD R1,R1,#7
ADD R2,R2,#1
CMP R2,#10
BNE BACKK
GO B GO
AREA PROGRESSION,DATA,READWRITE
PRO SPACE 10
END
b)
AREA PROG9,CODE,READONLY
N RN 1
NPLUSONE RN 2
TEMP RN 3
RESULT RN 4
ENTRY
MOV R5,#0x40000000
LDR N,=3
ADD NPLUSONE,N,#1
MUL TEMP,N,NPLUSONE
MOV TEMP,TEMP,LSR #1
MUL RESULT,TEMP,TEMP
STR RESULT,[R5]
STOP B STOP
END
Exercise # 5
a)
AREA PROG12,CODE,READONLY
N RN 1
FACT RN 2
ENTRY
MOV N,#10
MOV FACT,#1
LOOP MUL FACT,N,FACT
SUBS N,N,#1
BNE LOOP
STOP B STOP
END
b)
AREA PROG13,CODE,READONLY
ENTRY
MOV R1,#1
LDR R2,=TABLE
LDR R3,=NUMFIBONACCI
LDRB R6,[R3]
STRB R1,[R2],#1
MOV R3,#0
MOV R4,#0
MOV R5,#1
SUB R6,R6,#1
BACKK ADD R4,R3,R1
STRB R4,[R2],#1
MOV R3,R1
MOV R1,R4
ADD R5,R5,#1
CMP R5,R6
BLS BACKK
GO B GO
NUMFIBONACCI DCB 0x0A
AREA NUMBER,DATA,READWRITE
TABLE SPACE 60
END
Exercise # 7
a)
AREA PROG14,CODE,READONLY
DIVIDEND RN 1
DIVISOR RN 2
QUOTIENT RN 3
REMAINDER RN 4
RESULT RN 5
ENTRY
LDR DIVIDEND, =12345
MOV DIVISOR,#10
MOV RESULT,#0
LOOP BL DIV
ADD RESULT,REMAINDER,RESULT
CMP QUOTIENT,#0
MOVNE DIVIDEND,QUOTIENT
BNE LOOP
STOP B STOP
a)
AREA PROG16,CODE,READONLY
DIVIDEND RN 1
DIVISOR RN 2
QUOTIENT RN 3
REMAINDER RN 4
N RN 10
R RN 11
NDR RN 12
ENTRY
MOV N,#6
MOV R,#3
LDR R5,=0X40000000
SUB NDR,N,R
MOV DIVIDEND,N
BL FACT
MOV N,DIVISOR
MOV DIVIDEND,NDR
BL FACT
MOV DIVIDEND,N
BL DIV
STR QUOTIENT,[R5]
STOP B STOP
a)
AREA PROG18,CODE,READONLY
ENTRY
MOV R0,#13
LDR R1,=NUMS
LDR R2,=0X40000000
LOOP1 LDR R3,[R1],#4
STR R3,[R2],#4
SUBS R0,R0,#1
BNE LOOP1
MOV R12,#13
LDR R11,=0X40000000
LOOP3 MOV R1,R11;INITIALISING I
SUBS R12,R12,#1
MOVNE R0,R12
BEQ STOP
LOOP2 ADD R2,R1,#4
LDR R3,[R1]
LDR R4,[R2]
CMP R3,R4;
STRPL R3,[R2]
STRPL R4,[R1]
ADD R1,R1,#4
SUBS R0,R0,#1
BNE LOOP2
CMP R12,#0
BNE LOOP3
STOP B STOP
NUMS DCD 20,19,18,17,16,15,14,13,12,11,10,9,8
END
b)
AREA PROG19,CODE,READONLY
ENTRY
NUM EQU 11
SIZE EQU 1
MAIN BL FINDIT
B MAIN
FINDIT
STMDB SP!, {R4,R7,R8,R9,R10,R11,R12,LR}
LDMFD R3!, {R11,R7,R8,R10, R0}
CMP R7, R8
BGT STOP
MOV PC, LR
STOP B STOP
a)
AREA PROG20,CODE,READONLY
ENTRY
LDR R1, = 12321
MOV R6,R1
MOV R2,#10
MOV R5,#0
MOV R10,#10
LOOP BL DIV
MLA R5,R10,R5,R4
CMP R3,#0
MOVNE R1,R3
BNE LOOP
CMP R5,R6
MOVEQ R7,#1
MOVNE R7,#0
STOP B STOP
CMP R4,#0
ADDEQ CNT,CNT,#1
MOVEQ R2,R12
BEQ LOOP
CMP R3,R4
ADDEQ R2,R2,#1
MOVNE R2,R12
ADD R1,R1,#1
BEQ LOOP
CMP R3,#0
BEQ STOP
BNE LOOP
STOP B STOP
M DCB "ABCABC",0
S DCB "ABC",0
END
Exercise # 11
a)
#include<LPC214X.h>
void delay(int);
int main()
{
IODIR0 = 0x00000001;
while(1){
IOSET0 = 0x00000001;
delay(500);
IOCLR0 = 0x00000001;
delay(500);
}
}
void delay(int n)
{
inti =0;
for(i = 0;i<n;i++);
}
Exercise # 12
a)
#include<lpc214x.h>
//124373 * 0.25 = 31093 = 7975H
//124373 * 0.75 = 93280; 93280/2 = 46640 = B630
voidon_delay(void){
T0MR0=0x7974;
T0PR=0;
T0TCR=1;
while(T0TC!=T0MR0);
T0TCR=2;
T0TC=0;
}
voidoff_delay(void){
T0MR0=0xB630;
T0PR=1;
T0TCR=1;
while(T0TC!=T0MR0);
T0TCR=2;
T0TC=0;
}
int main(void){
T0MCR=4;
IODIR1=0x00010000;
while(1){
IOSET1=1<<16;
on_delay();
IOCLR1=1<<16;
off_delay();
}
}
b)
#include<LPC214X.h>
unsigned int x = 0;
__irq void Timer0_ISR (void){
x ^= 1;
if(x)
IOSET1 = 1 << 20;
else
IOCLR1 = 1 << 20;
T0IR = 0x01;
VICVectAddr = 0x00000000;
}
int main(){
IODIR1 = 0x0FFFFFFF;
T0MCR = 0x00000003;
T0MR0 = 0x3456FF;
VICVectAddr4 = (unsigned)Timer0_ISR;
VICVectCntl4 = 0x00000024;
VICIntEnable = 0x00000010;
T0TCR = 1;
for(;;);
}
Exercise # 13
a)
# include <lpc214x.h>
voidpwm_init(void)
{
PINSEL0|=0x00000002;
PWMPR= 0x2;
PWMPCR=0x00000200;
PWMMR0=0xC37F;
PWMMCR=0x00000002;
PWMTCR=0x00000009;
}
int main()
{
inti;
pwm_init();
while(1)
{ for(i=0;i<10;i++)
{PWMMR1=0xFFF+(0xFF5*i);
PWMLER=0x02;
}}}
Exercise # 14
a)
#include<LPC214X.h>
voidinit()
{
PINSEL0=0x05;
U0FCR=0x07;
U0LCR=0x83;
U0DLL=0x5D;
U0DLM=0x00;
}
void delay()
{
inti;
for(i=0;i<250;i++);
}
int main()
{
unsigned char p[]="I LOVE ISE\n";
int z;
init();
for(z=0;z<=24;z++)
{
U0THR=p[z];
while(!(U0LSR&0x20));
delay();
}
while(1);
}