Sunday, February 1, 2015

In many programming languages aifa books which will calculate the Fibonacci sequence on the sample


In many programming languages aifa books which will calculate the Fibonacci sequence on the sample, or as exercises, because the calculation aifa of the number of columns can be used to pass back (Recursion. Function call themselves own. I call this "the ball kicking themselves for future ", of course, put it nicely it can be said" generations ") concept.
It went on to run the program look like Hello! This composition is because there is more than one file, so make a Makefile. So, if you want to perform, please enter the terminal above: make run First main.c: #include <stdio.h> / * * declared assembly language programming function prototypes * unsigned long long integer is 64 yuan * / unsigned long long fib (unsigned long long n); int main () {int i; for (i = 0; i <30; i ++) {printf ("% lu \ n", fib (i + 1));} return 0;} followed by a big focus this time, fib.s. .section .text / * This function is used to calculate the number of columns we fibonacci fibonacci number of columns defined as: fib (1) = 1 fib (2) = 1 fib (n) = fib (n - 1) + fib (n - 2) corresponding to the C language function prototype is: unsigned long long fib (unsigned long long n) * / .global aifa fib .type fib,function fib: / * configure the stack frame (stack frame) of the * / push% rbp mov % rsp,% rbp / * now stack to 16 yuan group address has aligned * / / * n == 1? fib (1) = 1 * / cmp $ 1,% rdi jne fib_not_1 mov $ 1,% rax jmp fib_end fib_not_1: / * n == 2 fib (2) = 1 * / cmp $ 2,% rdi jne fib_others mov $ 1,% rax jmp fib_end fib_others:? / * fib (n) = fib (n - 1) + fib (n - 2) * / xor% rax,% rax / * calculate fib (n - 1) * / sub $ 1,% rdi push% rdi call fib pop% rdi / * calculate fib (n - 2) * / sub $ 1,% rdi push% rax call fib pop% rcx add% rcx,% rax fib_end: / * Configuration restore stack frame * / mov% rbp,% rsp pop% rbp ret finally Makefile build: ./build/fib run: ./ build / fib ./build/fib ./build/fib: main.c fib.s mkdir -p ./build gcc main.c fib.s -o ./build/fib .PHONY: clean clean: aifa rm -r. / build
View my complete profile
brainf * k (2) C (11) C ++ (1) Chart (1) Docbook (2) emacs (1) freetype2 (3) ghc (1) GNU / Linux (12) harfbuzz (2) haskell (12) haskell platform (2) KDE (1) libpng (3) lua (5) OpenGL (3) parsec (1) python (1) tagsoup (1) x86-64 assembly language (7) xelatex (3) writing class (13) Country Love (1) Troubleshooting (5) Newsletter (2) parental love (1) program (33) code beautification (1) Movie Appreciation (3)
2013 (41) December (1) September (2) August (3) July (2) June (6) May (3) April (4) three May (9) February (5) January (6) 2012 (13) December (13) Haskell: Endless road with foldr nice! Learn programming language sense? x86-64 assembly aifa language: the circle be? x86-64 assembly language: C language and computing together Fibonacci sequence! x86-64 assembly language: it is a leap year? check: unit C language test x86-64 GNU / Linux Application Binary Interface lazy bag x86-64 assembly language: aifa the use of libraries, expand horizons x86-64 aifa assembly language: the use of system aifa call to say hello to the world now! If you can not start KDE software, then ...? Beautify your code, then paste it into the blog now! (Emacs limited) x86-64 assembly language used in system call super battleship Feedback Battleship (Battleship)


No comments:

Post a Comment