Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close Lab-1 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lab-1/fib.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ fibonacci:

@ R4 = R0 - 0 (update flags)
@ if(R0 <= 0) goto .L3 (which returns 0)
subs r4, r0, #0
ble .L3

@ Compare R4 wtih 1
@ If R4 == 1 goto .L4 (which returns 1)
cmp r4, #1
beq .L4

@ R0 = R4 - 1
@ Recursive call to fibonacci with R4 - 1 as parameter
subs r0, r4, #1
bl fibonacci

@ R5 = R0
@ R0 = R4 - 2
@ Recursive call to fibonacci with R4 - 2 as parameter
mov r5, r0
subs r0, r4, #2
bl fibonacci

@ R0 = R5 + R0 (update flags)
adds r0, r5, r0

pop {r3, r4, r5, pc} @EPILOG

Expand Down
10 changes: 7 additions & 3 deletions lab-1/fibseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ int main(int argc, char **argv)
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);

if (scanf("%d",&number) == 1) {
result = fibonacci(number);
printf("The fibonacci sequence at %d is: %d\n", number, result);
}

return 0;
}