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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:09:37+00:00 2026-06-12T06:09:37+00:00

Possible Duplicate: x86 assembly registers — Why do they work the way they do?

  • 0

Possible Duplicate:
x86 assembly registers — Why do they work the way they do?

I’ve compiled the following program:

#include <stdio.h>

int square(int x) {
    return x * x;
}

int main() {
    int y = square(9);
    printf("%d\n", y);

    return 0;
}

two times with different options on OSX with GCC 4.2.1:

gcc foo.c -o foo_32.s -S -fverbose-asm -m32 -O1

gcc foo.c -o foo_64.s -S -fverbose-asm -m64 -O1

The result for 32 bit:

_square:                                ## @square
## BB#0:                                ## %entry
    pushl   %ebp
    movl    %esp, %ebp
    movl    8(%ebp), %eax
    imull   %eax, %eax
    popl    %ebp
    ret

And for 64-bit:

_square:                                ## @square
Leh_func_begin1:
## BB#0:                                ## %entry
    pushq   %rbp
Ltmp0:
    movq    %rsp, %rbp
Ltmp1:
    movl    %edi, %eax
    imull   %eax, %eax
    popq    %rbp
    ret

As is evident, the 32-bit version retrieves the parameter from the stack, which is what one would expect with cdecl. The 64-bit version however uses the EDI register to pass the parameter.

Doesn’t this violate the System V AMD64 ABI, which specifies that the RDI, RSI, RDX, RCX, R8, R9, XMM0–7 registers should be used? Or is this only the case for true 64-bit values like long?

  • 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-12T06:09:38+00:00Added an answer on June 12, 2026 at 6:09 am

    EDI is simply the lower half of RDI so the compiler is passing the argument in RDI, but the argument is only 32-bits long, so it only takes up half of the register.

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

Sidebar

Related Questions

Possible Duplicate: harmonic series with x86-64 assembly trying to do a version of a
Possible Duplicate: C# - How to get Program Files (x86) on Windows Vista 64
Possible Duplicate: C# - How to get Program Files (x86) on Vista x64 What
Possible Duplicate: nth-child for every two table rows I'm trying to work my way
Possible Duplicate: C# - How to get Program Files (x86) on Windows Vista 64
Possible Duplicate: Loading x86 or x64 assembly I'm trying to compile Any CPU .NET
Possible Duplicate: Confusing add command in x86 assembly I would like to understand these
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: How to cross compile from Mac OS X to Linux x86? I
Possible Duplicate: ant error JAVA_HOME does not point to SDK I'm getting the following

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.