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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:22:55+00:00 2026-05-18T10:22:55+00:00

I have been following the excellent book Programming Ground Up, wanting to learn assembly.

  • 0

I have been following the excellent book Programming Ground Up, wanting to learn assembly. Although not in the book at this point, I wanted to call my assembly function from C. on a 32 bit machine, this works as is when working from the book.

What I do here is storing the first argument in %ebx and the second in %ecx.

.type power, @function
.globl power
power:
    pushq   %ebp
    movl    %esp, %ebp
    subl    $4, %esp

    movl    8(%ebp), %ebx
    movl    12(%ebp), %ecx

I compile this (and the rest of the function) into an object file, create a main.c, where I prototype the function and call it, something like this:

int power(int b, int x);
int a = power(2, 1);

However, when I compile this on a 64 bit machine, I get some very unexpected results. I modified the obvious, like the fact that %esp and %ebp needs to be replaced with %rsp and %rbp, but digging with GDB reveals that the arguments are nowhere to be found on the stack!

Checking out what happens by using the -S option to GCC I can see that instead of pushing the variables on the stack, GCC stores the arguments in registers.

 movl $1, %esi
 movl $2, %edi
 call power

On the 32 bit machine, it does what I expect and push the arguments on the stack:

 movl $1, 4(%esp)
 movl $2, (%esp)
 call power

Now what is going on here? Why does GCC pass the arguments in registers on 64 bit and on the stack on 32 bit? This is very confusing! And I can’t find any mention on this anywhere. Is there anyone who can enlighten me on this situation?

  • 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-05-18T10:22:56+00:00Added an answer on May 18, 2026 at 10:22 am

    64-bit C calling convention is: %rdi, %rsi, %rdx, %rcx, %r8 and %r9

    See full description here:
    “System V Application Binary Interface: AMD64 Architecture Processor Supplement” http://www.x86-64.org/documentation/abi.pdf

    3.2 Function Calling Sequence

    When I learned the same topic, I made small C programs with required functions, compiled them in 64 bit compiler and read the Assembly code produced by C compiler. C/C++ compiler can be used like kind of Assembly reference.

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

Sidebar

Related Questions

I have been following this great guide on setting up bluetooth between 2 iPhones.
Hi I am quite new to php but i have been following some tutorials
Recently I have started playing with jQuery, and have been following a couple of
The following have been proposed for an upcoming C++ project. C++ Coding Standards, by
The rails books and web pages I've been following have all stuck to very
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Ok, I have been using the following script for over a year now to
I having trouble in dividing the HTML frames. I have been using the following
I have been searching everywhere for the following functionality in Lisp, and have gotten
People have been developing own solutions to the following problems: Consistent messaging frameworks for

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.