.global func
.section .text
func :
init :
MOV R 0 ,#3 @Move 3 to R0
MOV R 1 ,#5 @Move 5 to R1
MOV R 2 ,#0 @Move 0 to R2
MOV R 3 ,#1000 @The value to compare with
loop :
add5 :
ADD R 2 ,R 2 ,R 1 @Add R1 to R2
ADD R 1 ,R 1 ,#5 @Increment R1 by 5
add3 :
ADD R 2 ,R 2 ,R 0 @Add R0 to R2
ADD R 0 ,R 0 ,#3 @Increment R0 by 3
check3 :
CMP R 0 ,R 3 @Is R0 less than 1000?
BGE r m v15 @If the multiple of 3 is greater than 1000, go to rmv15
check5 :
CMP R 1 ,R 3 @Is R1 less than 1000?
BLT l o o p @If true, go back to loop
BGE a d d3 @If the multiple of 5 reaches 1000, go back to add3 instead of loop - Continue adding multiples of 3, because those wouldn't have reached 1000 yet
rmv15 :
MOV R 0 ,#15 @The loop that follows is intended to subtract multiples of 15, which would have been added twice - 3, 6, 9, 12, [15], 18 ; 5, 10, [15], 20
loop2 :
SUB R 2 ,R 2 ,R 0
ADD R 0 ,R 0 ,#15
CMP R 0 ,R 3
BLT l o o p2
return :
MOV R 0 ,R 2
BX l r
.section .data