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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:25+00:00 2026-05-26T22:47:25+00:00

I want to read the stack pointer register value without writing inline assembly.The reason

  • 0

I want to read the stack pointer register value without writing inline assembly.The reason I want to do this is because I want to assign the stack pointer register value to an element of an array and I find it cumbersome to access an array using inline assembly. So I would want to do something like that.

register "rsp" long rsp_alias; <--- How do I achieve something like that in gcc?
long current_rsp_value[NUM_OF_THREADS];

current_rsp_value[tid] = rsp_alias;

Is there anything like that possible with gcc?

  • 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-26T22:47:26+00:00Added an answer on May 26, 2026 at 10:47 pm

    There’s a shortcut:

    register long rsp asm ("rsp");
    

    Demo:

    #include<stdio.h>
    
    void foo(void)
    {
        register long rsp asm ("rsp");
        printf("RSP: %lx\n", rsp);
    }
    
    int main()
    {
        register long rsp asm ("rsp");
        printf("RSP: %lx\n", rsp);
        foo();
        return 0;
    }
    

    Gives:

     $ gdb ./a.out 
    GNU gdb (Gentoo 7.2 p1) 7.2
    ...
    Reading symbols from /home/user/tmp/a.out...done.
    (gdb) break foo
    Breakpoint 1 at 0x400538: file t.c, line 7.
    (gdb) r
    Starting program: /home/user/tmp/a.out 
    RSP: 7fffffffdb90
    
    Breakpoint 1, foo () at t.c:7
    7       printf("RSP: %lx\n", rsp);
    (gdb) info registers
    ....
    rsp            0x7fffffffdb80   0x7fffffffdb80
    ....
    (gdb) n
    RSP: 7fffffffdb80
    8   }
    

    Taken from the Variables in Specified Registers documentation.

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

Sidebar

Related Questions

I want to read an specific xml node and its value for example <customers>
I want to read the full stack trace of an exception that I capture.
I've read several of the posts on stack overflow already about this topic, but
I have a text file. I want read that file. But In that if
I want to read the contents of a URL but don't want to hang
I want to read all items of a feed in C#. The solutions I've
I want to read and write from serial using events/interrupts. Currently, I have it
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to read an xml file, apply a transform, then write to another
I want to read, write and create Spreadsheets in the Open Document Format with

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.