0% found this document useful (0 votes)
2 views16 pages

ARM7 Programs

The document outlines various experiments based on the ARM7 architecture, focusing on data manipulation, interfacing, and programming in Assembly Language and C/C++. It includes detailed assembly language programs for tasks such as addition, subtraction, data transfer, and interfacing with LEDs and switches. Each experiment specifies the programming language to be used and provides example code for implementation.

Uploaded by

raafiask
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)
2 views16 pages

ARM7 Programs

The document outlines various experiments based on the ARM7 architecture, focusing on data manipulation, interfacing, and programming in Assembly Language and C/C++. It includes detailed assembly language programs for tasks such as addition, subtraction, data transfer, and interfacing with LEDs and switches. Each experiment specifies the programming language to be used and provides example code for implementation.

Uploaded by

raafiask
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/ 16

ARM7TDMI

ARM7 based experiments:


1. Simple data manipulation programs (addition, subtraction,
multiplication, division etc).
2. Study of IN and OUT port of ARM7 by Interfacing switches, LEDs etc.
3. Study of Timer.
4. Interfacing DAC/ADC using I2C Protocols.

Note:
1) Experiment no. 1 and Experiment no. 2 are to be performed using
Assembly Language.
2) Experiment no. 3 and Experiment no. 4 are to be performed using
C/C++/Embedded C/ Assembly Language.

The following are some of the programs pertaining to Experiment No. 1 i.e.
only simple data manipulation programs:

1) 32 – bit addition
Two, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to add these nos. Store the result in
consecutive memory location.
org 0x0000
main ldr r1,num1
ldr r2,num2
add r3,r2,r1
str r3,result
swi 0x11

org 0x0050
num1 dcdu 0xffff0000
num2 dcdu 0x00005151
result space 4
end

2) 64 – bit addition
Two, 64-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to add these nos. Store the result in
consecutive memory locations.

1
org 0x0000
main mov r0,#num
ldr r1,[r0],#4
ldr r2,[r0],#4
ldr r3,[r0],#4
ldr r4,[r0]
adds r5,r3,r1
adc r6,r4,r2
str r5,ResLow
str r6,ResHigh
swi 0x11

org 0x0050
num dcdu 0xffff0000
dcdu 0x44444444
dcdu 0x11111111
dcdu 0x55555555
ResLow space 4
ResHigh space 4
end

3) 16-bit Data Transfer


Four, 16-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to transfer these half word nos. to
new offset starting from 0070H.
org 0x0000
main mov r0,#table1
ldr r1,table2
mov r3,#3
up ldrh r2,[r0],#2
strh r2,[r1],#2
subs r3,r3,#1
bpl up
swi 0x11

org 0x0050
table1 dcw 0x1230
dcw 0x6120
dcw 0x8751

2
dcw 0x8963
table2 dcdu 0x0070
end

4) 32 – bit Data Transfer


Four, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to transfer these words to new offset
starting from 0070H.
org 0x0000
main mov r0,#table1
ldr r1,table2
ldmia r0,{r2-r5}
stmia r1,{r2-r5}
swi 0x11

org 0x0050
table1 dcdu 0x12300005
dcdu 0x61200005
dcdu 0x87516866
dcdu 0x89639901
table2 dcdu 0x0070
end

5) Dissemble
Write an ALP to dissemble a 32-bit no. stored in a memory location. For
example, let 11113333H be 32-bit no. After dissembling the result
should be 11110000H and 00003333H.
org 0x0000
main ldr r1,num
ldr r2,mask
and r3,r1,r2
and r4,r1,r2,lsl#16
strh r3,low
strh r4,high
swi 0x11

org 0x0050
num dcdu 0x11113333
mask dcdu 0x0000ffff

3
low space 2
high space 2
end

6) 16- bit Greatest


Five, 16-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to find the greatest from these nos.
Store the result in the consecutive memory location.
org 0x0000
main mov r0,#num
mov r3,#0x03
ldrh r1,[r0],#2
up ldrh r2,[r0],#2
cmp r1,r2
bhi down
mov r1,r2
down subs r3,r3,#0x01
bpl up
str r1,resgre
swi 0x11

org 0x0050
num dcw 0x1111
dcw 0x0000
dcw 0x2222
dcw 0x7777
dcw 0x4444
resgre space 4
end

7) 32 –bit Greatest
Five, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to find the greatest from these nos.
Store the result in the consecutive memory location.
org 0x0000
main mov r0,#num
mov r3,#0x03
ldr r1,[r0],#4
up ldr r2,[r0],#4

4
cmp r1,r2
bhi down
mov r1,r2
down subs r3,r3,#0x01
bpl up
str r1,result
swi 0x11

org 0x0050
num dcdu 0x11110000
dcdu 0x00001111
dcdu 0x22221111
dcdu 0x77777777
dcdu 0x33333333
result space 4
end

8) Long multiplication
Two, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to multiply them and get a 64-bit
result. The nos. can be unsigned or signed. Store the result in the
consecutive memory locations.
org 0x0000
main ldr r1,num1
ldr r2,num2
umull r4,r3,r2,r1
smull r6,r5,r2,r1
swi 0x11

org 0x0050
num1 dcdu 0x91111111
num2 dcdu 0x00000011
result space 4
end

5
9) 16-bit Smallest
Five, half-word nos. are stored in consecutive memory locations
starting from offset 0050H. Write an ALP to find the smallest from
these nos. Store the result in the consecutive memory location.
org 0x0000
main mov r0,#num
mov r3,#0x03
ldrh r1,[r0],#2
up ldrh r2,[r0],#2
cmp r1,r2
blo down
mov r1,r2
down subs r3,r3,#0x01
bpl up
str r1,result
swi 0x11

org 0x0050
num dcw 0x1111
dcw 0x0100
dcw 0x2222
dcw 0x0010
dcw 0x0000
result space 4
end

10) 32- bit Smallest


Five, words are stored in consecutive memory locations starting from
offset 0050H. Write an ALP to find the smallest from these nos. Store
the result in the consecutive memory location.
org 0x0000
main mov r0,#num
mov r3,#0x03
ldr r1,[r0],#4
up ldr r2,[r0],#4
cmp r1,r2
blo down
mov r1,r2
down subs r3,r3,#0x01

6
bpl up
str r1,result
swi 0x11

org 0x0050
num dcdu 0x11110000
dcdu 0x00001111
dcdu 0x00000111
dcdu 0x00000011
dcdu 0x00000001
result space 4
end

11) 32- bit Multiplication (Short or Normal multiplication)


Two, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to multiply them and get a 32-bit
result. The nos. can be unsigned or signed. Store the result in the
consecutive memory location.
org 0x0000
main ldr r1,num1
ldr r2,num2
mul r3,r2,r1
str r3,res
swi 0x11

org 0x0050
num1 dcdu 0xf1111111
num2 dcdu 0x00000002
res space 4
end

12) 16- bit Negative nos.


Five, half-words are stored in consecutive memory locations starting
from offset 0050H. Write an ALP to find the negative nos. from these
nos. Store the result in the consecutive memory location.
org 0x0000
main eor r2,r2,r2
mov r0,#num
mov r3,#0x04

7
up ldrh r1,[r0],#2
cmp r1,#0x8000
bcs down
add r2,r2,#1
down subs r3,r3,#0x01
bpl up
strb r2,result
swi 0x11

org 0x0050
num dcw 0x8555
dcw 0x1111
dcw 0x2222
dcw 0x9333
dcw 0x4445
result space 4
end

13) 32 – bit Negative nos.


Five, words are stored in consecutive memory locations starting from
offset 0050H. Write an ALP to find negative nos. from these nos. Store
the result in the consecutive memory location.
org 0x0000
main eor r2,r2,r2
mov r0,#num
mov r3,#0x04
up ldr r1,[r0],#4
cmp r1,#0x80000000
bcc down
add r2,r2,#1
down subs r3,r3,#0x01
bpl up
strb r2,result
swi 0x11

org 0x0050
num dcdu 0x85550000
dcdu 0x11110000
dcdu 0x22220000

8
dcdu 0x93330000
dcdu 0xf4450001
result space 4
end

14) Ones complement


Write an ALP to find the Ones Complement of the given 32-bit no.
org 0x0000
main ldr r0,num
mvn r1,r0
str r1,result
swi 0x11
org 0x0050
num dcdu 0x12345678
result space 4
end

15) 32-bit Subtraction


Two, 32-bit nos. are stored in consecutive memory locations starting
from offset 0050. Write an ALP to subtract the first no. from the second
no. and also the second no. from the first no. Store both the result in
consecutive memory locations.
org 0x0000
main ldr r1,num1
ldr r2,num2
subs r3,r2,r1
rsbs r4,r2,r1
str r3,subres
str r4,rsbres
swi 0x11

org 0x0050
num1 dcdu 0xffff0000
num2 dcdu 0x00005151
subres space 4
rsbres space 4
end

9
16) 64 – bit Subtraction
Two, 64-bit nos. are stored in consecutive memory locations starting
from offset 0050. Write an ALP to subtract these nos. Store the result
in consecutive memory location.
org 0x0000
main ldr r1,NUM1L
ldr r2,NUM1H
ldr r3,NUM2L
ldr r4,NUM2H
rsbs r5,r3,r1
rscs r6,r4,r2
str r5,RESL
str r6,RESH
swi 0x11

org 0x0050
NUM1L dcdu 0x00001111
NUM1H dcdu 0xffff0000
NUM2L dcdu 0x10101010
NUM2H dcdu 0xf0f00000
RESL space 4
RESH space 4
end

10
The following are some of the programs pertaining to Experiment No. 2
i.e. Study of IN and OUT port of ARM7 by Interfacing switches, LEDs
etc.:

1) LED Flashing
Write an ALP for flashing 8 LEDs. i.e. byte flashing
org 0x0000
B main

org 0x0050
main
MOV R0, #0X00
LDR R1, PINSEL0
STR R0, [R1]
MOV R0, #0X00
LDR R2, PINSEL1
STR R0, [R2]
MOV R0, #0xFF
LDR R3, PIODIR
STR R0, [R3]

TEXT MOV R0, #0xff


LDR R1, PIOSET
STR R0, [R1]
BL DELAY
LDR R1, PIOCLR
STR R0, [R1]
BL DELAY
B TEXT

DELAY
LDR R5, DCOUNT
LOOP MOV R5, R5
SUBS R5, R5, #0X001
BNE LOOP
11
MOV R15, R14

org 0x0150
PINSEL0 DCDU 0xE002C000
PINSEL1 DCDU 0xE002C004
PIOSET DCDU 0xE0028004
PIODIR DCDU 0xE0028008
PIOCLR DCDU 0xE002800C
DCOUNT DCDU 0X0000F00F
end

2) Modify the above program to alternately flash 4 LEDs. i.e. nibble


flashing – Lower four LEDs “ON”, Upper four LEDs “OFF” then Lower
four LEDs “OFF’, Upper four LEDs “ON”.

3) Write an ALP to alternately flash LEDs.


ORG 0x0000
B main

ORG 0x0050
main BL psel
BL pdir
repeat MOV R0,#0X55
BL pset
BL delay
BL pclr
MOV R0, #0XAA
BL pset
BL delay
BL pclr
B repeat

ORG 0X0100
psel MOV R0, #0X00
LDR R1, PINSEL0
STR R0, [R1]
LDR R1, PINSEL1
STR R0, [R1]
12
MOV R15, R14

pdir MOV R0,#0xFF ;


LDR R1,PIODIR ;
STR R0,[R1] ;
MOV R15,R14 ; RETURN

pset LDR R1,PIOSET ;


STR R0,[R1] ;
MOV R15,R14 ; RETURN

pclr LDR R1,PIOCLR ;


STR R0,[R1] ;
MOV R15,R14 ; RETURN

delay
LDR R5,dcount ; load in r1
loop MOV R5,R5 ; like NOP
SUBS R5,R5,#0x001 ; decrement by 1
BNE loop
MOV R15,R14 ; RETURN

ORG 0x0200
PINSEL0 DCDU 0xE002C000
PINSEL1 DCDU 0xE002C004
PIOSET DCDU 0xE0028004
PIODIR DCDU 0xE0028008
PIOCLR DCDU 0xE002800C
dcount DCDU 0x0000F005 ; LED flash frequency
END

13
4) Write an ALP for running LEDs.

org 0x0000

MAIN
MOV R0, #0X00
LDR R1, PINSEL0
STR R0, [R1]
MOV R0, #0X00
LDR R1, PINSEL1
STR R0,[R1]
MOV R0, #0xFF
LDR R1, PIODIR
STR R0, [R1]
MOV R3, #0X08
MOV R0, #0X01
AGAIN LDR R1, PIOSET
STR R0, [R1]
BL DELAY
LDR R1, PIOCLR
STR R0, [R1]
MOV R0, R0, LSL#1
SUBS R3, R3, #0X01
BNE AGAIN
B MAIN

DELAY
LDR R5, DCOUNT
LOOP MOV R5, R5
SUBS R5, R5, #0X001
BNE LOOP
MOV R15, R14

org 0x0150
PINSEL0 DCDU 0xE002C000
PINSEL1 DCDU 0xE002C004
PIOSET DCDU 0xE0028004

14
PIODIR DCDU 0xE0028008
PIOCLR DCDU 0xE002800C
DCOUNT DCDU 0X000FFFF
end

5) Write an ALP to display digit “__” on a Common Cathode 7-Segment


Display

org 0x0000

main
MOV R0, #0X00
LDR R1, PINSEL0
STR R0, [R1]
MOV R0, #0X00
LDR R1, PINSEL1
STR R0, [R1]
MOV R0, #0xFF
LDR R1, PIODIR
STR R0,[R1]
MOV R0, #00
TEXT
MOV R1, #CODE
LDRB R0, [R1]
LDR R1, PIOSET
STR R0, [R1]
BL DELAY
LDR R1, PIOCLR
STR R0, [R1]
B TEXT

DELAY
LDR R5, DCOUNT
LOOP MOV R5, R5
15
SUBS R5, R5, #0X001
BNE LOOP
MOV R15, R14

org 0x0150
PINSEL0 DCDU 0xE002C000
PINSEL1 DCDU 0xE002C004
PIOSET DCDU 0xE0028004
PIODIR DCDU 0xE0028008
PIOCLR DCDU 0xE002800C
DCOUNT DCDU 0X0000F00F

ORG 0X200
CODE DCB 0X6D ; Code to display “5” for Common Cathode
end

16

You might also like