EmbDev.net

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


von Will W. (Company: SMU) (wbeasley)


Rate this post
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
  ADD r3,r2,r1
  ADD r1,r1,r2
  SUB r2,r2,r2
  ADD r2,r3,r2      ;also having problems here with logic
  ADD r4,r4,#1
  STR r3, [r5]      ;here is where it loops back
  CMP r4,#18
  BNE FIBO


stop  B  stop
  END

von Krapao (Guest)


Rate this post
useful
not useful
Your Code doesn't compute the Fibonacci numbers because there are 
logical errors. Code for first 18 Fibonacci numbers:
1
int SRAM_BASE[18];
2
int main(void)
3
{
4
  int r1 = 0;          // MOV r1,#0
5
  int r2 = 1;          // MOV r2,#1
6
  int r3 = 0;          // MOV r3,#0
7
  int r4 = 0;          // MOV r4,#0
8
  int *r5 = SRAM_BASE; // LDR r5,=SRAM_BASE
9
10
  // Init 1st and 2nd Fibonacci numbers
11
  *r5++ = 0;           // STR r3,[r5]
12
                       // ADD r5,r5,#1
13
  r4++;                // ADD r4,r4,#1
14
  *r5++ = 1;           // STR r3,[r5]
15
                       // ADD r5,r5,#1
16
  r4++;                // ADD r4,r4,#1
17
18
  // Compute following Fibonacci numbers
19
  do {
20
  // FIBO:
21
    r3 = r2 + r1;      // ADD r3,r2,r1
22
    *r5++ = r3;        // STR r3,[r5]
23
                       // ADD r5,r5,#1
24
    r4++;              // ADD r4,r4,#1
25
    r1 = r2;           // MOV r1,r2
26
    r2 = r3;           // MOV r2,r3
27
  } while( r4 != 18 ); // CMP r4,#18
28
                       // BNE FIBO                         
29
// STOP:
30
  while(1){}           // B STOP
31
}

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.