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

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

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

SRAM_BASE EQU 0x04000000    ;static ram location


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
;  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

stop  B  stop

von Krapao (Guest)

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[18];
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


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.