0% found this document useful (0 votes)
639 views24 pages

ARM7 Codes

The document provides 16 programming problems to write ARM assembly language programs. The problems cover topics like addition, subtraction, shifting, logical operations, string manipulation, arrays, and mathematical equations. For each problem, the document provides the required assembly code structure and syntax for the given task. Sample code is provided to add and subtract 32-bit numbers using direct, indirect addressing modes and a barrel shifter. Other problems include finding factorials, copying arrays, counting characters in strings, and implementing mathematical equations.

Uploaded by

Ken Adams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
639 views24 pages

ARM7 Codes

The document provides 16 programming problems to write ARM assembly language programs. The problems cover topics like addition, subtraction, shifting, logical operations, string manipulation, arrays, and mathematical equations. For each problem, the document provides the required assembly code structure and syntax for the given task. Sample code is provided to add and subtract 32-bit numbers using direct, indirect addressing modes and a barrel shifter. Other problems include finding factorials, copying arrays, counting characters in strings, and implementing mathematical equations.

Uploaded by

Ken Adams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

1.

Write a program in ARM assembly language to add and subtract two 32-bit numbers
using:
a) Direct addressing mode
Addition:
area program, code, readonly
entry
LDR R1,value1
LDR R2,value2
ADD R3,R1,R2

area program,data,readonly
value1 DCD &00000005
value2 DCD &00000004
END

1
Subtraction:
area program, code, readonly
entry
LDR R1,value1
LDR R2,value2
SUB R3,R1,R2

area program, data, readonly

value1 DCD &00000005


value2 DCD &00000004
END

2
b) Indirect addressing mode

Addition:
area program, code, readonly
entry
LDR R0,value1
LDR R1,[R0]
LDR R2,value2
LDR R3,[R2]
ADD R4,R1,R3

area program,data,readonly
value1 DCD &10000024
value2 DCD &10000028
END

Subtraction:
area program, code, readonly
entry
LDR R0,value1
LDR R1,[R0]
LDR R2,value2
LDR R3,[R2]
SUB R4,R1,R3
area program, data, readonly
value1 DCD &10000024
value2 DCD &10000028
END

3
c) ​Barrel shifter

Addition:
area program, code, readonly
entry
LDR R1,value1
LDR R2,value2
ADD R0,R1,R2,LSL #2
SWI&11

area program, data, readonly


value1 DCD &00001000
value2 DCD &00001010
END

Subtraction:
area program, code, readonly
entry
LDR R1,value1
LDR R2,value2

4
ADD R0,R1,R2,LSL #2
SWI&11
area program, data, readonly
value1 DCD &00001000
value2 DCD &00001010
END

5
2. Write a program to perform left and right shift of a number.

AREA abc, code, readonly


entry
LDR R1,value1
LDR R1,value1

MOV R0,R1,LSL #2
MOV R0,R1,LSL R2

MOV R0,R1,LSR #2
MOV R0,R1,LSR R2

MOV R0,R1,ASR #2
MOV R0,R1,ASR R2

MOV R0,R1,ASL #2
MOV R0,R1,ASL R2

MOV R0,R1,ROR #2
MOV R0,R1,ROR R2

AREA abc, data, readonly

value1 DCD &00000010


value2 DCD &00000003

END

6
Logical Left Shift:

7
Logical Right Shift

3. Write a program in ARM assembly language to calculate one’s compliment of a number.

area program,code,readonly
entry
main
LDR R1,value
MVN R1,R1
SW1 &11

area program,data,readonly
value DCD &00000001
END

8
4. Write a program to find whether a number is even or odd.

AREA evenodd, code, readonly


entry
LDR R1,value1
AND R2,R1,#1

AREA evenodd, data, readonly


value1 DCD &00000012
END

9
10
5. Write a program to perform Multiplication using addition.

AREA addwithoutmultiply, code, readonly


entry
LDR R1,value1
LDR R2,value2
LDR R3,value3
LOOP
ADD R3,R1,R3
SUBS R2,R2,#1
BNE LOOP

AREA addwithoutmultiply, data, readonly


value1 DCD &00000012
value2 DCD &00000008
value3 DCD &00000000
END

11
6. Write a program to store Multiplication table of a number.

area program, code, readonly


entry
LDR R0,value1
MOV R3,R0
LDR R1,value2
MOV R2,#0X0A
LOOP
STR R0,[R1]
ADD R0,R0,R3
SUB R2,R2,#0X01
ADD R1,R1,#0X04
CMP R2,#0X00
BNE LOOP
SWI&11

area program,data,readonly
value1 DCD &00000002
value2 DCD &0000000A
END

12
7. Write a program to perform Division using subtraction.

area program, code, readonly


entry
LDR R0,value1
LDR R1,value2
MOV R2,#0X00
MOV R3,R0
LOOP
SUB R3,R3,R1
ADD R2,R2,#0X01
CMP R3,R1
BGE LOOP

area program,data,readonly
value1 DCD &0000000A
value2 DCD &00000002
END

13
8. Write a program to count the number of characters in a given string.

AREA countnoofchar, code , readonly


entry
LDR R0, =String
MOV R2, #0
LOOP
LDRB R1,[R0],#0X01
CMP R1,#0X00
ADDNE R2,#0X01
BNE LOOP

AREA countnoofchar,data,readonly
String DCB "HELLO"
END

14
9. Write a program to find the number of occurence of a particular character in a string.

area program, code, readonly


entry
LDR R0,=string
MOV R2,#0x00
LOOP
LDRB R1,[R0],#0x01
CMP R1,#"A"
ADDEQ R2,R2,#0x01
CMP R1,#0x00
BNE LOOP
SWI&11
area program,data,readonly
string DCB "ADIOS AMIGOS"
END

15
10. Write a program to add two integer strings.

area program, code, readonly


entry
LDR R0,=val1
LDR R1,=val2
LDR R2,=val3
LDR R3,count
LOOP
LDRB R4,[R0],#0x01
LDRB R5,[R1],#0x01
ADD R6,R4,R5
STRB R6,[R2],#0x01
SUB R3,#0x01
CMP R3,#0x00
BNE LOOP
SWI&11

area program,data,readonly
count DCD &00000004
val1 DCB 2,4,6,8
val2 DCB 1,5,3,7
val3 DCD &00000000
END

16
11. Write a program to find the factorial of a number.

AREA fact, code , readonly


entry
LDR R0, num
MOV R1, #1
LOOP
MUL R2,R1,R0
MOV R1,R2
SUBS R0,R0,#1
BNE LOOP

AREA fact,data,readonly
num DCD &00000003
END

17
12. Write a program to perform 64-bit addition of two 64-bit number.

area program, code, readonly


entry

LDR R0,=val1
LDR R1,[R0]

18
LDR R2,[R0,#0x04]
LDR R0,=val2
LDR R3,[R0]
LDR R4,[R0,#0x04]
ADDS R5,R2,R4
ADC R6,R1,R3
LDR R1,=result
STR R6,result
STR R5,[R1,#0x04]

area program,data,readonly
val1 DCD &12A2E640,&F2100123
val2 DCD &001019BF,&40023F51
result DCD &00000000
END

19
13. Write a program to find the largest number in an array.

area program,code,readonly
entry
main
LDR R0, =arr
LDRB R1,[R0]
LDR R2, arrsize
LOOP
LDRB R3,[R0],#0x01
CMP R3,R1
MOVGT R1,R3
SUB R2, #0x01
CMP R2, #0x00
BNE LOOP
area program,data,readonly
arrsize DCD &00000006
arr DCB 23,45,56,20,72,19
END

20
14. Write a program to copy an array.

area program, code, readonly


entry
LDR R0,=arr
MOV R4,#0x04
LDR R5,val
LOOP
LDRB R2,[R0],#0x01
STRB R2,[R5],#0x01
SUB R4,R4,#0x01
CMP R4,#0x00
BNE LOOP
SWI&11
area program,data,readonly
arr DCB 4,3,2,1
val DCD &10000080
END

21
15​. ​Write a program in ARM assembly language to implement the following equation:
i. ax​2​+by​2
area program, code, readonly
entry
LDR R0,value1
LDR R1,value2
LDR R2,value3
LDR R3,value4
MUL R4,R2,R2
MUL R5,R4,R0
MUL R6,R3,R3
MUL R7,R6,R1
ADD R8,R5,R7
area program, data, readonly
value1 DCD &00000001
value2 DCD &00000002
value3 DCD &00000003
value4 DCD &00000004
END

22
ii) 6(x+y) +2z+4
area program, code, readonly
entry
LDR R0,value1
LDR R1,value2
LDR R2,value3
ADD R3,R0,R1
MUL R4, #6
MUL R2, #2
ADD R5,R4,R2,#4

area program, data, readonly


value1 DCD &00000001
value2 DCD &00000002
value3 DCD &00000003
END

16. Write a program in ARM assembly language to count the number of 1s and 0s in a
given byte and verify the result.

area program, code, readonly


entry
main
LDR R0,value1
MOV R1,#0x00000020
MOV R2,#0x00000000
MOV R3,#0x00000000
LOOP
MOVS R0,R0,RRX
ADDCC R3,R3,#0x00000001
ADDCS R2,R2,#0x00000001
SUBS R1,R1,#0x00000001
BNE LOOP
SWI&11
area program, data, readonly
value1 DCD &FFFFFFFF
END

23
24

You might also like