Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:10:42+00:00 2026-06-04T15:10:42+00:00

We have to code in Assembly which is as you may know hard. Or

  • 0

We have to code in Assembly which is as you may know hard. Or professor didnt give us any information how to code or link properly. We had to learn it by ourselves. Tomorrow I have to hand in my work.
The aim is to print the n.th Fibonacci number to the console.

section .data
    fmt: db "fib=%d",10,0

section .text
extern _printf
global _main, fib

_main:
    mov eax, 10     ; e.g. n=10
    mov ebx, 1      ; we know f_0 and f_1
    sub eax, ebx    ; thats why n--
    push eax        ; push n
    push 0      ; f_0 = 0 
    push 1      ; f_1 = 1

    call fib

    push eax        ; in eax the result is stored
    push fmt
    call _printf

    mov ebx, 0
    mov eax, 1      ; exit(0)
    int 0x80    


fib:
    mov ecx, eax
    pop esi
    calc:
    pop ebx
    pop edx
    add ebx, edx
    mov eax, ebx
    push edx
    push ebx
    sub ecx, 1
    cmp ecx, 0
    jne calc
    push esi
    ret

After struggling with the linker I finally managed to assemble and link my program. But it doesn’t work – I get a segmentation fault everytime.

Edit:
corrected code – I get some text on the console, but sadly no correct number it always displays “fib=1” and again seg fault.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:10:43+00:00Added an answer on June 4, 2026 at 3:10 pm

    You have

    push 0      ; f_0 = 0 
    push 1      ; f_1 = 1
    
    call fib
    

    then

    fib:
        mov ecx, eax
        calc:
        pop ebx
        pop edx
    

    You can’t do that – the call instruction will push the return address on the stack, and that’s the first thing you’ll be popping off in fib.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C# code which is using CSharpCodeProvider.CompileAssemblyFromSource to create an assembly in
I have seen an assembly code which subtracts from the stack pointer before calling
I have a simple assembly code file called exit.s that looks like the following:
I have the following code: namespace ConectorV2 { [assembly:InternalsVisibleTo(Pruebas)] internal static class Utilidades {
I have this code to register dlls into my gac Assembly asm = Assembly.LoadFrom(argument);
My EAX register contains the xxxxxx9D value and I have the following assembly code:
I have some Javascript code that will programmatically register an COM interop assembly by
I have a .net assembly that contains data access code (a bunch of Typed
I have a .NET assembly DLL that is created on-the-fly from pre-compiled code in
Do we have a way to view assembly and c code both using gdb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.