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

  • Home
  • SEARCH
  • 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 7628829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:40:25+00:00 2026-05-31T05:40:25+00:00

Can I read from or write to a variable defined in my assembly file

  • 0

Can I read from or write to a variable defined in my assembly file in my C file? I couldn’t figure it out on my own. For example the C file looks as follows:

int num = 33;

and produces this assembly code:

    .file   "test.c"
    .globl  _num
    .data
    .align 4
_num:
    .long   33

As i started to learn assembly i heard often the speed is the reason why i have to pick assembly and lower file size and all that stuff…

I am using mingw(32 bit) gnu assembly on windows 7

  • 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-31T05:40:27+00:00Added an answer on May 31, 2026 at 5:40 am

    Yes, Linker combines all the .o files (built from .s files) and makes a single object file. So all your c files will first become assembly files.

    Each assembly file will have an import list, and an export list. Export list contains all the variables that have a .global or .globl directive. Import list contains all the variables that start with a extern in the c file. (GAS, unlike NASM, doesn’t require declaring imports, though. All symbols that aren’t defined in the file are assumed to be external. But the resulting .o or .obj object files will have import lists of symbols they use, and require to be defined somewhere else.)

    So if your assembly file contains this:

        .globl  _num        # _num is a global symbol, when it is defined
        .data               # switch to read-write data section
        .align 4
    _num:                   # declare the label 
        .long  33           # 4 bytes of initialized storage after the label
    

    All you need to do in order to use num, is to create a extern variable like this

    extern int num;  // declare the num variable as extern in your C code   
    

    and then you’ll be able to read it or modify it.


    Many platforms (Windows, OS X) add a leading underscore to symbol names, so the C variable num has an asm name of _num. Linux/ELF doesn’t do this, so the asm name would also be num.

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

Sidebar

Related Questions

I'm trying to create a Zip file from .Net that can be read from
How you can read a file (text or binary) from a batch file? There
In C# you can easily read all classes from a given assembly. I'm looking
How can I read the first line from a text file using a Windows
I found that you can't read from some sites using Python's urllib2(or urllib). An
How can I read international characters from console in java?
I'm new to ASP.net, how can I read parameters passed from ASP.net page (
How can I read the status of the battery on my MacBookPro from my
How can I read the client's machine/computer name from the browser? Is it possible
How to read data from Bar Code Scanner in .net windows application? Can some

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.