Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Laboratory 2 Templates.

Sorting Program
RCC_APB2ENR
GPIOE_CRH
GPIOE_ODR

EQU
EQU
EQU

0x40021018
0x40011804
0x4001180c

AREA RESET, DATA, READONLY


EXPORT __Vectors
__Vectors
DCD
DCD

0x20000200
Reset_Handler

;<------------------------

AREA |.text|, CODE, READONLY


EXPORT Reset_Handler
;
Reset_Handler PROC
mov r6,#0x40
;enable clock to port E
ldr r7,=RCC_APB2ENR
str r6,[r7]
mov r6,#0x33333333 ;configure port E - o/p to LEDs
ldr r7,=GPIOE_CRH
str r6,[r7]
bl
MoveData
;LEDs are turned On and OFF use to measure performance of your code
mov r6,#0xff00;
;turn LEDs on
ldr r7,=GPIOE_ODR
str r6,[r7]
;New program here
mov r6,#0x00;
;turn LEDs off
ldr r7,=GPIOE_ODR
str r6,[r7]
Loop
b Loop
ENDP
MoveData
PROC
push {r0,r1,r2,r3}
mov r3,#0
ldr r1,=Tbe
ldr r2,=Tb2
MM2
ldr r0,[r1]
str r0,[r2]
add
r1,#4
add r2,#4
add r3,#1
cmp r3,#4
bne MM2
pop {r0,r1,r2,r3}
bx lr
ENDP

;counter for doubles


;data address in ROM
;data address in RAM
;get double
;save double in RAM
;increment pointers
;count
;4 doubles done

AREA Table, DATA, READONLY


Tbe

DCB
DCB

0x12,0x34,0x56,0x78,0x21,0x43,0x65,0x87
0x93,0x39,0x05,0x50,0x75,0x57,0x21,0x81

AREA RAM, DATA, READWRITE


Tb2
SPACE 4
END

Add
ress

Opera
nd

;space for 4 double words 16 bytes

Instr
uctio
n
Just
prior
to BL

Result/Explanation.
Ie After instruction execution
R0 =0x00000034
R1 =0x00000021
R2 =0x2000000C
R3 =0x2000000D
LR =0xFFFFFFFF
SP =0x20000200
LR =0x0800001D

BL
Move
PUS SP = 0x200001F0
H
Contents of memory at SP =
{R0R3}

MOV Here the contents from the first table Tb1(in the read
etc
only area) is transferred 4 bytes (32 bits) at a time
(total 4 times, for 16 bytes) to a read/write area of
memory predefined as Tb2
Prior R0 =0x81215775
to
R1 =0x080000B0
POP R2 =0x20000010
R3 =0x00000004
LR =0x0800001D
SP =0x200001F0
POP R0 =0x00000093
{R0- R1 =0x00000005
R3}
R2 =0x20000000
R3 =0x20000001
LR =0x0800001D
SP =0x20000200
BX
Branching to the link register to go back from the

LR
Next

MoveData subroutine
Next, we added our own subroutine to sort the data

Period: 376us
Offtime:740ns
Ontime : 376us-740ns= 375us approximately
S32312504_EEET2096_LAB2.pdf
Time taken for 1 loop is 1563ns ( =375us/(15*16)).

You might also like