Skip to content

Instantly share code, notes, and snippets.

@officialcjunior
Created October 8, 2019 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save officialcjunior/e13f4af8046c7fec55705142dc39d4b8 to your computer and use it in GitHub Desktop.
Save officialcjunior/e13f4af8046c7fec55705142dc39d4b8 to your computer and use it in GitHub Desktop.
Program to print the n-th term in the fibonacci series, written in x86 assembly language
BITS 32
extern printf
extern scanf
section .rodata
output: db "The n-th term of the Fibnoacci series is %d", 10, 0
input: db "%d", 0
section .text
global main
main:
push ebp
mov ebp, esp
sub esp, 0x10
lea eax, [ebp-0x4]
push eax
push input
call scanf
mov ecx, dword [ebp-0x4]
cmp ecx, 1
mov ebx, 0
je L2
mov ecx, dword [ebp-0x4]
cmp ecx, 2
mov ebx, 1
je L2
mov edi, 0 ;a
mov ebx, 1 ;b
mov edx, 0
sub ecx, 2
L1:
inc edx
mov esi, ebx
add ebx, edi
mov edi, esi
cmp edx, ecx
jne L1
L2:
push ebx
push output
call printf
leave
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment