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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:52+00:00 2026-06-16T00:38:52+00:00

Possible Duplicate: Not sure why we add the registers %rdx and %rax when the

  • 0

Possible Duplicate:
Not sure why we add the registers %rdx and %rax when the assembly code has been using %eax and %edx

all.
So, here’s my minimal program:

int main(int argc, char * argv[]){
    volatile int a;
    volatile int b;
    volatile int c;
    a = 9;
    b = 15;
    c = a+b;
    return c;
}

I now run gcc -S on this, and here’s the meat of the generated assembly:

.LCFI1:
    movl    %edi, -20(%rbp)    //unknown setup
    movq    %rsi, -32(%rbp)    //unknown setup
    movl    $9, -4(%rbp)       //a=9, so -4(%rbp) is the register for a.
    movl    $15, -8(%rbp)      //b=15, so -8(%rbp) is b's register.
    movl    -4(%rbp), %edx     //move a into the register for addition.
    movl    -8(%rbp), %eax     //move b into the register for additon.
    leal    (%rdx,%rax), %eax  //Add a and b, store in %eax. (PROBLEM LINE)
    movl    %eax, -12(%rbp)    //Store %eax in c's register.
    movl    -12(%rbp), %eax    //get ready to return c. 
    leave                      //we're done here.
    ret

Okay, so you see the line I indicate as the problem line. Here’s my question: What on earth are %rdx and %rax? The only registers I’ve loaded things into are %edx and %eax.

Since the program works, %rdx and %rax must be some sort of alias to %edx and %eax, accordingly. Can someone possibly explain the nuances of x86 register nomenclature? I’m completely in the dark on this.

(Of note, if I change the problem line to addl %edx, %eax, the result is identical, but if I change it to addl %rdx, %rax, I get “Error: Incorrect register ‘%rax’ used with l suffix”)

  • 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-16T00:38:53+00:00Added an answer on June 16, 2026 at 12:38 am

    Have a look here if you are unsure about the registers and their sizes. Think of it this way

    union{
      struct{
        uint32_t eax;
        uint32_t padd;
      };
      uint64_t rax;
    };
    

    eax and rax share the same register, eax is low part of that register.

    This is the reason why addl won’t work with the registers prefixed with r, they are longer than addl is expecting. Try addq instead.

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

Sidebar

Related Questions

Possible Duplicate: Activity not started, its current task has been brought to the front
Possible Duplicate: Why does Mac's $find not have the option -printf? Not sure what
Possible Duplicate: Making a generic property I'm not quite sure how to do that,
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
Possible Duplicate: most elegant way to return a string from List<int> I'm not sure
Possible Duplicate: LINQ - Where not exists I'm using LINQ2SQL and I want to
Possible Duplicate: How do I use arrays in C++? I am not sure if
Possible Duplicate: MATLAB: Matrix of differences I am not sure how to word this
Possible Duplicate: PHP SPL RecursiveDirectoryIterator RecursiveIteratorIterator retrieving the full tree I am not sure
Possible Duplicate: How are SSL certificate server names resolved/Can I add alternative names using

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.