forked from embedded2015/arm-lecture
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CC = arm-linux-gnueabihf-gcc | ||
CFLAGS = -O1 -Wall | ||
LDFLAGS = -fno-stack-protector | ||
|
||
objects = fibseq.o fib.o | ||
|
||
default: fibseq | ||
|
||
.PHONY: default clean | ||
|
||
fibseq: $(objects) | ||
$(CC) $(LDFLAGS) -o $@ $^ | ||
|
||
fib.o: fib.s | ||
fibseq.o: fibseq.c | ||
|
||
%.o: %.c | ||
$(CC) -c $(CFLAGS) -o $@ $< | ||
|
||
%.o: %.s | ||
$(CC) -c $(CFLAGS) -o $@ $< | ||
|
||
clean: | ||
rm -f $(objects) fibseq | ||
|
||
qemu: fibseq | ||
qemu-arm -L /usr/arm-linux-gnueabihf ./fibseq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.syntax unified | ||
.arch armv7-a | ||
.text | ||
.align 2 | ||
.thumb | ||
.thumb_func | ||
|
||
.global fibonacci | ||
.type fibonacci, function | ||
|
||
fibonacci: | ||
@ ADD/MODIFY CODE BELOW | ||
@ PROLOG | ||
push {r3, r4, r5, lr} | ||
|
||
@ R4 = R0 - 0 (update flags) | ||
@ if(R0 <= 0) goto .L3 (which returns 0) | ||
|
||
@ Compare R4 wtih 1 | ||
@ If R4 == 1 goto .L4 (which returns 1) | ||
|
||
@ R0 = R4 - 1 | ||
@ Recursive call to fibonacci with R4 - 1 as parameter | ||
|
||
@ R5 = R0 | ||
@ R0 = R4 - 2 | ||
@ Recursive call to fibonacci with R4 - 2 as parameter | ||
|
||
@ R0 = R5 + R0 (update flags) | ||
|
||
pop {r3, r4, r5, pc} @EPILOG | ||
|
||
@ END CODE MODIFICATION | ||
.L3: | ||
mov r0, #0 @ R0 = 0 | ||
pop {r3, r4, r5, pc} @ EPILOG | ||
|
||
.L4: | ||
mov r0, #1 @ R0 = 1 | ||
pop {r3, r4, r5, pc} @ EPILOG | ||
|
||
.size fibonacci, .-fibonacci | ||
.end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
|
||
extern int fibonacci(int x); | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int number=0; | ||
int result=0; | ||
|
||
printf("Please input a number:"); | ||
scanf("%d",&number); | ||
result = fibonacci(number); | ||
printf("The fibonacci sequence at %d is: %d\n", number, result); | ||
} | ||
|