Fibonacci Series:
Code:
PRESERVE8
THUMB
AREA |.text|,CODE,READONLY
EXPORT __main
ENTRY
__main FUNCTION
MOV R0,#0;Initial number 0
MOV R1,#1;Initial number 1
MOV R3,#255;Upto What Number you want the series(req)
MOV R4,#0;every element in series will be stored in r4
MOV R5,#0x20000000;The entire series is written from this memory location
ADD R4,R0,R1;val = t0+t1
loop1 CMP R4,R3;if(val > req)
BLE LOOP;if less goto loop
B stop;Else goto end
LOOP STR R4,[R5],#1;Storing the series into memory
MOV R0,R1;t1=t0;
MOV R1,R4;t0=val
ADD R4,R0,R1;val = t0 + t1
B loop1;Loop untill val >= req
stop B stop
ENDFUNC
END
1 ,1 ,2, 3, 5, 8, 13....
Series can be checked element by element in R4 or in the memory location mentioned.Code:
PRESERVE8
THUMB
AREA |.text|,CODE,READONLY
EXPORT __main
ENTRY
__main FUNCTION
MOV R0,#0;Initial number 0
MOV R1,#1;Initial number 1
MOV R3,#255;Upto What Number you want the series(req)
MOV R4,#0;every element in series will be stored in r4
MOV R5,#0x20000000;The entire series is written from this memory location
ADD R4,R0,R1;val = t0+t1
loop1 CMP R4,R3;if(val > req)
BLE LOOP;if less goto loop
B stop;Else goto end
LOOP STR R4,[R5],#1;Storing the series into memory
MOV R0,R1;t1=t0;
MOV R1,R4;t0=val
ADD R4,R0,R1;val = t0 + t1
B loop1;Loop untill val >= req
stop B stop
ENDFUNC
END