AREA Example,CODE,READONLY ;
;IMPORT sum5
;IMPORT i
export sum1ToN
export sortBubble
export SumOfArray
export factorial
export result
export reverse
ENTRY
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
sum1ToN
loop
add r1,r1,r0
subs r0,r0,#1
cmp r0,#0
bne loop
ldr r2,=result
mov r0,r1
str r1,[r2]
bx lr
result dcd 0
;*******************************************************************************
; sort bubble
;*******************************************************************************
sortBubble
subs r1,r1,#1
loopi
mov r5,#0
loopj
mov r3, #4
mul r3, r5,r3
add r6, r3,#4
ldr r9, [r0,r3]
ldr r10, [r0,r6]
cmp r9, r10
movgt r4, r9
movgt r9, r10
movgt r10, r4
str r9,[r0,r3]
str r10,[r0,r6]
add r5,r5,#1
cmp r5,r1
blo loopj
subs r1,r1,#1
cmp r1,#0
bne loopi
bx lr
;*******************************************************************************
; SumOfArray
;*******************************************************************************
SumOfArray
mov r2,#0
mov r3,#0
loopk
mov r10,#4
mul r10,r10,r2
ldr r9,[r0,r10]
add r3,r3,r9
add r2,r2,#1
cmp r2,r1
blo loopk
mov r0, r3
bx lr
;*******************************************************************************
; factorial
;*******************************************************************************
factorial
mov r1,#1
mov r2,#1
loopl
mul r2,r2,r1
add r1,#1
cmp r1, r0
bls loopl
mov r0, r2
bx lr
;*******************************************************************************
; reverse array
; r0: address of given arrary
; r1: length of given arrary
; r2: element size of given arrary
;*******************************************************************************
reverse
mov r4,#0
loopm
mov r5,r2
mov r6,r2
mul r5,r5,r4
mul r6,r6,r1
sub r6,r6,r2
ldr r7,[r0, r5]
ldr r8,[r0, r6]
mov r9, r7
mov r7, r8
mov r8, r9
str r7,[r0, r5]
str r8,[r0, r6]
add r4,r4,#1
sub r1,r1,#1
cmp r4, r1
blo loopm
bx lr