Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arm Lpc2148codesfinallll

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 129

ARM CODES:

1.ARM CODE TO FIND SUM OF TWO 32 BIT NUMBERS:

AREA ADD,CODE,READONLY

ENTRY

LDR R0,=0X12345678

LDR R1,=0X11223344

ADD R2,R0,R1

STOP B STOP

END

MEMORY TIME
CODE 24B 0.583us

2.ARM CODE TO SUBTRACT TWO 32 BIT NUMBERS

AREA ADD,CODE,READONLY

ENTRY

LDR R0,=0X12345678

LDR R1,=0X11223344

SUB R2,R0,R1

STOP B STOP

END
MEMORY TIME
CODE 24B 0.583us

3. ARM CODE TO ADD TWO 64 BIT VALUES

AREA ADD,CODE,READONLY

ENTRY

LDR R0,=0X12345678

LDR R1,=0X11223344

LDR R2,=0X11111111

LDR R3,=0X22222222

ADD R4,R0,R1

ADC R5,R2,R3

STOP B STOP

END
memory time
code 44b 1.166us

4. ARM CODE TO SUBTRACT TWO 64 BIT NUMBERS

AREA ADD,CODE,READONLY

ENTRY

LDR R0,=0X12345678

LDR R1,=0X11223344

LDR R2,=0X11111111

LDR R3,=0X22222222

SUB R4,R0,R1

SUB R5,R3,R2

STOP B STOP

END

memory time
code 44b 1.166us
5. ARM CODE TO CHECK IF A NUMBER IS POSITIVE OR NEGATIVE IF ITS POSITIVE SUBTRACT 1 AND
IF ITS NEGATIVE ADD 1

AREA POSNEG,CODE,READONLY

ENTRY

MOVS R0,R1

ADDMI R0,R0,#0X01

SUBPL R0,R0,#0X01

STOP B STOP

END

memory time
code 16b 1.166us

6. ARM CODE TO CHECK IF A NUMBER IS EVEN OR ODD,IF ITS EVEN ADD 0 IF ITS ODD ADD 1

AREA EVODD,CODE,READONLY

ENTRY

MOVS R0,R1,ROR #0X01

ADDCS R1,R1,#0X01

ADDCC R1,R1,#0X00

STOP B STOP

END
memory time
code 16b 0.249us

7. ARM CODE TO ADD 5 32 BIT NUMBERS

CODE1:

AREA ADD532,CODE,READONLY

ENTRY

LDR R0,=0X12345678

LDR R1,=0X11223344

LDR R2,=0X12341111

LDR R3,=0X11111111

LDR R4,=0X22222222

ADD R5,R0,R1

ADC R5,R5,R2

ADC R5,R5,R3

ADC R5,R5,R4

STOP B STOP

END
CODE2:

AREA ADD32,CODE,READONLY

ENTRY

LDR R0,=0X40000000

LDR R1,=0X40000000

MOV R2,#0X04

LDR R3,[R0],#4

LOP LDR R4,[R0],#4

ADD R3,R3,R4

SUBS R2,R2,#0X01

BNE LOP

STR R3,[R1]

STOP B STOP

END
EXECUTION PROFILING :

MEMORY TIME
CODE1 60b 1.582us
CODE2 40b 3.165us

8.ARM CODES TO SUBTRACT 5 32 BIT NUMBERS:

CODE1:

AREA SUB532,CODE,READONLY

ENTRY

LDR R0,=0X22222222

LDR R1,=0X12345678

LDR R2,=0X12222222

LDR R3,=0X11112222

LDR R4,=0X11111111

SUB R5,R0,R1

SUB R5,R5,R2

SUB R5,R5,R3

SUB R5,R5,R4

STOP B STOP

END
CODE2:

AREA ADD32,CODE,READONLY

ENTRY

LDR R0,=0X40000000

LDR R1,=0X40000000

MOV R2,#0X04

LDR R3,[R0],#4

LOP LDR R4,[R0],#4

SUB R3,R3,R4

SUBS R2,R2,#0X01

BNE LOP

STR R3,[R1]

STOP B STOP

END
MEMORY TIME
CODE1 60b 1.582us
CODE2 40b 3.165us

9.ARM CODE TO FIND LARGEST OF TWO NUMBERS

CODE1:

AREA LAR,CODE,READONLY

ENTRY

CMP R0,R1

MOVCS R3,R0

MOVCC R3,R1

STOP B STOP

END
CODE2:

AREA LAR,CODE,READONLY

ENTRY

SUBS R5,R0,R1

MOVCS R3,R0

MOVCC R3,R1

STOP B STOP

END

MEMORY TIME
CODE1 16B 0.249us
CODE2 16B 0.249us
10. ARM CODE TO FIND THE SMALLEST

CODE1:

AREA LAR,CODE,READONLY

ENTRY

CMP R0,R1

MOVCS R3,R1

MOVCC R3,R0

STOP B STOP

END
CODE2:

AREA LAR,CODE,READONLY

ENTRY

SUB R5,R0,R1

MOVCS R3,R1

MOVCC R3,R0

STOP B STOP

END
MEMORY TIME
CODE1 16B 0.249us
CODE2 16B 0.249us

11. ARM CODE TO DIVIDE A NUMBER BY 4 USING SUBTRACTION LOGIC

AREA SUBDIV,CODE,READONLY

ENTRY

LOOP CMP R0,#0X00

SUBPL R0,#0X04

ADDPL R1,R1,#0X01

CMP R0,#0X04

BPL LOOP

STOP B STOP

END

MEMORY TIME
CODE 24B 1.583us
12.ARM CODE FOR MULTIPLYING A NUMBER BY 5 USING ADDITION LOGIC

CODE1.

AREA MULADD,CODE,READONLY

ENTRY

MOV R0,#0X05

LOOP CMP R0,#0X00

ADDNE R2,R2,R1

SUBNE R0,R0,#0X01

B LOOP

STOP B STOP

END

CODE2.

AREA MULADD2,CODE,READONLY

ENTRY

MOV R0,#0X02

ADD R2,R0,R0,LSL #0X02

STOP B STOP

END
MEMORY TIME
CODE1 24B 1.832us
C0DE2 12B 0.166us
13. ARM CODE TO FIND THE LARGEST IN AN ARRAY OF 5 32 BIT NUMBERS

AREA MAXC2,CODE,READONLY
ENTRY
MOV R0,#0X04
LDR R1,=ARRAY
LDR R2,[R1],#4
LDR R5,=0X40000000
LOOP LDR R3,[R1],#4
CMP R2,R3
MOVCS R2,R2
MOVCC R2,R3
SUBS R0,R0,#0X01
BNE LOOP
STOP B STOP
ARRAY DCD 0X55554411,0X44567890,0X12341111,0X11111111,0X22222222
END
CODE2:

AREA LARGEST,CODE
ENTRY
MOV R5,0X05;
LDR R1,=0X40000000;
LDR R2,[R1],#04;
LOOP LDR R4,[R1],#04
CMP R2,R4
BCC LOOP1
MOV R2,R4
LOOP1 SUBS R5,R5,#1
BNE LOOP
STOP B STOP
END
MEMORY TIME
CODE1 64B 25ms
CODE2 40B 4.75us

14. ARM CODE TO FIND THE SMALLEST IN AN ARRAY OF 5 32 BIT NUMBERS

AREA MAXC2,CODE,READONLY
ENTRY
MOV R0,#0X04
LDR R1,=ARRAY
LDR R2,[R1],#4
LDR R5,=0X40000000
LOOP LDR R3,[R1],#4
CMP R2,R3
MOVCC R2,R2
MOVCS R2,R3
SUBS R0,R0,#0X01
BNE LOOP
STOP B STOP
ARRAY DCD 0X55554411,0X44567890,0X12341111,0X11111111,0X22222222
END
CODE2:
AREA LARGEST,CODE
ENTRY
MOV R5,0X05;
LDR R1,=0X40000000;
LDR R2,[R1],#04;
LOOP LDR R4,[R1],#04
CMP R2,R4
BCC LOOP1
MOV R2,R4
LOOP1 SUBS R5,R5,#1
BNE LOOP
STOP B STOP
END
MEMORY TIME
CODE1 68B 4.08us
CODE2 40B 48ms

15.ARM CODE TO FIND NUMBER OF ZEROES AND ONES IN 8 BIT DATA

AREA ZO,CODE,READONLY

ENTRY

MOVS R0,R0,LSR #0X01

ADDCS R1,R1,#0X01

ADDCC R2,R2,#0X01

MOVS R0,R0,LSR #0X01

ADDCS R1,R1,#0X01

ADDCC R2,R2,#0X01

MOVS R0,R0,LSR #0X01

ADDCS R1,R1,#0X01

ADDCC R2,R2,#0X01

MOVS R0,R0,LSR #0X01

ADDCS R1,R1,#0X01

ADDCC R2,R2,#0X01

STOP B STOP
END

CODE2:

AREA ZO,CODE,READONLY

ENTRY

LDR R0,=0X40000000

LDR R1,[R0]

MOV R2,#0X08

LOP MOVS R1,R1,LSR #0X01

ADDCC R4,R4,#0X01

ADDCS R5,R5,#0X01

SUBS R2,R2,#0X01

BNE LOP

STOP B STOP

END
MEMORY TIME
CODE1 52B 0.913us
CODE2 36B 4.92us

16.ARM CODE TO FIND THE NUMBER OF EVEN NUMBERS IN AN ARRAY OF 5 32 BIT NUMBERS

AREA EV32,CODE,READONLY

ENTRY

MOV R0,#0X05

LDR R1,=ARRAY

LOOP LDR R2,[R1],#4

MOVS R3,R2,ROR #0X01

ADDCC R4,R4,#0X01

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

ARRAY DCD 0X11111111,0X12345678,0X12341120,0X1234781,0X12121234

END

MEMORY TIME
CODE 56B 3.917us
17. ARM CODE TO FIND THE NUMBER OF ODD NUMBERS IN AN ARRAY OF 5 32 BIT NUMBERS

AREA EV32,CODE,READONLY

ENTRY

MOV R0,#0X05

LDR R1,=ARRAY

LOOP LDR R2,[R1],#4

MOVS R3,R2,ROR #0X01

ADDCS R4,R4,#0X01

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

ARRAY DCD 0X11111111,0X12345678,0X12341120,0X1234781,0X12121234

END
MEMORY TIME
CODE 56B 3.917us
18.ARM CODE TO FIND THE NUMBER OF POSITIVE NUMBERS IN AN ARRAY OF 5 32 BIT NUMBERS

AREA POS32,CODE,READONLY

ENTRY

MOV R0,#0X05

LDR R1,=ARRAY

LOOP LDR R2,[R1],#4

CMP R2,#0X00

ADDPL R3,R3,#0X01

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

ARRAY DCD 0X12345678,0XFFFFFFFC,0X12341120,0X12347815,0X12121234

END
memory Time
code 56b 3.917us

19.ARM CODE TO FIND NUMBER OF NEGATIVE NUMBERS IN AN ARRAY OF 5 32 BIT NUMBERS

AREA POS32,CODE,READONLY

ENTRY

MOV R0,#0X05

LDR R1,=ARRAY

LOOP LDR R2,[R1],#4

CMP R2,#0X00

ADDMI R3,R3,#0X01

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

ARRAY DCD 0X12345678,0XFFFFFFFC,0X12341120,0X12347815,0X12121234

END
memory Time
code 56b 3.917us
20. .ALP TO ADD TWO ARRAY ELEMENTS AND SAVE THE ANSWER IN THIRD ARRAY

AREA ARRAYSUM,CODE,READONLY

ENTRY

LDR R3,=0X40000000

LDR R2,=ARRAY1

LDR R4,=ARRAY2

MOV R5,#0X05

ADD LDR R0,[R2],#4

LDR R6,[R4],#4

ADD R7,R0,R6

STR R7,[R3],#4

SUBS R5,R5,#1

BNE ADD

STOP B STOP

ARRAY1 DCD 0X01,0X02,0X03,0X04,0X05

ARRAY2 DCD 0X05,0X04,0X03,0X02,0X01

END
MEMORY TIMETAKEN
CODE1 92B 7.754us

21 .ALP TO FIND THE SUM OF ALL EVEN NUMBERS IN AN ARRAY

AREA EVSUM,CODE,READONLY

ENTRY

MOV R3,#0

MOV R5,#0X05

LDR R0,=0X40000000

LOOP LDR R2,[R0],#4

MOVS R6,R2,ROR #1

ADDCC R3,R3,R2

SUBS R5,R5,#0X01

BNE LOOP

STOP B STOP

END
MEMORY TIME TAKEN
CODE 36bytes 3.833us

22. ALP TO FIND THE SUM OF ALL ODD NUMBERS IN AN ARRAY

AREA ODSUM,CODE,READONLY

ENTRY

MOV R3,#0

MOV R5,#0X05

LDR R0,=0X40000000

LOOP LDR R2,[R0],#4

MOVS R6,R2,ROR #1

ADDCC R3,R3,R2

SUBS R5,R5,#0X01

BNE LOOP

STOP B STOP

END
MEMORY TIME TAKEN
CODE 36bytes 3.833us

23. ALP TO FIND THE SUM OF ALL THE NEGATIVE NUMBERS IN AN ARRAY

AREA NEG,CODE,READONLY

ENTRY

MOV R3,#0

MOV R0,#0X05

LDR R1,=0X40000000

LOOP LDR R2,[R1],#4

CMP R2,#0X00

ADDMI R3,R3,R2

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

END

MEMORY TIME TAKEN


CODE 36bytes 3.833us
24.ALP TO FIND THE SUM OF ALL THE POSITIVE NUMBERS IN AN ARRAY

AREA EVSUM,CODE,READONLY

ENTRY

MOV R3,#0

MOV R0,#0X05

LDR R1,=0X40000000

LOOP LDR R2,[R1],#4

CMP R2,#0X00

ADDPL R3,R3,R2

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

END

MEMORY TIME TAKEN


CODE 36bytes 3.833us

25. ALP TO SORT ARRAY IN ASCENDING ORDER

AREA ASC,CODE,READONLY

ENTRY

MOV R0,#0X05

LOOP LDR R5,=0X40000000


ADD R6,R5,#4

MOV R3,#0X04

IN LDR R1,[R5]

LDR R2,[R6]

CMP R1,R2

BCC LOP

MOV R4,R2

MOV R2,R1

MOV R1,R4

LOP STR R1,[R5]

STR R2,[R6]

ADD R5,R5,#4

ADD R6,R6,#4

SUBS R3,R3,#0X01

BNE IN

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

END
MEMORY TIME TAKEN
CODE 80bytes 35.585us

26.ALP TO SORT ARRAY IN DESCENDING ORDER

AREA ASC,CODE,READONLY

ENTRY

MOV R0,#0X05

LOOP LDR R5,=0X40000000

ADD R6,R5,#4

MOV R3,#0X04

IN LDR R1,[R5]

LDR R2,[R6]

CMP R1,R2

BCS LOP

MOV R4,R2

MOV R2,R1

MOV R1,R4

LOP STR R1,[R5]

STR R2,[R6]

ADD R5,R5,#4

ADD R6,R6,#4

SUBS R3,R3,#0X01

BNE IN

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

END
MEMORY TIME TAKEN
CODE 80bytes 35.997us

27.SORT ARRAY IN HALF ASCENDING HALF DESCENDING ORDER

AREA ASC,CODE,READONLY

ENTRY

MOV R0,#0X03

LOOP1 LDR R5,=0X40000000

ADD R6,R5,#4

MOV R3,#0X02

IN1 LDR R1,[R5]

LDR R2,[R6]

CMP R1,R2

BCC LOP1

MOV R4,R2

MOV R2,R1

MOV R1,R4

LOP1 STR R1,[R5]

STR R2,[R6]

ADD R5,R5,#4
ADD R6,R6,#4

SUBS R3,R3,#0X01

BNE IN1

SUBS R0,R0,#0X01

BNE LOOP1

MOV R0,#0X02

LOOP LDR R5,=0X4000000c

ADD R6,R5,#4

MOV R3,#0X01

IN LDR R1,[R5]

LDR R2,[R6]

CMP R1,R2

BCS LOP

MOV R4,R2

MOV R2,R1

MOV R1,R4

LOP STR R1,[R5]

STR R2,[R6]

ADD R5,R5,#4

ADD R6,R6,#4

SUBS R3,R3,#0X01

BNE IN

SUBS R0,R0,#0X01

BNE LOOP

STOP B STOP

END

MEMORY TIME
CODE 156 15.2us
28.(25)DEVELOP A ARM CODE FOR:

a) AREA CCODE,CODE,READONLY

ENTRY

MOV R0,#00; (a)

CMP R0,#00

BEQ LOOP

SUB R1,R0,#1

B STOP

LOOP ADD R2,R0,#1

STOP B STOP

END
MEMORY TIME
28B 0.416us

b) AREA CCODE,CODE,READONLY

ENTRY

MOV R0,#06;(a)

CMP R0,#5

BPL LOOP1

SUB R1,R0,#1

B STOP

LOOP1 ADD R2,R0,#1

STOP B STOP

END
MEMORY TIME
CODE 28B 0.416us

29.GENERATE 10 FIBONACCI SERIES

AREA FIBBO,CODE

ENTRY

MOV R0,#00

SUB R0,R0,#01

MOV R1,#01

MOV R4,#10

LDR R2,=0X40000000

BACK ADD R0,R0,R1

STR R0,[R2],#4

MOV R3,R0

MOV R0,R1

MOV R1,R3

SUBS R4,R4,#01

BNE BACK

STOP B STOP

END
MEMORY TIME
CODE 52B 8.58us

30.GENERATE FIST 10 EVEN NUMBERS

AREA GENE_EVEN,CODE,READONLY

ENTRY

MOV R0,#2

LDR R1,=0X40000000

MOV R2,#10

LOOP STRB R0,[R1],#1

ADD R0,R0,#2

SUBS R2,R2,#1

BNE LOOP

STOP B STOP

END
MEMORY TIME
CODE 32B 5.915us

31.GENERATE FIRST 10 ODD NUMBERS

AREA ODD,CODE,READONLY

ENTRY

MOV R0,#1

LDR R1,=0X40000000

MOV R2,#10

LOOP STRB R0,[R1],#1

ADD R0,R0,#2

SUBS R2,R2,#1

BNE LOOP

STOP B STOP

END

MEMORY TIME
CODE 32B 5.915us
32.FINDING SQUARE OF A NUMBER WITHOUT USING MULTIPLICATION

AREA SQUARE_MUL,CODE,READONLY

ENTRY

MOV R0,#3

MOV R1,#00

MOV R2,R0

LOOP ADD R1,R1,R0

SUBS R2,R2,#1

BNE LOOP

STOP B STOP

END

MEMORY TIME
CODE 28B 1.332us
33.MULTIPLY A NUMBER BY 23 USING SHIFT LOGIC

AREA SHIFT23,CODE,READONLY

ENTRY

MOV R0,#3

MOV R1,R0

MOV R2,R0

MOVS R1,R1,LSL#4

MOVS R2,R2,LSL #3

ADD R2,R1,R2

SUBS R3,R2,R0

STOP B STOP

END

MEMORY TIME
CODE 32B 0.581us
34.DEVELOP ARM CODE FOR THE FOLLOWING C PROGRAM CODES

a)

AREA C1,CODE,READONLY

ENTRY

MOV R1,#0X02

MOV R2,#0X05

MUL R0,R1,R2

SBS

END

MEMORY TIME
CODE 16B 0.167us

b)

AREA C1,CODE,READONLY

ENTRY

MOV R4,#0X02

MOV R2,#0X0A

MUL R3,R4,R2

SBS

END
MEMORY TIME
CODE 16B 0.333

c)
AREA C1,CODE,READONLY
ENTRY
MOV R3,#0X02
MOV R2,#0X0F
MUL R7,R3,R2
SBS
END
MEMORY TIME
CODE 16B 0.333
d)
AREA C1,CODE,READONLY
ENTRY
MOV R0,#5
MOV R1,#2
CMP R0,R1
BPL LOOP1
MOV R3,#7
MUL R4,R3,R1
ADD R2,R0,R4
B STOP
LOOP1 MOV R5,#4
MUL R6,R5,R1
ADD R2,R0,R6
STOP B STOP
END
MEMORY TIME
CODE 48B 0.832us

e)
AREA CCODE,CODE,READONLY
MOV R5,#2
MOV R6,#5
MOV R0,#1;A
MOV R1,#1;B
MOV R2,#1;C
CMN R5,R6
BEQ LOOP1
LOOP MUL R3,R0,R1
MUL R4,R1,R2
MUL R7,R0,R2
ADD R8,R3,R4
ADD R9,R8,R7
LOOP1
EOR R3,R0,R1
EOR R3,R3,R2
STOP B STOP
END

MEMORY TIME
CODE 60B 1.414us

35.SEARCH A GIVEN CHARACTER IN A STRING

AREA SEARCHSTRING,CODE,READONLY

ENTRY

LDR R0,=STRING

LOOP LDRB R2,[R0],#1

CMP R2,#'B'

ADDEQ R3,R3,#1

CMP R2,#0

BNE LOOP

STOP B STOP

STRING DCB "BVB",0

END
MEMORY TIME
CODE 36B 2.582us

36.FIND THE NUMBER OF BLANK SPACES IN STRING

AREA COUNT,CODE,READONLY

ENTRY

SPACE EQU ''

LDR R0,=STRING

LOOP LDRB R2,[R0],#1

CMP R2,#SPACE

ADDEQ R3,R3,#1

CMP R2,#0

BNE LOOP

STOP B STOP

STRING DCB "BVB CET ",0

END
MEMORY TIME
CODE 44B 4.833us

37.COMPARE TWO STRINGS FOR LENGTH AND CONTENT

AREA CMP_STR,CODE,READONLY

ENTRY

LDR R0,=STRING1

LDR R1,=STRING2

MOV R9,R0

MOV R10,R1

MOV R8,#0

LOOP LDRB R2,[R0],#1

CMP R2,#0

ADD R3,R3,#1

BNE LOOP

LOOP1 LDRB R4,[R1],#1

CMP R4,#0

ADD R5,R5,#1

BNE LOOP1

CMP R3,R5
BNE STOP

LOOP2 LDRB R6,[R9],#1

LDRB R7,[R10],#1

CMP R6,R7

ADDEQ R8,R8,#1

CMP R6,#0

BNE LOOP2

CMP R8,R3

ADDEQ R11,R11,#1

STOP B STOP

STRING1 DCB "BVBCET",0

STRING2 DCB "BVB",0

END

MEMORY TIME
CODE 116B 8.08us

38.REVERSE THE STRING

AREA REV,CODE

ENTRY

LDR R0,=STRING
LDR R10,=0X40000000

MOV R2,#00

LOOP LDRB R1,[R0],#1

CMP R1,#0

ADDNE R3,R3,#1

BNE LOOP

SUBS R0,R0,#2

LOOP1 LDRB R1,[R0],#-1

STRB R1,[R10],#1

SUBS R3,R3,#1

BNE LOOP1

STOP B STOP

STRING DCB "KLETECH",0

END

MEMORY TIME
CODE 64B 10.749us

39.LENGTH OF CARRIAGE RETURN STRING

AREA STRING,CODE

ENTRY
LDR R0,=STRIN

MOV R1,#00

LOOP LDRB R2,[R0],#1

CMP R2,#0X0D ;ASCILL OF CARRIAGE RETURN IS 13=0X0D

BEQ STOP

ADD R1,#1

B LOOP

STOP B STOP

STRIN DCB "ABCBD",'\r'

END

MEMORY TIME
CODE 44B 4.667us

40.T0 CHECK IF STRING IS PALINDROME OR NOT

AREA PALIN,CODE,READONLY

ENTRY

LDR R0,=0X40000000

LDR R1,=ARRAY

MOV R10,R1

LEN LDRB R2,[R1],#1


CMP R2,#00

ADDNE R3,R3,#1;STRING LENGTH

BNE LEN

MOV R4,R3

MOV R1,R10

SEC LDRB R2,[R1],#1

STRB R2,[R0],#1

SUBS R3,R3,#1

BNE SEC

MOV R1,R10

SUB R0,R0,#1

CCMP LDRB R5,[R0],#-1

LDRB R6,[R1],#1

CMP R5,R6

ADDNE R7,R7,#1;NOT A PALINDROME IF R7=0

SUBS R4,R4,#1

BNE CCMP

ARRAY DCB "MARK",0

END
MEMORY TIME
CODE 96B 13.746us

41.BLOCK EXCHANGE

a) DATA TO STACK

1.WITH LDM/STM DATA TO STACK

AREA BT,CODE,READONLY

ENTRY

LDR R13,=0X40000020

LDR R7,=0X40000000

LDMFD R13,{R1-R3}

MOV R6,R1

SWP R1,R6,[R7]

ADD R7,#4

MOV R6,R2

SWP R2,R6,[R7]

ADD R7,#4

MOV R6,R3

SWP R3,R6,[R7]

STMIA R13,{R1-R3}

S B S

END
MEMORY TIME
CODE 52B 2.33us

2. WITHOUT USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

MOV R3,#3

LDR R5,=0X40000020

LDR R7,=0X40000000

LOP LDR R1,[R5]

MOV R6,R1

SWP R1,R6,[R7]

STR R1,[R5]

ADD R5,#4

ADD R7,#4

SUBS R3,#1

BNE LOP

S B S

END
MEMORY TIME
CODE 48B 4.082us

b)DATA TO DATA

1. WITHOUT USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

MOV R3,#3

LDR R5,=0X40000020

LDR R7,=0X40000000

LOP LDR R1,[R5]

MOV R6,R1

SWP R1,R6,[R7]

STR R1,[R5]

ADD R5,#4

ADD R7,#4

SUBS R3,#1

BNE LOP

S B S

END
MEMORY TIME
CODE 48B 4.082us

2. USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R5,=0X40000020

LDR R7,=0X40000000

LDM R5,{R1-R3}

MOV R6,R1

SWP R1,R6,[R7]

ADD R7,#4

MOV R6,R2

SWP R2,R6,[R7]

ADD R7,#4

MOV R6,R3

SWP R3,R6,[R7]

STM R5,{R1-R3}

S B S

END
MEMORY TIME
C0DE 52B 2.33us

42.BLOCK TRANSFER

a)DATA TO DATA MEMORY

1.USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R5,=0X40000020

LDR R7,=0X40000000

LDMIA R7,{R2-R4}

STMIA R5,{R2-R4}

SBS

END
MEMORY TIME
CODE 20B 0.916us

2.WITHOUT USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R1,=0X40000020

LDR R0,=0X40000000

MOV R5,#0X03

LOOP LDR R2,[R0],#4

STR R2,[R1],#4

SUBS R5,#0X01

BNE LOOP

SBS

END
MEMORY TIME
CODE 32B 2.332us

b)CODE TO DATA

1.WITHOUT LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R1,=ARRAY

LDR R0,=0X40000000

MOV R5,#0X03

LOOP LDR R2,[R1],#4

STR R2,[R0],#4

SUBS R5,#0X01

BNE LOOP

SBS

ARRAY DCD 0X01,0X02,0X03

END
MEMORY TIME
CODE 48B 2.499us

2.WITH LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R1,=ARRAY

LDR R0,=0X40000000

MOV R5,#0X03

LDMIA R1,{R2-R4}

STMIA R0,{R2-R4}

SBS

ARRAY DCD 0X01,0X02,0X03

END
MEMORY TIME
CODE 40B 1.166us

c)DATA TO STACK

1.USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R1,=0X40000010

LDR R0,=0X40000000

MOV R5,#0X03

LDMFD R1,{R2-R4}

STMIA R0,{R2-R4}

SBS

END
MEMORY TIME
CODE 24B 0.999uS

2.WITHOUT USING LDM/STM

AREA BT,CODE,READONLY

ENTRY

LDR R1,=0X40000020

LDR R0,=0X40000000

MOV R5,#0X03

LOOP LDR R2,[R0],#4

STR R2,[R1],#4

SUBS R5,#0X01

BNE LOOP

SBS

END
MEMORY TIME
CODE 32B 2.332uS

THUMB PROGRAMS:

Q) ATTEMPT ALL THE QUESTIONS IN THUMB INSTRUCTION MODE

1. ADD TWO 32 BIT NUMBERS

AREA T32ADD,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R1,=0X30000000

LDR R2,=0X20000000

ADD R1,R2

LDR R3,=ARM

BX R3
CODE32

ARM LDR R4,=0X40000000

STR R1,[R4]

STOP B STOP

END

MEMORY TIME
CODE 48BYTES 2.083 MICROSECOND

2. SUBTRACT TWO 32 BIT NUMBERS

AREA T32SUB,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R1,=0X30000000

LDR R2,=0X20000000

SUB R1,R2

LDR R3,=ARM
BX R3

CODE32

ARM LDR R4,=0X40000000

STR R1,[R4]

STOP B STOP

END

MEMORY TIME
CODE 48BYTES 2.083 MICROSECOND

3. ADD TWO 64BIT NUMBERS

AREA T64ADD,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R1,=0X30000000

LDR R2,=0X20000000

LDR R3,=0X40000001
LDR R4,=0X10000000

ADD R1,R2

ADC R3,R4

LDR R5,=ARM

BX R5

CODE32

ARM LDR R6,=0X40000000

STR R1,[R6]

ADD R6,#0X04

STR R3,[R6]

STOP B STOP

END

MEMORY TIME
CODE 68BYTES 2.666 MICROSECOND

4. SUBTRACT TWO 64BIT NUMBERS

AREA T64SUB,CODE,READONLY

ENTRY

CODE32
LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R1,=0X30000000

LDR R2,=0X20000000

LDR R3,=0X40000001

LDR R4,=0X10000000

SUB R1,R2

SBC R3,R4

LDR R5,=ARM

BX R5

CODE32

ARM LDR R6,=0X40000000

STR R1,[R6]

ADD R6,#0X04

STR R3,[R6]

STOP B STOP

END
MEMORY TIME
CODE 68BYTES 2.666 MICROSECOND

5. TO CHECK POSITIVE

CODE1: TO CHECK IF A NUMBER IS POSITIVE

AREA TPOS,CODE,READONLY

ENTRY

CODE32

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

CMP R2,#0X00

BPL POS

BMI NEG

POS MOV R3,#0X01 ; THE NUMBER IS POSITIVE IS INDIATED WHEN R3=0X00000001

NEG B STOP

STOP B STOP

END
CODE2:TO CHECK OF A GIVEN NUMBER IS POSITIVE OR NOT(CODE2)

AREA TPS,CODE,READONLY

ENTRY

CODE32

LDR R3,=0XFFFFFFFF

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

AND R3,R2

LSL R3,#1

BCC POS

BCS NEG

POS MOV R4,#0X01 ; THE NUMBER IS POSITIVE IS INDIATED WHEN R3=0X00000001

NEG B STOP

STOP B STOP

END
MEMORY TIME
CODE 1 32BYTES 1.583 MICROSECOND
CODE 2 36 BYTES 1.748 MICROSECOND

CODE1:TO FIND NUMBER OF POSITIVE NUMBERS IN AN ARRAY OF 5 NUMBERS

AREA TPS,CODE,READONLY

ENTRY

CODE32

MOV R5,#0X05

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

ADD R1,#0X04

CMP R2,#0X00

BPL POS

BMI N

POS ADD R4,#0X01


SUB R5,#0X01

BNE THUMB

BEQ STOP

N SUB R5,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

CODE 2: TO FIND NUMBER OF POSITIVE NUMBERS IN AN ARRAY OF 5 NUMBERS

AREA TPS,CODE,READONLY

ENTRY

CODE32

MOV R5,#0X05

LDR R3,=0XFFFFFFFF

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]


ADD R1,#0X04

AND R3,R2

LSL R3,#1

BCC POS

BCS NE

POS ADD R4,#0X01

SUB R5,#0X01

BNE THUMB

BEQ STOP ;

NE SUB R5,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 1 48BYTES 5.583 MICROSECOND
CODE 2 52 BYTES 4.583 MICROSECOND

6. TO CHECK NEGATIVE
CODE 1: TO CHECK IF A GIVEN NUMBER IS NEGATIVE OR NOT

AREA TNEG,CODE,READONLY

ENTRY

CODE32

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

CMP R2,#0X00

BMI NEG

BPL POS

NEG MOV R3,#0X01 ;

POS B STOP

STOP B STOP END

CODE 2: TO CHECK OF A GIVEN NUMBER IS NEGATIVE OR NOT

AREA TPS,CODE,READONLY

ENTRY

CODE32

LDR R3,=0XFFFFFFFF
LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

AND R3,R2

LSL R3,#1

BCS NEG

BCC POS

NEG MOV R4,#0X01 ; THE NUMBER IS NEGATIVE IS INDIATED WHEN R3=0X00000001

POS B STOP

STOP B STOP

END

MEMORY TIME
CODE 1 32BYTES 1.582 MICROSECOND
CODE 2 36 BYTES 1.748 MICROSECOND

CODE 1:TO FIND THE NUMBER OF NEGATIVE NUMBERS IN AN ARRAY

AREA TPS,CODE,READONLY
ENTRY

CODE32

MOV R5,#0X05

LDR R3,=0XFFFFFFFF

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

ADD R1,#0X04

AND R3,R2

LSL R3,#1

BCC POS

BCS NE

POS SUB R5,#0X01

BNE THUMB

BEQ STOP

NE ADD R4,#0X01

SUB R5,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
CODE 2:TO FIND THE NUMBER OF NEGATIVE NUMBERS IN AN ARRAY

AREA TPS,CODE,READONLY

ENTRY

CODE32

MOV R5,#0X05

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

ADD R1,#0X04

CMP R2,#0X00

BPL POS

BMI N

POS SUB R5,#0X01

BNE THUMB

BEQ STOP

N ADD R4,#0X01

SUB R5,#0X01
BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 1 52BYTES 6.415 MICROSECOND
CODE 2 48 BYTES 5.917 MICROSECOND

7. TO CHECK EVEN OR ODD

CODE1: TO CHECK IF A NUMBER IS EVEN OR ODD

AREA TPS,CODE,READONLY

ENTRY

CODE32

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

LSR R2,#1
BCC EVE

BCS ODD

EVE MOV R3,#0X01

B STOP ; THE NUMBER IS EVEN IS INDIATED WHEN R3=0X00000001

ODD MOV R4,#0X01

B STOP ; THE NUMBER IS ODD IS INDIATED WHEN R4=0X00000001

STOP B STOP

END

CODE 2:

AREA TPS,CODE,READONLY

ENTRY

CODE32

LDR R7,=0X11111111

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

AND R2,R7
LSR R2,#1

BCC EVE

BCS ODD

EVE MOV R3,#0X01

B STOP ; THE NUMBER IS EVEN IS INDIATED WHEN R3=0X00000001

ODD MOV R4,#0X01

B STOP ; THE NUMBER IS ODD IS INDIATED WHEN R4=0X00000001

STOP B STOP

END

MEMORY TIME
CODE 1 36BYTES 1.415 MICROSECOND
CODE 2 44 BYTES 1.748 MICROSECOND

CODE 1:TO FIND THE NUMBER OF EVEN AND ODD NUMBERS IN AN ARRAY

AREA TPS,CODE,READONLY

ENTRY

CODE32

MOV R5,#0X05

LDR R3,=0X11111111

LDR R1,=0X40000000
LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

ADD R1,#0X04

AND R3,R2

LSR R3,#1

LDR R3,=0X11111111

BCC EVN

BCS NE

EVN ADD R4,#0X01 ; EVEN

SUB R5,#0X01

BNE THUMB

BEQ STOP

NE ADD R6,#0X01 ; ODD

SUB R5,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
CODE 2:

AREA TPS,CODE,READONLY

ENTRY

CODE32

MOV R5,#0X05

LDR R1,=0X40000000

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LDR R2,[R1]

ADD R1,#0X04

LSR R2,#1

BCS ODD

BCC EVN

EVN ADD R4,#0X01

SUB R5,#0X01

BNE THUMB

BEQ STOP

ODD ADD R6,#0X01


SUB R5,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 1 60BYTES 8.167MICROSECOND
CODE 2 48 BYTES 5.834 MICROSECOND

8. TO FIND MINIMUM AND MAXIMUM

CODE 1: TO FIND MAXIMUM OF TWO NUMBERS

AREA MAX2,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=THUMB+1

BX R1

CODE16

THUMB LDR R1,[R0]

ADD R0,#0X04
LDR R2,[R0]

CMP R1,R2

BCC L2

BCS L1

L2 MOV R3,R2

B STOP

L1 MOV R3,R1

B STOP

STOP B STOP

END

CODE 2:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=THUMB+1

BX R1

CODE16

THUMB LDR R1,[R0]


MOV R4,R1

ADD R0,#0X04

LDR R2,[R0]

MOV R5,R2

SUB R4,R5

BCC L2

BCS L1

L2 MOV R3,R2

B STOP

L1 MOV R3,R1

B STOP

STOP B STOP

END

MEMORY TIME
CODE 1 40BYTES 1.748MICROSECOND
CODE 2 44 BYTES 1.665MICROSECOND

B)FIND MAXIMUM IN AN ARRAY

CODE 1:

AREA MAX2,CODE,READONLY
ENTRY

CODE32

MOV R7,#0X05

LDR R0,=0X40000000

LDR R3,[R0]

LDR R1,=THUMB+1

BX R1

CODE16

THUMB ADD R0,#0X04

LDR R2,[R0]

MOV R4,R3

SUB R4,R2

BMI L2

BPL L1

L2 MOV R3,R2

SUB R7,#0X01

BNE THUMB

BEQ STOP

L1 SUB R7,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
CODE 2:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

MOV R7,#0X05

LDR R0,=0X40000000

LDR R3,[R0]

LDR R1,=THUMB+1

BX R1

CODE16

THUMB ADD R0,#0X04

LDR R2,[R0]

MOV R4,R3

CMP R4,R2

BMI L2

BPL L1

L2 MOV R3,R2

SUB R7,#0X01

BNE THUMB
BEQ STOP

L1 SUB R7,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 1 52BYTES 6.665 MICROSECOND
CODE 2 52BYTES 6.667 MICROSECOND

TO FIND MINUMIN OF TWO NUMBERS

CODE 1:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=THUMB+1

BX R1

CODE16

THUMB LDR R1,[R0]


ADD R0,#0X04

LDR R2,[R0]

CMP R1,R2

BCS L2

BCC L1

L2 MOV R3,R2

B STOP

L1 MOV R3,R1

B STOP

STOP B STOP

END

CODE 2:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=THUMB+1

BX R1

CODE16
THUMB LDR R1,[R0]

MOV R4,R1

ADD R0,#0X04

LDR R2,[R0]

MOV R5,R2

SUB R4,R5

BCS L2

BCC L1

L2 MOV R3,R2

B STOP

L1 MOV R3,R1

B STOP

STOP B STOP

END

MEMORY TIME
CODE 1 40BYTES 1.499 MICROSECOND
CODE 2 44BYTES 1.998 MICROSECOND

TO FIND MINIMUM OF 5 NUMBERS IN AN ARRAY


CODE 1:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

MOV R7,#0X05

LDR R0,=0X40000000

LDR R3,[R0]

LDR R1,=THUMB+1

BX R1

CODE16

THUMB ADD R0,#0X04

LDR R2,[R0]

MOV R4,R3

SUB R4,R2

BPL L2

BMI L1

L2 MOV R3,R2

SUB R7,#0X01

BNE THUMB

BEQ STOP

L1 SUB R7,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
CODE 2:

AREA MAX2,CODE,READONLY

ENTRY

CODE32

MOV R7,#0X05

LDR R0,=0X40000000

LDR R3,[R0]

LDR R1,=THUMB+1

BX R1

CODE16

THUMB ADD R0,#0X04

LDR R2,[R0]

MOV R4,R3

CMP R4,R2

BMI L2

BPL L1

L2 MOV R3,R2

SUB R7,#0X01

BNE THUMB
BEQ STOP

L1 SUB R7,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 1 52BYTES 6.834 MICROSECOND
CODE 2 52BYTES 6.667 MICROSECOND

9. CODE FOR DIVISION

AREA DIV,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB MOV R1,#0X06

MOV R2,#0X03

CMP R2,#0X00
BEQ STOP

BNE LQ

LQ CMP R1,R2

BEQ LOP

BNE DI

LOP MOV R3,#0X01

DI SUB R1,R2

CMP R1,#0X00

BPL AD

BMI STOP

AD ADD R3,#0X01

B DI

STOP B STOP

END

MEMORY TIME
CODE 44 BYTES 3.248 MICROSECOND

10. CODE FOR MULTIPLICATION

AREA MUL,CODE,READONLY

ENTRY
CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB MOV R1,#0X02

MOV R2,#0X03

CMP R2,#0X00

BEQ STOP

BNE LQ

LQ ADD R3,R1

SUB R2,#0X01

BNE LQ

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 32 BYTES 2.081 MICROSECOND

11. PROGRAM TO ADD TWO ARRAYS AND SAVE THE RESULT IN THIRD ONE

AREA AD,CODE,READONLY
ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=0X40000010

LDR R6,=0X40000020

MOV R2,#0X05

LDR R3,=THUMB+1

BX R3

CODE16

THUMB LDR R4,[R0]

ADD R0,#0X04

LDR R5,[R1]

ADD R1,#0X04

ADD R4,R5

STR R4,[R6]

ADD R6,#0X04

SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
MEMORY TIME
CODE 52 BYTES 7.416 MICROSECOND

12. PROGRAM TO COUNT THE NUMBER OF ONES AND ZEROES

AREA ZO,CODE,READONLY

ENTRY

CODE32

MOV R1,#0X0E

MOV R4,#0X04

LDR R0,=THUMB+1

BX R0

CODE16

THUMB LSR R1,#1

BCC Z

BCS ONE

Z ADD R2,#0X01

SUB R4,#0X01

BNE THUMB

BEQ STOP

ONE ADD R3,#0X01


SUB R4,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 44 BYTES 3.664 MICROSECOND

13. CODE FOR THE SUM OF NEGATIVE NUMBERS IN AN ARRAY

AREA ADODD,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R2,#0X05

LDR R3,=THUMB+1

BX R3

CODE16

THUMB LDR R4,[R0]

ADD R0,#0X04

MOV R6,R4
LSL R4,#1

BCS ODD

BCC LOP

ODD ADD R5,R6

SUB R2,#0X01

BNE THUMB

BEQ STOP

LOP SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 48 BYTES 6.415 MICROSECOND

14. CODE TO FIND THE SUM OF POSITIVE NUMBERS IN AN ARRAY

AREA ADODD,CODE,READONLY

ENTRY

CODE32
LDR R0,=0X40000000

MOV R2,#0X05

LDR R3,=THUMB+1

BX R3

CODE16

THUMB LDR R4,[R0]

ADD R0,#0X04

MOV R6,R4

LSL R4,#1

BCC ODD

BCS LOP

ODD ADD R5,R6

SUB R2,#0X01

BNE THUMB

BEQ STOP

LOP SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
MEMORY TIME
CODE 48 BYTES 6.415 MICROSECOND

15. CODE TO FIND THE SUM OF ODD NUMBERS

AREA ADODD,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R2,#0X05

LDR R3,=THUMB+1

BX R3

CODE16

THUMB LDR R4,[R0]

ADD R0,#0X04

MOV R6,R4

LSR R4,#1

BCS ODD

BCC LOP

ODD ADD R5,R6

SUB R2,#0X01
BNE THUMB

BEQ STOP

LOP SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 48 BYTES 6.584 MICROSECOND

16. CODE TO FIND THE SUM OF ALL EVEN NUMBERS IN AN ARRAY

AREA ADODD,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R2,#0X05

LDR R3,=THUMB+1

BX R3

CODE16

THUMB LDR R4,[R0]


ADD R0,#0X04

MOV R6,R4

LSR R4,#1

BCC EV

BCS LOP

EV ADD R5,R6

SUB R2,#0X01

BNE THUMB

BEQ STOP

LOP SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 48 BYTES 6.584 MICROSECOND

17. CODE TO GENERATE FIRST 10 EVEN NUMBERS


AREA GEN,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R2,#0X0A

MOV R1,#0X00

LDR R3,=THUMB+1

BX R3

CODE16

THUMB STR R1,[R0]

ADD R0,#0X04

ADD R1,#0X02

SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 40 BYTES 5.828 MICROSECOND
18. CODE TO GEERATE FIRST 10 ODD NUMBERS

AREA GEN,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R2,#0X0A

MOV R1,#0X01

LDR R3,=THUMB+1

BX R3

CODE16

THUMB STR R1,[R0]

ADD R0,#0X04

ADD R1,#0X02

SUB R2,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END

MEMORY TIME
CODE 40 BYTES 5.828 MICROSECOND
19. CODE TO GENERATE FIBONACCI SERIES

AREA GEN,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

MOV R3,#0X01

ADD R0,#0X04

MOV R2,#0X00

STR R2,[R0]

ADD R0,#0X04

MOV R6,#0X08

LDR R5,=THUMB+1

BX R5

CODE16

THUMB STR R3,[R0]

ADD R0,#0X04

MOV R4,R3

ADD R3,R2

MOV R2,R4

SUB R6,#0X01

BNE THUMB

BEQ STOP

STOP B STOP

END
MEMORY TIME
CODE 60 BYTES 7.749 MICROSECOND

20. ASCENDING ORDER

AREA ASC,CODE,READONLY

ENTRY

CODE32

LDR R0,=TH+1

BX R0

CODE16

TH MOV R1,#5

UP LDR R2,=0X40000000

MOV R3,R2

ADD R3,#0X04

MOV R7,#0X03

LOP LDR R4,[R2]

LDR R5,[R3]

CMP R4,R5

BCC COR

BCS IN
IN MOV R6,R4

MOV R4,R5

MOV R5,R6

COR STR R4,[R2]

STR R5,[R3]

ADD R2,#0X04

ADD R3,#0X04

SUB R7,#0X01

BNE LOP

BEQ SUBB

SUBB SUB R1,#0X01

BNE UP

STOP B STOP

END

MEMORY TIME
CODE 64BYTES 30.333 MICROSECOND

21. DESCENDING ORDER

AREA ASC,CODE,READONLY

ENTRY
CODE32

LDR R0,=TH+1

BX R0

CODE16

TH MOV R1,#5

UP LDR R2,=0X40000000

MOV R3,R2

ADD R3,#0X04

MOV R7,#0X04

LOP LDR R4,[R2]

LDR R5,[R3]

CMP R4,R5

BCS COR

BCC IN

IN MOV R6,R4

MOV R4,R5

MOV R5,R6

COR STR R4,[R2]

STR R5,[R3]

ADD R2,#0X04

ADD R3,#0X04

SUB R7,#0X01

BNE LOP

BEQ SUBB

SUBB SUB R1,#0X01

BNE UP

STOP B STOP

END
memory Time
Code 64bytes 30.333 microsecond

21. HALF ASCENDING HALF DESCENDING

area asc,code,readonly

entry

code32

ldr r0,=th+1

bx r0

code16

th mov r1,#3

up ldr r2,=0x40000000

mov r3,r2

add r3,#0x04

mov r7,#0x02

lop ldr r4,[r2]

ldr r5,[r3]

cmp r4,r5

bcc cor

bcs in
in mov r6,r4

mov r4,r5

mov r5,r6

cor str r4,[r2]

str r5,[r3]

add r2,#0x04

add r3,#0x04

sub r7,#0x01

bne lop

beq subb

subb sub r1,#0x01

bne up

dth mov r1,#2

dup ldr r2,=0x4000000d

mov r3,r2

add r3,#0x04

mov r7,#0x01

dlop ldr r4,[r2]

ldr r5,[r3]

cmp r4,r5

bcs dcor

bcc din

din mov r6,r4

mov r4,r5

mov r5,r6

dcor str r4,[r2]

str r5,[r3]

add r2,#0x04

add r3,#0x04

sub r7,#0x01
bne dlop

beq dsubb

dsubb sub r1,#0x01

bne dup

stop b stop

end

memory Time
Code 112bytes 17.333 microsecond

22. STRING LENGTH

area asc,code,readonly

entry

code32

dollar equ '$'

ldr r0,=string

ldr r1,=th+1

bx r1

code16
th ldrb r2,[r0]

add r0,#0x01

cmp r2,#dollar

bne ad

beq stop

ad add r3,#0x01

b th

stop b stop

string dcb "bcbcet",'$'

end

memory Time
Code 44 bytes 7.499 microsecond

23. FIND THE NUMBER OF OCCURRENCE OF A CHARACTER

area asc,code,readonly

entry

code32

dollar equ '$'

space equ ' '

ldr r0,=string
ldr r1,=th+1

bx r1

code16

th ldrb r2,[r0]

add r0,#0x01

cmp r2,#space

beq ad

bne rep

ad add r3,#0x01

b th

rep cmp r2,#dollar

bne th

beq stop

stop b stop

string dcb "tanvi shanbhag is good girl iii",'$'

end

memory Time
Code 52 bytes 9.249 microsecond

24. COMPARE STRING FOR LENGTH AND CONTENT


area asc,code,readonly

entry

code32

dollar equ '$'

ldr r0,=string1

ldr r4,=string2

ldr r1,=th+1

bx r1

code16

th ldrb r2,[r0]

add r0,#0x01

cmp r2,#dollar

bne ad

beq dth

ad add r5,#0x01

bne th

dth ldrb r2,[r4]

add r4,#0x01

cmp r2,#dollar

beq lop

bne dad

dad add r6,#0x01

bne dth

lop cmp r5,r6

bne stop

content ldr r0,=string1

ldr r4,=string2

loop ldrb r2,[r0]

add r0,#0x01

ldrb r3,[r4]

add r4,#0x01
cmp r2,r3

beq hap

bne stop

hap add r7,#0x01

sub r5,#0x01

bne loop

beq comp

comp cmp r6,r7

beq addd

bne stop

addd mov r1,#0x01

stop b stop

string1 dcb "tanvi",'$'

string2 dcb "tanv ",'$'

end

memory Time
Code 120 bytes 13.416microsecond

25. REVERSE A STRING

area strrev,code,readonly
entry

code32

ldr r1,=th+1

bx r1

code16

th ldr r0,=string

ldr r2,=0x40000000

l ldrb r3,[r0]

add r0,#0x01

cmp r3,#0

bne ad

beq reverse

ad add r4,#0x01

bl

reverse ldr r0,=string

add r0,r4

b loop

loop sub r0,#0x01

ldrb r5,[r0]

strb r5,[r2]

add r2,#0x01

sub r4,#0x01

bne loop

stop b stop

string dcb "bvb",'0'

end
memory Time
Code 68 bytes 10.665microsecond

26. CHECK IF A STRING IS A PALINDROME

area strrev,code,readonly

entry

code32

ldr r0,=s+1

bx r0

code16

s mov r0,#0

ldr r1,=string

ldr r2,=string

loop1 ldrb r3,[r1]

add r1,#1

cmp r3,#0

bne loop2

beq loop3

loop2 add r5,#1


bne loop1

loop3 mov r4,r5

sub r4,#0x01

add r2,r4

ldr r1,=string

loop5 ldrb r4,[r1]

ldrb r7,[r2]

add r1,#0x01

sub r2,#0x01

cmp r4,r7

beq loop4

bne loop6

loop4 add r6,#0x01

bne loop5

loop6 cmp r5,r6

beq yes

bne stop

yes add r0,#0x01

stop b stop

string dcb "madam",0

end
memory Time
Code 88 bytes 15.498 microsecond

27. TO ARRANGE A STRING IN ALPHABETICAL ORDER


area d,code,readonly
entry
code32
ldr r0,=thu+1
bx r0
code16
thu mov r0,#0
ldr r0,=string
ldr r2,=0x40000000
tu ldrb r3,[r0]
add r0,#1
cmp r3,#0
bne loops
beq asc
loops strb r3,[r2]
add r2,#1
add r4,#1
b tu
asc mov r0,#0
mov r0,r4
up ldr r2,=0x40000000
sub r0,#0x01
mov r3,r2
add r3,#1
mov r4,r0
loop1 ldrb r5,[r2]
ldrb r6,[r3]
cmp r5,r6
bcc cor
bcs inc
inc mov r7,r5
mov r5,r6
mov r6,r7
cor strb r5,[r2]
strb r6,[r3]
add r2,#1
add r3,#1
sub r4,#0x01
bne loop1
sub r0,#0x01
bne up
beq stop
stop b stop
string dcb "bvbcet",0
end

memory Time
Code 104 bytes 25.081 microsecond

28. DEVELOP CODE IN THUMB MODE FOR FOLLOWING CONTEXT


1. Main function should take care of block transfer of 6 words from data memory to
register bank
2. SUBROUTINE CALLED IN MAIN DOING ADDITION OF 5 WORDS

3.ON RETURN MAIN FUNCTION SHOULD STORE ADDED RESULT ON TO MEMORY

AREA CODE1,CODE,READONLY

ENTRY

CODE32

LDR R0,=MAIN+1

BX R0

CODE16

MAIN LDR R1,=0X40000000

LDMIA R1!,{R2-R6}
AD BL ADDITION

LDR R0,=0X40000020

STR R2,[R0]

STOP B STOP

ADDITION ADD R2,R3

ADD R2,R4

ADD R2,R5

ADD R2,R6

MOV PC,LR

END

MEMORY TIME
CODE 44 BYTES 2.915 MICROSECOND

29. CODE TO CHECK IF A GIVEN NUMBER IS PRIME OR NOT

AREA ASC,CODE,READONLY

ENTRY

CODE32

LDR R0,=THU+1

BX R0
CODE16

THU MOV R0,#0X00

MOV R0,#0X09

MOV R1,R0

MOV R2,#0X02

CMP R0,#0X02

BEQ PRIME

BNE CONT

PRIME MOV R6,#0X01

B STOP

NOTPRIME ADD R2,#0X01

CMP R2,R0

BPL CONT

BMI STOP

CONT MOV R3,R0

MOV R4,R2

BL DIV

CMP R3,#0X00

BNE GO

BEQ NOTPRIME

GO ADD R2,#0X01

CMP R0,R2

BNE CONT

BEQ PRIME

STOP B STOP

DIV SUB R3,R4

ADD R5,#0X01

CMP R3,R4

BPL DIV

MOV PC,LR
END

MEMORY TIME
CODE 72 BYTES 7.58 MICROSECOND

30. BLOCK TRANSFER WITH LDM/STM INSTRUCTION

1. CODE MEMORY TO DATA MEMORY

AREA MOVE,CODE,READONLY

ENTRY

CODE32

LDR R0,=DATA

LDR R1,=0X40000000

LDR R2,=THUMB+1

BX R2

CODE16

THUMB LDMIA R0!,{R2-R4}

STMIA R1!,{R2-R4}

STOP B STOP

DATA DCD 0X11,0X12,0X13

END
MEMORY TIME
CODE 44 BYTES 1.583 MICROSECOND

2. DATA MEMORY TO DATA MEMORY

AREA MOVE,CODE,READONLY

ENTRY

CODE32

LDR R0,=0X40000000

LDR R1,=0X40000010

LDR R2,=THUMB+1

BX R2

CODE16

THUMB LDMIA R0!,{R2-R4}

STMIA R1!,{R2-R4}

STOP B STOP

END
MEMORY TIME
CODE 28 BYTES 1.416 MICROSECOND

31. DEVELOP CODE TO FIND

1. R0=5R1

AREA MULT,CODE,READONLY

ENTRY

CODE32

LDR R3,=THUMB+1

BX R3

CODE16

THUMB MOV R1,#0X02

MOV R0,#0X00

MOV R2,#0X05

LQ ADD R0,R1

SUB R2,#0X01

BNE LQ

BEQ STOP
STOP B STOP

END

MEMORY TIME
CODE 28 BYTES 2.749 MICROSECOND

2. R3=10R4

AREA MULT,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB MOV R4,#0X02

MOV R3,#0X00

MOV R2,#0X0A

LQ ADD R3,R4

SUB R2,#0X01

BNE LQ

BEQ STOP
STOP B STOP

END

MEMORY TIME
CODE 28 BYTES 2.749 MICROSECOND

3. R7=10R3

AREA MULT,CODE,READONLY

ENTRY

CODE32

LDR R0,=THUMB+1

BX R0

CODE16

THUMB MOV R3,#0X02

MOV R7,#0X00

MOV R2,#0X0A

LQ ADD R7,R3

SUB R2,#0X01

BNE LQ

BEQ STOP
STOP B STOP

END

MEMORY TIME
CODE 28 BYTES 2.749 MICROSECOND

4. IF (R0>R1)

R2=R0+4R1

ELSE

R2=R0+7R1

AREA MULT,CODE,READONLY

ENTRY

CODE32

LDR R4,=THUMB+1

BX R4

CODE16
THUMB MOV R0,#0X01

MOV R1,#0X02

CMP R0,R1

BPL L1

BMI L2

L2 MOV R1,#0X02

MOV R2,#0X00

MOV R3,#0X07

LQ1 ADD R2,R1

SUB R3,#0X01

BNE LQ1

ADD R0,R2

MOV R2,R0

B STOP

L1 MOV R1,#0X02

MOV R2,#0X00

MOV R3,#0X04

LQ ADD R2,R1

SUB R3,#0X01

BNE LQ

ADD R0,R2

MOV R2,R0

STOP B STOP

END
MEMORY TIME
CODE 60 BYTES 4.246 MICROSECOND

You might also like