I am stuck as to why this function repeatedly calls it self when it should return.
Initialize:
stmfd sp!, {R0-R4,lr}
mov R4, #0 @used for storing 0
mov R0, #2
mov R5, #0
ldr R1, =sieve
ldr R1, [R1]
ldr R2, =primes
ldr R2, [R2]
str R4, [R1], #4 @intialize first and second elements in sieve to 0
str R4, [R1]
mov R4, #1 @used for storing 1
setToOne:
str R4, [R1], #4
add R0, R0, #1
cmp R0, #MAX
blt setToOne
ldmfd sp!, {R0-R4,pc} @For somereason Initialize repeats as if lr points back to its begining (instead of where it's called from)
Ok I can’t post the entire program because it says “Your post does not have much context to explain the code sections; please explain your scenario more clearly.”
You are overwriting
R5without saving it first. I can´t see why it should make the function call itself, but it will probably give some kind of strange results.As a side note, if you are calling this function from C,
R0-R3do not need to be saved since they are scratch registers. If you are calling it from assembly, you can of course create your own calling convention which might make it necessary to save them.