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 8224189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:58:34+00:00 2026-06-07T14:58:34+00:00

I’ve written a simple program in assembly language, trying to run it on my

  • 0

I’ve written a simple program in assembly language, trying to run it on my 64bit Ubuntu OS. However, it failed for the “Segmentation fault (core dumped) error “.

Here is my code :

    .section .data
    values :
        .int 10, 15, 20, 25, 30 ,35, 40, 45, 50, 55, 60
    output :
        .asciz "The value is %d\n"
   .section .text
   .globl main
   main :
        nop
        movl $0, %edi
   loop :
        movl values( , %edi, 4), %eax
        pushq %rax
        pushq $output
        call printf
        addl $8, %esp
        inc %edi
        cmpl $11, %edi
        jne loop
        movl $0, %ebx
        movl $1, %eax
        int $0x80
  • 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-07T14:58:36+00:00Added an answer on June 7, 2026 at 2:58 pm

    There are multiple problems in your code.

    From 64bit Ubuntu and pushq %rax I infer that you’re trying to make a 64-bit executable.

    If that’s the case, then…

    Here:

    pushq %rax
    pushq $output
    call printf
    addl $8, %esp
    

    you’re not properly balancing the stack after the function call. You still remember that this is 64-bit code? You need to add to rsp, not esp. Also, if you push 2 8-byte parameters, you have to remove exactly 2 8-byte parameters, which means you have to add 16, not 8.

    But it’s even worse than that. In 64-bit mode parameters are passed differently. The first parameters are in the registers rdi, rsi, rdx, rcx, r8 and r9. So, that gives us:

    movq %rax, %rsi
    movq $output, %rdi
    movq $0, %rax ; number of vector registers used for var-arg-function printf()
    call printf
    

    Here:

    inc %edi
    

    You just destroyed the value of rdi by the call and by using this register for parameter passing. You need to manually push rdi prior to the call and then pop it back. Or you could save it in a global variable. If you choose to push and pop, make sure than the stack pointer rsp is always 16-byte-aligned before any call instruction.

    Here:

    movl $0, %ebx
    movl $1, %eax
    int $0x80
    

    you are using the 32-bit system call interface. In 64-bit programs you have to use the 64-bit system call interface:

    movq $60, %rax ; sys_exit
    movq $0, rdi ; return 0 (success)
    syscall
    

    Now, I think this one may have problems too:

    movl $0, %edi
    loop :
    movl values( , %edi, 4), %eax
    

    In general, you shouldn’t be using 32-bit registers and 32-bit instructions in address calculations in 64-bit code. I’d change it to:

    movl $0, %rdi
    loop :
    movl values( , %rdi, 4), %eax
    

    If neither of the two works because the address of values is more than 2GB away from rip (fact: displacements are limited to 32-bit signed integers in memory operands in most instructions in 64-bit mode and most of them have no displacement-only memory operand encoding in 64-bit mode either, they use rip-relative addressing there), you will need to manually add the 64-bit address of values and the index into the array multiplied by 4. Make sure you do a 64-bit addition without any truncations along the way.

    Must-reads:

    • System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.6

    • Calling conventions for different C++ compilers and operating systems By Agner Fog

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.