You are on page 1of 20

Arm Microcontroller Lab

(22EECP204)

Assembly Codes

Team: 1 Div: B (Batch 2)


Name USN Roll No

1.Tanmay Kulkarni 01fe22bec076 246


2. Karthik Gunda 01fe22bec081 251
3. Shashank Padavalkar 01fe22bec087 256
4. Rohit Kuppelur 01fe22bec095 264
1. Develop an ALP to check whether the given string is palindrome or not
AREA PALINDROME,CODE,READONLY
ENTRY
START
LDR R0,=string
LDR R2,=0x40000000
loop
LDRB R1,[R0],#0x01
CMP R1,#0x00
BEQ next
STRB R1,[R2],#0x01
B loop
next
BL stringlength
Arm Microcontroller Lab 2
LDR R0,=0x40000000
SUB R7,R1,#0x01
ADD R3,R0,R7
loop1 ;reverse the string
CMP R4,R1,LSR #0x01
BEQ Next
LDRB R5,[R0]
LDRB R6,[R3]
STRB R6,[R0]
STRB R5,[R3]
ADD R0,R0,#0x01
SUB R3,R3,#0x01
ADD R4,R4,#0x01
B loop1
Arm Microcontroller Lab 3
Next
LDR R0,=0x40000000
LDR R2,=string
loop3
LDRB R7,[R0],#0x01
LDRB R8,[R2],#0x01
CMP R7,R8 ;compare both the strings
BNE next2
SUBS R1,R1,#0x01
BNE loop3
MOV R10,#0xEE ;IT IS A PALINDROME
B STOP
next2
MOV R10,#0xFF ;IT IS NOT A PALINDROME
Arm Microcontroller Lab 4
STOP B STOP
stringlength
LDR R0,=string
loop2
LDRB R2,[R0],#0x01
CMP R2,#0x00
BEQ next1
ADD R1,R1,#0x01
B loop2
next1
MOV PC,LR
string DCB "racecar",0
END

Arm Microcontroller Lab 5


AREA PALINDROME, CODE, READONLY
ENTRY
START
LDR R0, =string
LDR R1, =0
loop
LDRB R2, [R0], #1
CMP R2, #0
BEQ check_palindrome
STRB R2, [R0, #-1]
ADD R1, R1, #1
B loop
check_palindrome
SUBS R3, R1, #1

Arm Microcontroller Lab 6


loop1
CMP R0, R3
BEQ is_palindrome
LDRB R4, [R0]
LDRB R5, [R0, R3, LSL #1]
CMP R4, R5
BNE not_palindrome
ADD R0, R0, #1 ;
SUBS R3, R3, #1
B loop1
is_palindrome
MOV R6, #0xEE
B STOP
not_palindrome
MOV R6, #0xFF
B STOP
STOP B STOP
string DCB "racecar",0
END
Arm Microcontroller Lab 7
Simulation

Arm Microcontroller Lab 8


Execution Profiling (Timing) and Code Coverage

Arm Microcontroller Lab 9


Arm Microcontroller Lab 10
Performance Analyzer

Arm Microcontroller Lab 11


2. Develop an ALP to check whether the given number is prime or not

AREA PRIMECHECK,CODE,READONLY
ENTRY
START
MOV R3,#0x1F
MOV R4,#0x02
MOV R6,#0xFF ;it is a prime number
loop
CMP R4,R3
BEQ STOP
BL DIV
CMP R2,#0 ;check if remainder is zero after division
BEQ notprime
Arm Microcontroller Lab 12
ADD R4,R4,#0x01
B loop
notprime
MOV R6,#0xEE ;not a prime number
STOP B STOP

DIV
MOV R2,R3
MOV R1,R4
MOV R0,#0x00
again ADD R0,R0,#0x01
SUBS R2,R2,R1
BPL again
SUB R0,R0,#0x01
ADD R2,R2,R1
MOV PC,LR
END
Arm Microcontroller Lab 13
AREA PRIMECHECK,CODE,READONLY

ENTRY
START
MOV R0, #2
MOV R1, #31

loop
BL is_prime

CMP R2, #1
BEQ STOP

ADD R0, R0, #2


BLT loop

STOP
B STOP

Arm Microcontroller Lab 14


is_prime
MOV R3, R0
MOV R8,R3
MUL R2,R8,R3

loop2
CMP R2, #0
BEQ not_prime ;

SUBS R3, R3, R2


BHI loop2

CMP R3, #1
BEQ prime

not_prime
MOV R1, #0
BX LR

prime
MOV R1, #1
BX LR

Arm Microcontroller Lab 15


Simulation

Arm Microcontroller Lab 16


Execution Profiling (Timing) and Code Coverage

Arm Microcontroller Lab 17


Arm Microcontroller Lab 18
Performance Analyzer

Arm Microcontroller Lab 19


THANK YOU

Arm Microcontroller Lab 20

You might also like