# Forum: ARM programming with GCC/GNU tools EASY for most

Rate this post
 0 ▲ useful ▼ not useful
; I am horrible with ARM and I am having problems this is the program I
wrote
; but it isn't working the right way it is supposed to do the fibonacci
seq
; using indirect addressing it keeps looping back to when i LDR r0
; what do i do to fix this? thanks

AREA  FIBSEQ,CODE
SRAM_BASE EQU 0x04000000    ;static ram location

ENTRY

MAIN  MOV r1,#0      ;first number used in sequence
MOV r2,#1      ;second number used in sequence
MOV r3,#0      ;third number used in sequence
MOV r4,#1      ;counter
LDR r5,=SRAM_BASE
;  STR r3,[r5],#0      ;these are supposed to be the first numbers in
the           ;fib seq
;  STR r4,[r5],#1

FIBO          ;method that solves for fib up to 18th seq
SUB r2,r2,r2
ADD r2,r3,r2      ;also having problems here with logic
STR r3, [r5]      ;here is where it loops back
CMP r4,#18
BNE FIBO

stop  B  stop
END

Rate this post
 0 ▲ useful ▼ not useful
Your Code doesn't compute the Fibonacci numbers because there are
logical errors. Code for first 18 Fibonacci numbers:

 int SRAM_BASE; int main(void) { int r1 = 0; // MOV r1,#0 int r2 = 1; // MOV r2,#1 int r3 = 0; // MOV r3,#0 int r4 = 0; // MOV r4,#0 int *r5 = SRAM_BASE; // LDR r5,=SRAM_BASE // Init 1st and 2nd Fibonacci numbers *r5++ = 0; // STR r3,[r5] // ADD r5,r5,#1 r4++; // ADD r4,r4,#1 *r5++ = 1; // STR r3,[r5] // ADD r5,r5,#1 r4++; // ADD r4,r4,#1 // Compute following Fibonacci numbers do { // FIBO: r3 = r2 + r1; // ADD r3,r2,r1 *r5++ = r3; // STR r3,[r5] // ADD r5,r5,#1 r4++; // ADD r4,r4,#1 r1 = r2; // MOV r1,r2 r2 = r3; // MOV r2,r3 } while( r4 != 18 ); // CMP r4,#18 // BNE FIBO // STOP: while(1){} // B STOP } 

• $formula (LaTeX syntax)$